From 372b1a2d11ccedfbde5db0dad1956882504472c7 Mon Sep 17 00:00:00 2001 From: rqian <1206436827@qq.com> Date: Fri, 23 Oct 2026 09:12:53 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=AE=9E=E6=97=B6=E6=B6=88=E6=81=AF=E5=92=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maibu/core/business/DeviceRunParam.java | 687 ++++++++++-------- .../core/business/device/NettyDevice.java | 34 +- .../java/com/maibu/core/host/ParamDetail.java | 8 +- .../com/maibu/core/host/VehicleMessage.java | 3 + .../com/maibu/mqtt/HostMessageHandler.java | 18 +- .../netty/handler/CommandForwardHandler.java | 6 +- .../netty/handler/DataToDataBaseHandler.java | 14 +- .../com/maibu/scheduled/ScheduledTask.java | 26 +- .../maibu/service/TransferDeviceService.java | 187 ++--- .../controller/DeviceRunParamController.java | 41 +- .../controller/OrderModelController.java | 3 - .../service/impl/DeviceRunParamService.java | 203 ++++-- .../resources/机器属性导入模板.xlsx | Bin 0 -> 11105 bytes 13 files changed, 711 insertions(+), 519 deletions(-) create mode 100755 maibu-service/maibu-iot-service/src/main/resources/机器属性导入模板.xlsx diff --git a/maibu-common/src/main/java/com/maibu/core/business/DeviceRunParam.java b/maibu-common/src/main/java/com/maibu/core/business/DeviceRunParam.java index 5f3e381..77e6bce 100644 --- a/maibu-common/src/main/java/com/maibu/core/business/DeviceRunParam.java +++ b/maibu-common/src/main/java/com/maibu/core/business/DeviceRunParam.java @@ -1,22 +1,19 @@ package com.maibu.core.business; +import java.time.LocalDate; +import java.util.List; + import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.maibu.annotation.Excel; -import com.maibu.constant.CommandConstant; import com.maibu.core.domain.BaseDO; import lombok.Data; import lombok.EqualsAndHashCode; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; -import java.util.List; - @EqualsAndHashCode(callSuper = true) @Data @TableName(value = "iot_device_run_param", autoResultMap = true) @@ -25,366 +22,440 @@ public class DeviceRunParam extends BaseDO { @TableId(type = IdType.AUTO) private Long id; -// private String deviceId; + // private String deviceId; private Long siteId; private Long orgId; - private Integer runSpeed; //不下发到设备自己用 + private Integer runSpeed; // 不下发到设备自己用 @Excel(name = "设备序列号", cellType = Excel.ColumnType.STRING, prompt = "设备序列号") - private String deviceId;//设备序列号 + private String deviceId;// 设备序列号 @Excel(name = "产品型号", cellType = Excel.ColumnType.STRING, prompt = "产品型号") - private String productModel;//产品型号 + private String productModel;// 产品型号 @Excel(name = "设备类型", cellType = Excel.ColumnType.STRING, prompt = "设备类型") - private String deviceType;//设备类型:mower-割草机器人 + private String deviceType;// 设备类型:mower-割草机器人 @Excel(name = "RTK模式", cellType = Excel.ColumnType.STRING, prompt = "RTK模式") - private String rtkMode;//RTK模式:network-4G网络差分 + private String rtkMode;// RTK模式:network-4G网络差分 @Excel(name = "摄像头数量", cellType = Excel.ColumnType.STRING, prompt = "摄像头数量") - private Integer cameraNum;//摄像头数量 + private Integer cameraNum;// 摄像头数量 @Excel(name = "动力类型", cellType = Excel.ColumnType.STRING, prompt = "动力类型") - private String powerType;//动力类型:hybrid-混动 + private String powerType;// 动力类型:hybrid-混动 @Excel(name = "车轮类型", cellType = Excel.ColumnType.STRING, prompt = "车轮类型") - private String wheelType;//车轮类型:track-履带式 + private String wheelType;// 车轮类型:track-履带式 @Excel(name = "发动机类型", cellType = Excel.ColumnType.STRING, prompt = "发动机类型") - private String engineType;//发动机类型:honda-本田发动机 + private String engineType;// 发动机类型:honda-本田发动机 - @Excel(name = "是否搭载上位机",cellType = Excel.ColumnType.NUMERIC) - private Integer hasHost = 1;//是否搭载上位机 + @Excel(name = "是否搭载上位机", cellType = Excel.ColumnType.NUMERIC) + private Integer hasHost = 1;// 是否搭载上位机 @Excel(name = "设备能力列表") @TableField(exist = false) private String capabilities; + private String factoryCode; // 工厂码 + + private String lineNum;// 产线号 + + private LocalDate productionDate;// 生产日期 + + private String serialNumber;// 流水号 + + @Excel(name = "电池类型", cellType = Excel.ColumnType.STRING, prompt = "电池类型") + private String batteryType;// 电池类型 + + @Excel(name = "行走驱动类型", cellType = Excel.ColumnType.STRING, prompt = "行走驱动类型") + private String walkingDriveType;// 行走驱动类型 + + @Excel(name = "割刀驱动类型", cellType = Excel.ColumnType.STRING, prompt = "割刀驱动类型") + private String cutterDriveType;// 割刀驱动类型 + + @Excel(name = "RTK天线数", cellType = Excel.ColumnType.STRING, prompt = "RTK天线数") + private String rtkAntennasNum;// RTK天线数 + + @Excel(name = "手柄类型", cellType = Excel.ColumnType.STRING, prompt = "手柄类型") + private String handleType;// 手柄类型 + + @Excel(name = "PCB硬件版本", cellType = Excel.ColumnType.STRING, prompt = "PCB硬件版本") + private String pcbVersion;// PCB硬件版本 + + @Excel(name = "长宽高", cellType = Excel.ColumnType.STRING, prompt = "长宽高") + private String dimensions;// 长宽高 + + @Excel(name = "割刀宽度", cellType = Excel.ColumnType.STRING, prompt = "割刀宽度") + private String bladeWidth;// 割刀宽度 + + @Excel(name = "轮胎尺寸", cellType = Excel.ColumnType.STRING, prompt = "轮胎尺寸") + private String tyreSize;// 轮胎尺寸 + + @Excel(name = "转速比", cellType = Excel.ColumnType.STRING, prompt = "转速比") + private String speedRatio;// 转速比 + + @Excel(name = "蜂窝网络通信信息", cellType = Excel.ColumnType.STRING, prompt = "蜂窝网络通信信息") + private String cellularInfo;// 蜂窝网络通信信息 + + @Excel(name = "wifi名称", cellType = Excel.ColumnType.STRING, prompt = "wifi名称") + private String wifiName;// wifi名称 + + @Excel(name = "蓝牙广播名", cellType = Excel.ColumnType.STRING, prompt = "蓝牙广播名") + private String bluetoothName;// 蓝牙广播名 + + @Excel(name = "硬件标识信息", cellType = Excel.ColumnType.STRING, prompt = "硬件标识信息") + private String hardwareIdentifiers;// 硬件标识信息 + + @Excel(name = "IMU型号", cellType = Excel.ColumnType.STRING, prompt = "IMU型号") + private String imuModel;// IMU型号 + + @Excel(name = "温湿度传感器", cellType = Excel.ColumnType.STRING, prompt = "温湿度传感器") + private String tempHumiditySensor;// 温湿度传感器 + + @Excel(name = "气压计在位", cellType = Excel.ColumnType.STRING, prompt = "气压计在位") + private String barometerPresent;// 气压计在位 + + @Excel(name = "超声波在位", cellType = Excel.ColumnType.STRING, prompt = "超声波在位") + private String ultrasonicPresent;// 超声波在位 + + @Excel(name = "DAC在位", cellType = Excel.ColumnType.STRING, prompt = "DAC在位") + private String dacPresent;// DAC在位 + + @Excel(name = "质检员", cellType = Excel.ColumnType.STRING, prompt = "质检员") + private String operator;// 质检员 + + @Excel(name = "检测报告号", cellType = Excel.ColumnType.STRING, prompt = "检测报告号") + private String inspectionNo;// 检测报告号 + + @Excel(name = "固件版本", cellType = Excel.ColumnType.STRING, prompt = "固件版本") + private String firmwareVersion;// 固件版本 + + @Excel(name = "经销商", cellType = Excel.ColumnType.STRING, prompt = "经销商") + private String dealer;// DAC在位 + @TableField(typeHandler = JacksonTypeHandler.class) - private List capabilityList;//设备能力列表:heartbeat-上报心跳/location-上报位置/vehicle_status-上报整机状态/task_control-任务控制/single_point-单点作业/coverage-全覆盖割草作业/path_upload-作业路径上传 + private List capabilityList;// 设备能力列表:heartbeat-上报心跳/location-上报位置/vehicle_status-上报整机状态/task_control-任务控制/single_point-单点作业/coverage-全覆盖割草作业/path_upload-作业路径上传 + + // @TableField(exist = false) + // public byte header1; + // @TableField(exist = false) + // public byte header2; + // @TableField(exist = false) + // public byte cmd; + + // public byte chipUidSign;// 芯片UID固化标志位 + // public String chipUid;// 芯片UID + + // public byte[] remoteConfig;// 遥控器通道配置 + // public int knifeMotorMode;// 割刀电机模式 + // public int walkMotorMode;// 行走电机模式 + // public int leftMotorReverse;// 左轮电机方向极性 + // public int rightMotorReverse;// 右轮电机方向极性 + // public int swapChannel;// 左右轮通道互换标志位 + // public int use4G;// 联网标志位 + + // public short forwardSpeedLimit;// 前进速度限制 + // public short turnSpeedLimit;// 转向速度限制 + + // public int knifePolarity;// 割刀通道极性 + // public int fanPolarity;// 风门通道极性 + // public int throttlePolarity;// 油门通道极性 + // public int liftProtectTime;// 底盘升降电机保护时间 + // public int dualRtk;// RTK配置 + + // public int knifeChannel;// 割刀通道配置 + // public int fanChannel;// 风门通道配置 + + // public int throttleChannel;// 油门通道配置 + // public int remoteType;// 遥控器类型 + // public boolean relayBoard;// 是否搭载继电器板 + + // public int liftChannel;// 底盘升通道配置 + // public int chassisChannel;// 底盘降通道配置 + + // public int armChannel;// 抱闸通道配置 + // public int fuelPumpChannel;// 燃油励磁通道配置 + + // public String wifiName;// wifi名称 + // public String wifiPassword;// wifi密码 + + // public int batteryType;// 电池类型 + // public int driveType;// 行走驱动配置 + + // public float gearRatio;// 转速比 + // public float robotLength;// 机器人长度 + // public float robotWidth;// 机器人宽度 + // public float robotHeight;// 机器人高度 + // public float knifeWidth;// 割刀宽度 + // public float tyreSize;// 轮胎尺寸 + // public float leftForwardGain;// 左轮前进增益 + // public float leftBackwardGain;// 左轮后退增益 + // public float rightForwardGain;// 右轮前进增益 + // public float rightBackwardGain;// 右轮后退增益 + + // public String firmwareVersion;// 固件版本 + // @TableField(exist = false) + // public int crc16; + // @TableField(exist = false) + // public byte tail1; + // @TableField(exist = false) + // public byte tail2; + // @TableField(exist = false) + // private byte[] originalData; + + // public static byte[] toReadBytes() { + // ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节 + // buffer.order(ByteOrder.LITTLE_ENDIAN); + + // buffer.put((byte) 0xAB); + // buffer.put((byte) 0xAA); + + // buffer.put(CommandConstant.readConfig); + + // buffer.putShort((short) 0); + + // buffer.put((byte) 0xAA); + // buffer.put((byte) 0xAB); + + // return buffer.array(); + // } + + // public byte[] toWriteBytes() { + // // 如果没有原始数据,使用静态方法重新构建 + // if (originalData == null || originalData.length < 178) { + // return null; + // } + + // // 克隆原始数据,避免修改原始数据 + // byte[] result = originalData.clone(); + // ByteBuffer buffer = ByteBuffer.wrap(result); + // buffer.order(ByteOrder.LITTLE_ENDIAN); + + // // 修改指令为写配置(字节2) + // buffer.put(2, CommandConstant.writeConfig); + + // // 修改字节68:遥控器配置 + // byte remote = 0; + // remote |= (getKnifeMotorMode() & 0x03); + // remote |= (getWalkMotorMode() & 0x03) << 2; + // remote |= (getLeftMotorReverse() & 0x01) << 4; + // remote |= (getRightMotorReverse() & 0x01) << 5; + // remote |= (getSwapChannel() & 0x01) << 6; + // remote |= (getUse4G() & 0x01) << 7; + // buffer.put(68, remote); + + // // 修改字节69-72:速度限制 + // buffer.putShort(69, getForwardSpeedLimit()); + // buffer.putShort(71, getTurnSpeedLimit()); + + // // 修改字节73:通道极性 + // byte b73 = 0; + // b73 |= (getKnifePolarity() & 1); + // b73 |= (getFanPolarity() & 1) << 1; + // b73 |= (getThrottlePolarity() & 1) << 2; + // b73 |= (getLiftProtectTime() & 0x0F) << 3; + // b73 |= (getDualRtk() & 1) << 7; + // buffer.put(73, b73); + + // // 修改字节74-77:通道配置 + // byte b74 = 0; + // b74 |= (getKnifeChannel() & 0x0F); + // b74 |= (getFanChannel() & 0x0F) << 4; + // buffer.put(74, b74); + + // byte b75 = 0; + // b75 |= (getThrottleChannel() & 0x0F); + // b75 |= (getRemoteType() & 0x07) << 4; + // if (isRelayBoard()) + // b75 |= 1 << 7; + // buffer.put(75, b75); + + // byte b76 = 0; + // b76 |= (getLiftChannel() & 0x0F); + // b76 |= (getChassisChannel() & 0x0F) << 4; + // buffer.put(76, b76); + + // byte b77 = 0; + // b77 |= (getArmChannel() & 0x0F); + // b77 |= (getFuelPumpChannel() & 0x0F) << 4; + // buffer.put(77, b77); + + // // // 修改字节78-117:WiFi信息 + // // byte[] wifiNameBytes = new byte[20]; + // // if (getWifiName() != null) { + // // byte[] src = getWifiName().getBytes(StandardCharsets.UTF_8); + // // System.arraycopy(src, 0, wifiNameBytes, 0, Math.min(src.length, 20)); + // // } + // // System.arraycopy(wifiNameBytes, 0, result, 78, 20); + // // + // // byte[] wifiPwdBytes = new byte[20]; + // // if (getWifiPassword() != null) { + // // byte[] src = getWifiPassword().getBytes(StandardCharsets.UTF_8); + // // System.arraycopy(src, 0, wifiPwdBytes, 0, Math.min(src.length, 20)); + // // } + // // System.arraycopy(wifiPwdBytes, 0, result, 98, 20); + + // // // 修改字节118:电池和驱动配置 + // // byte b118 = 0; + // // b118 |= (getBatteryType() & 0x03); + // // b118 |= (getDriveType() & 0x03) << 2; + // // buffer.put(118, b118); + + // // 修改字节119-158:float参数 + // buffer.putFloat(119, getGearRatio()); + // buffer.putFloat(123, getRobotLength()); + // buffer.putFloat(127, getRobotWidth()); + // buffer.putFloat(131, getRobotHeight()); + // buffer.putFloat(135, getKnifeWidth()); + // buffer.putFloat(139, getTyreSize()); + // buffer.putFloat(143, getLeftForwardGain()); + // buffer.putFloat(147, getLeftBackwardGain()); + // buffer.putFloat(151, getRightForwardGain()); + // buffer.putFloat(155, getRightBackwardGain()); + + // // 修改字节159-173:固件版本 + // // byte[] fwBytes = new byte[15]; + // // if (getFirmwareVersion() != null) { + // // byte[] src = getFirmwareVersion().getBytes(StandardCharsets.UTF_8); + // // System.arraycopy(src, 0, fwBytes, 0, Math.min(src.length, 15)); + // // } + // // System.arraycopy(fwBytes, 0, result, 159, 15); + + // // 保留原始的 CRC 和尾部,不强制修改 + // // 移除以下强制修改: + // // buffer.putShort(174, (short) 0); + // // buffer.put(176, (byte) 0xAA); + // // buffer.put(177, (byte) 0xAB); + + // return result; + // } + + // public static void putFixedString(ByteBuffer buffer, String value, int len) { + + // byte[] bytes = new byte[len]; + + // if (value != null) { + // byte[] src = value.getBytes(StandardCharsets.UTF_8); + + // System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len)); + // } + + // buffer.put(bytes); + // } + + // public static DeviceRunParam fromBytes(byte[] data) { + // // 183 + // if (data == null || data.length < 178) { + // throw new IllegalArgumentException("数据长度不足"); + // } + + // ByteBuffer buffer = ByteBuffer.wrap(data); + // buffer.order(ByteOrder.LITTLE_ENDIAN); + + // DeviceRunParam p = new DeviceRunParam(); + // p.setOriginalData(data); - @TableField(exist = false) - public byte header1; - @TableField(exist = false) - public byte header2; - @TableField(exist = false) - public byte cmd; - - - public byte chipUidSign;//芯片UID固化标志位 - public String chipUid;//芯片UID - - public byte[] remoteConfig;//遥控器通道配置 - public int knifeMotorMode;//割刀电机模式 - public int walkMotorMode;//行走电机模式 - public int leftMotorReverse;//左轮电机方向极性 - public int rightMotorReverse;//右轮电机方向极性 - public int swapChannel;//左右轮通道互换标志位 - public int use4G;//联网标志位 - - public short forwardSpeedLimit;//前进速度限制 - public short turnSpeedLimit;//转向速度限制 - - public int knifePolarity;//割刀通道极性 - public int fanPolarity;//风门通道极性 - public int throttlePolarity;//油门通道极性 - public int liftProtectTime;//底盘升降电机保护时间 - public int dualRtk;//RTK配置 - - - public int knifeChannel;//割刀通道配置 - public int fanChannel;//风门通道配置 - - public int throttleChannel;//油门通道配置 - public int remoteType;//遥控器类型 - public boolean relayBoard;//是否搭载继电器板 - - public int liftChannel;//底盘升通道配置 - public int chassisChannel;//底盘降通道配置 - - public int armChannel;//抱闸通道配置 - public int fuelPumpChannel;//燃油励磁通道配置 - - public String wifiName;//wifi名称 - public String wifiPassword;//wifi密码 - - public int batteryType;//电池类型 - public int driveType;//行走驱动配置 - - public float gearRatio;//转速比 - public float robotLength;//机器人长度 - public float robotWidth;//机器人宽度 - public float robotHeight;//机器人高度 - public float knifeWidth;//割刀宽度 - public float tyreSize;//轮胎尺寸 - public float leftForwardGain;//左轮前进增益 - public float leftBackwardGain;//左轮后退增益 - public float rightForwardGain;//右轮前进增益 - public float rightBackwardGain;//右轮后退增益 - - public String firmwareVersion;//固件版本 - @TableField(exist = false) - public int crc16; - @TableField(exist = false) - public byte tail1; - @TableField(exist = false) - public byte tail2; - @TableField(exist = false) - private byte[] originalData; - - public static byte[] toReadBytes() { - ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节 - buffer.order(ByteOrder.LITTLE_ENDIAN); - - buffer.put((byte) 0xAB); - buffer.put((byte) 0xAA); - - buffer.put(CommandConstant.readConfig); - - buffer.putShort((short) 0); - - buffer.put((byte) 0xAA); - buffer.put((byte) 0xAB); - - return buffer.array(); - } - - public byte[] toWriteBytes() { - // 如果没有原始数据,使用静态方法重新构建 - if (originalData == null || originalData.length < 178) { - return null; - } - - // 克隆原始数据,避免修改原始数据 - byte[] result = originalData.clone(); - ByteBuffer buffer = ByteBuffer.wrap(result); - buffer.order(ByteOrder.LITTLE_ENDIAN); - - // 修改指令为写配置(字节2) - buffer.put(2, CommandConstant.writeConfig); - - // 修改字节68:遥控器配置 - byte remote = 0; - remote |= (getKnifeMotorMode() & 0x03); - remote |= (getWalkMotorMode() & 0x03) << 2; - remote |= (getLeftMotorReverse() & 0x01) << 4; - remote |= (getRightMotorReverse() & 0x01) << 5; - remote |= (getSwapChannel() & 0x01) << 6; - remote |= (getUse4G() & 0x01) << 7; - buffer.put(68, remote); - - // 修改字节69-72:速度限制 - buffer.putShort(69, getForwardSpeedLimit()); - buffer.putShort(71, getTurnSpeedLimit()); - - // 修改字节73:通道极性 - byte b73 = 0; - b73 |= (getKnifePolarity() & 1); - b73 |= (getFanPolarity() & 1) << 1; - b73 |= (getThrottlePolarity() & 1) << 2; - b73 |= (getLiftProtectTime() & 0x0F) << 3; - b73 |= (getDualRtk() & 1) << 7; - buffer.put(73, b73); - - // 修改字节74-77:通道配置 - byte b74 = 0; - b74 |= (getKnifeChannel() & 0x0F); - b74 |= (getFanChannel() & 0x0F) << 4; - buffer.put(74, b74); - - byte b75 = 0; - b75 |= (getThrottleChannel() & 0x0F); - b75 |= (getRemoteType() & 0x07) << 4; - if (isRelayBoard()) b75 |= 1 << 7; - buffer.put(75, b75); - - byte b76 = 0; - b76 |= (getLiftChannel() & 0x0F); - b76 |= (getChassisChannel() & 0x0F) << 4; - buffer.put(76, b76); - - byte b77 = 0; - b77 |= (getArmChannel() & 0x0F); - b77 |= (getFuelPumpChannel() & 0x0F) << 4; - buffer.put(77, b77); - -// // 修改字节78-117:WiFi信息 -// byte[] wifiNameBytes = new byte[20]; -// if (getWifiName() != null) { -// byte[] src = getWifiName().getBytes(StandardCharsets.UTF_8); -// System.arraycopy(src, 0, wifiNameBytes, 0, Math.min(src.length, 20)); -// } -// System.arraycopy(wifiNameBytes, 0, result, 78, 20); -// -// byte[] wifiPwdBytes = new byte[20]; -// if (getWifiPassword() != null) { -// byte[] src = getWifiPassword().getBytes(StandardCharsets.UTF_8); -// System.arraycopy(src, 0, wifiPwdBytes, 0, Math.min(src.length, 20)); -// } -// System.arraycopy(wifiPwdBytes, 0, result, 98, 20); - -// // 修改字节118:电池和驱动配置 -// byte b118 = 0; -// b118 |= (getBatteryType() & 0x03); -// b118 |= (getDriveType() & 0x03) << 2; -// buffer.put(118, b118); - - // 修改字节119-158:float参数 - buffer.putFloat(119, getGearRatio()); - buffer.putFloat(123, getRobotLength()); - buffer.putFloat(127, getRobotWidth()); - buffer.putFloat(131, getRobotHeight()); - buffer.putFloat(135, getKnifeWidth()); - buffer.putFloat(139, getTyreSize()); - buffer.putFloat(143, getLeftForwardGain()); - buffer.putFloat(147, getLeftBackwardGain()); - buffer.putFloat(151, getRightForwardGain()); - buffer.putFloat(155, getRightBackwardGain()); - - // 修改字节159-173:固件版本 -// byte[] fwBytes = new byte[15]; -// if (getFirmwareVersion() != null) { -// byte[] src = getFirmwareVersion().getBytes(StandardCharsets.UTF_8); -// System.arraycopy(src, 0, fwBytes, 0, Math.min(src.length, 15)); -// } -// System.arraycopy(fwBytes, 0, result, 159, 15); - - // 保留原始的 CRC 和尾部,不强制修改 - // 移除以下强制修改: - // buffer.putShort(174, (short) 0); - // buffer.put(176, (byte) 0xAA); - // buffer.put(177, (byte) 0xAB); - - return result; - } - - public static void putFixedString(ByteBuffer buffer, String value, int len) { - - byte[] bytes = new byte[len]; - - if (value != null) { - byte[] src = value.getBytes(StandardCharsets.UTF_8); - - System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len)); - } - - buffer.put(bytes); - } - - - public static DeviceRunParam fromBytes(byte[] data) { - // 183 - if (data == null || data.length < 178) { - throw new IllegalArgumentException("数据长度不足"); - } - - ByteBuffer buffer = ByteBuffer.wrap(data); - buffer.order(ByteOrder.LITTLE_ENDIAN); - - DeviceRunParam p = new DeviceRunParam(); + // p.setHeader1(buffer.get()); + // p.setHeader2(buffer.get()); - p.setOriginalData(data); + // p.setCmd(buffer.get()); - p.setHeader1(buffer.get()); - p.setHeader2(buffer.get()); + // p.setChipUidSign(buffer.get()); - p.setCmd(buffer.get()); + // p.setChipUid(readString(buffer, 45)); - p.setChipUidSign(buffer.get()); + // // 跳过字节49-67(共19字节,预留不用) + // buffer.position(buffer.position() + 19); - p.setChipUid(readString(buffer, 45)); + // byte remote = buffer.get(); - // 跳过字节49-67(共19字节,预留不用) - buffer.position(buffer.position() + 19); + // // p.setRemoteConfig(remote); - byte remote = buffer.get(); + // p.setKnifeMotorMode(remote & 0x03); + // p.setWalkMotorMode((remote >> 2) & 0x03); + // p.setLeftMotorReverse((remote >> 4) & 0x01); + // p.setRightMotorReverse((remote >> 5) & 0x01); + // p.setSwapChannel((remote >> 6) & 0x01); + // p.setUse4G((remote >> 7) & 0x01); -// p.setRemoteConfig(remote); + // p.setForwardSpeedLimit(buffer.getShort()); + // p.setTurnSpeedLimit(buffer.getShort()); - p.setKnifeMotorMode(remote & 0x03); - p.setWalkMotorMode((remote >> 2) & 0x03); - p.setLeftMotorReverse((remote >> 4) & 0x01); - p.setRightMotorReverse((remote >> 5) & 0x01); - p.setSwapChannel((remote >> 6) & 0x01); - p.setUse4G((remote >> 7) & 0x01); + // byte b73 = buffer.get(); - p.setForwardSpeedLimit(buffer.getShort()); - p.setTurnSpeedLimit(buffer.getShort()); + // p.setKnifePolarity(b73 & 1); + // p.setFanPolarity((b73 >> 1) & 1); + // p.setThrottlePolarity((b73 >> 2) & 1); + // p.setLiftProtectTime((b73 >> 3) & 0x0F); + // p.setDualRtk((b73 >> 7) & 1); - byte b73 = buffer.get(); + // byte b74 = buffer.get(); - p.setKnifePolarity(b73 & 1); - p.setFanPolarity((b73 >> 1) & 1); - p.setThrottlePolarity((b73 >> 2) & 1); - p.setLiftProtectTime((b73 >> 3) & 0x0F); - p.setDualRtk((b73 >> 7) & 1); + // p.setKnifeChannel(b74 & 0x0F); + // p.setFanChannel((b74 >> 4) & 0x0F); - byte b74 = buffer.get(); + // byte b75 = buffer.get(); - p.setKnifeChannel(b74 & 0x0F); - p.setFanChannel((b74 >> 4) & 0x0F); + // p.setThrottleChannel(b75 & 0x0F); + // p.setRemoteType((b75 >> 4) & 0x07); + // p.setRelayBoard(((b75 >> 7) & 1) == 1); - byte b75 = buffer.get(); + // byte b76 = buffer.get(); - p.setThrottleChannel(b75 & 0x0F); - p.setRemoteType((b75 >> 4) & 0x07); - p.setRelayBoard(((b75 >> 7) & 1) == 1); + // p.setLiftChannel(b76 & 0x0F); + // p.setChassisChannel((b76 >> 4) & 0x0F); - byte b76 = buffer.get(); + // byte b77 = buffer.get(); - p.setLiftChannel(b76 & 0x0F); - p.setChassisChannel((b76 >> 4) & 0x0F); + // p.setArmChannel(b77 & 0x0F); + // p.setFuelPumpChannel((b77 >> 4) & 0x0F); - byte b77 = buffer.get(); + // p.setWifiName(readString(buffer, 20)); + // p.setWifiPassword(readString(buffer, 20)); - p.setArmChannel(b77 & 0x0F); - p.setFuelPumpChannel((b77 >> 4) & 0x0F); + // byte b118 = buffer.get(); - p.setWifiName(readString(buffer, 20)); - p.setWifiPassword(readString(buffer, 20)); + // p.setBatteryType(b118 & 0x03); + // p.setDriveType((b118 >> 2) & 0x03); - byte b118 = buffer.get(); + // // float + // p.setGearRatio(buffer.getFloat()); + // p.setRobotLength(buffer.getFloat()); + // p.setRobotWidth(buffer.getFloat()); + // p.setRobotHeight(buffer.getFloat()); + // p.setKnifeWidth(buffer.getFloat()); + // p.setTyreSize(buffer.getFloat()); + // p.setLeftForwardGain(buffer.getFloat()); + // p.setLeftBackwardGain(buffer.getFloat()); + // p.setRightForwardGain(buffer.getFloat()); + // p.setRightBackwardGain(buffer.getFloat()); - p.setBatteryType(b118 & 0x03); - p.setDriveType((b118 >> 2) & 0x03); + // p.setFirmwareVersion(readString(buffer, 15)); - // float - p.setGearRatio(buffer.getFloat()); - p.setRobotLength(buffer.getFloat()); - p.setRobotWidth(buffer.getFloat()); - p.setRobotHeight(buffer.getFloat()); - p.setKnifeWidth(buffer.getFloat()); - p.setTyreSize(buffer.getFloat()); - p.setLeftForwardGain(buffer.getFloat()); - p.setLeftBackwardGain(buffer.getFloat()); - p.setRightForwardGain(buffer.getFloat()); - p.setRightBackwardGain(buffer.getFloat()); + // p.setCrc16(Short.toUnsignedInt(buffer.getShort())); - p.setFirmwareVersion(readString(buffer, 15)); + // p.setTail1(buffer.get()); + // p.setTail2(buffer.get()); - p.setCrc16(Short.toUnsignedInt(buffer.getShort())); + // return p; + // } - p.setTail1(buffer.get()); - p.setTail2(buffer.get()); + // public static String readString(ByteBuffer buffer, int len) { + // byte[] bytes = new byte[len]; + // buffer.get(bytes); - return p; - } + // int end = 0; + // while (end < bytes.length && bytes[end] != 0) { + // end++; + // } - public static String readString(ByteBuffer buffer, int len) { - byte[] bytes = new byte[len]; - buffer.get(bytes); - - int end = 0; - while (end < bytes.length && bytes[end] != 0) { - end++; - } - - return new String(bytes, 0, end, StandardCharsets.UTF_8); - } + // return new String(bytes, 0, end, StandardCharsets.UTF_8); + // } } diff --git a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java index a8580c4..11f808e 100644 --- a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java +++ b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java @@ -246,24 +246,24 @@ public class NettyDevice extends Connector { } } - public void readConfigCommand() { - byte[] bytes = DeviceRunParam.toReadBytes(); - log.debug("下发读取配置的报文:{}", toHexString(bytes)); - if (this.getChannel() != null && this.getChannel().isActive()) { - this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); - } - log.debug("下发读取配置的报文完成:{}", toHexString(bytes)); - } + // public void readConfigCommand() { + // byte[] bytes = DeviceRunParam.toReadBytes(); + // log.debug("下发读取配置的报文:{}", toHexString(bytes)); + // if (this.getChannel() != null && this.getChannel().isActive()) { + // this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); + // } + // log.debug("下发读取配置的报文完成:{}", toHexString(bytes)); + // } - public void writeConfigCommand(DeviceRunParam deviceRunParam) { - log.debug("下发修改配置的属性:{}", JsonUtils.toJsonString(deviceRunParam)); - byte[] bytes = deviceRunParam.toWriteBytes(); - log.debug("下发修改配置的报文:{}", toHexString(bytes)); - if (this.getChannel() != null && this.getChannel().isActive()) { - this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); - } - log.debug("下发修改配置的报文完成:{}", toHexString(bytes)); - } + // public void writeConfigCommand(DeviceRunParam deviceRunParam) { + // log.debug("下发修改配置的属性:{}", JsonUtils.toJsonString(deviceRunParam)); + // byte[] bytes = deviceRunParam.toWriteBytes(); + // log.debug("下发修改配置的报文:{}", toHexString(bytes)); + // if (this.getChannel() != null && this.getChannel().isActive()) { + // this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); + // } + // log.debug("下发修改配置的报文完成:{}", toHexString(bytes)); + // } // todo 优化 public synchronized boolean pauseTask() { diff --git a/maibu-common/src/main/java/com/maibu/core/host/ParamDetail.java b/maibu-common/src/main/java/com/maibu/core/host/ParamDetail.java index 9c55784..73779b1 100644 --- a/maibu-common/src/main/java/com/maibu/core/host/ParamDetail.java +++ b/maibu-common/src/main/java/com/maibu/core/host/ParamDetail.java @@ -4,11 +4,11 @@ import lombok.Data; @Data public class ParamDetail { - private short left_wheel_rpm; // 左轮转速 - private short right_wheel_rpm; // 右轮转速 + // private short left_wheel_rpm; // 左轮转速 + // private short right_wheel_rpm; // 右轮转速 - private double linear_speed; // 线速度 - private double angular_speed; // 角速度 + private double linear_x; // 线速度 + private double angular_z; // 角速度 private int chassis_lift; // 底盘升降 0:停止 1:升 2:降 private int cutter; // 割刀加减速 0:停止 1:加速 2:减速 diff --git a/maibu-common/src/main/java/com/maibu/core/host/VehicleMessage.java b/maibu-common/src/main/java/com/maibu/core/host/VehicleMessage.java index dc4b601..eaa00e7 100644 --- a/maibu-common/src/main/java/com/maibu/core/host/VehicleMessage.java +++ b/maibu-common/src/main/java/com/maibu/core/host/VehicleMessage.java @@ -31,4 +31,7 @@ public class VehicleMessage { private double roll;// 实时翻滚角度 private String control_mode;// 遥控器拨杆对应的当前控制模式 + private double linear_speed; // 实时线速度 + private double angular_speed; // 实时角速度 + } diff --git a/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java b/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java index 924a574..833ea31 100644 --- a/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java +++ b/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java @@ -154,7 +154,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler { String.format(MqttTopic.DEVICE_LOCATION_MESSAGE_TOPIC, deviceId), JsonUtils.toJsonString(locationRelTimeDTO)); } catch (MqttException e) { - log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e); + log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e); } } @@ -399,6 +399,18 @@ public class HostMessageHandler implements CustomMqttMessageHandler { control_mode.setUnit(""); transferData.add(control_mode); + DeviceStatusDetail linear_speed = new DeviceStatusDetail(); + linear_speed.setName("linear_speed"); + linear_speed.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLinear_speed())); + linear_speed.setUnit(""); + transferData.add(linear_speed); + + DeviceStatusDetail angular_speed = new DeviceStatusDetail(); + angular_speed.setName("angular_speed"); + angular_speed.setValue(String.valueOf(vehicleRelTimeDTO.getData().getAngular_speed())); + angular_speed.setUnit(""); + transferData.add(angular_speed); + webStatusMessageDTO.setData(transferData); webStatusMessageDTO.setType(MesType.deviceInfo); return webStatusMessageDTO; @@ -447,13 +459,13 @@ public class HostMessageHandler implements CustomMqttMessageHandler { } } } - // todo 推送实时位置和状态消息到外部 + // todo 推送实时位置和状态消息到外部 try { GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.DEVICE_VEHICLE_MESSAGE_TOPIC, deviceId), JsonUtils.toJsonString(vehicleRelTimeDTO)); } catch (MqttException e) { - log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e); + log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e); } } } catch (Exception e) { diff --git a/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java b/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java index 41204f7..5a417a1 100644 --- a/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java +++ b/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java @@ -83,7 +83,7 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler { } for (Connector target : connectedDevices) { - if (!target.canReceive()) { + if (target == null || !target.canReceive()) { logger.debug("发送拒绝master:{},消息到达的slave设备:{},处于禁止接收状态", senderDeviceId, target.getConnectorId()); continue; } @@ -110,8 +110,8 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler { .setScale(2, RoundingMode.HALF_UP) .doubleValue(); - data.setLinear_speed(linearSpeed); - data.setAngular_speed(angularSpeed); + data.setLinear_x(linearSpeed); + data.setAngular_z(angularSpeed); data.setChassis_lift(pEntity.getChassisLiftFlag()); data.setCutter(pEntity.getMowerSpeedFlag()); diff --git a/maibu-netty-server/src/main/java/com/maibu/netty/handler/DataToDataBaseHandler.java b/maibu-netty-server/src/main/java/com/maibu/netty/handler/DataToDataBaseHandler.java index 7d6d616..ecdb468 100644 --- a/maibu-netty-server/src/main/java/com/maibu/netty/handler/DataToDataBaseHandler.java +++ b/maibu-netty-server/src/main/java/com/maibu/netty/handler/DataToDataBaseHandler.java @@ -140,13 +140,13 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler { nettyDevice.setLatestStatus(latestStatus); } } else if (bytes[2] == CommandConstant.readConfig) { - DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); - logger.debug("收到返回的设备运行参数: {}", JsonUtils.toJsonString(runParam)); - CompletableFuture future = ctx.channel().attr(Constant.READ_CONFIG_KEY).get(); - if (future != null) { - future.complete(runParam); - ctx.channel().attr(Constant.READ_CONFIG_KEY).set(null); - } + // DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); + // logger.debug("收到返回的设备运行参数: {}", JsonUtils.toJsonString(runParam)); + // CompletableFuture future = ctx.channel().attr(Constant.READ_CONFIG_KEY).get(); + // if (future != null) { + // future.complete(runParam); + // ctx.channel().attr(Constant.READ_CONFIG_KEY).set(null); + // } } ctx.fireChannelRead(msg); } catch (Exception e) { diff --git a/maibu-netty-server/src/main/java/com/maibu/scheduled/ScheduledTask.java b/maibu-netty-server/src/main/java/com/maibu/scheduled/ScheduledTask.java index 47a4a8f..85341e3 100644 --- a/maibu-netty-server/src/main/java/com/maibu/scheduled/ScheduledTask.java +++ b/maibu-netty-server/src/main/java/com/maibu/scheduled/ScheduledTask.java @@ -75,20 +75,20 @@ public class ScheduledTask { System.out.println("0点定时刷新状态执行完成"); } - public static void main(String[] args) throws DecoderException { - String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1 FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA AB"; - String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符 - byte[] bytes = Hex.decodeHex(cleanHex); - DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); - System.out.println(JsonUtils.toJsonString(runParam)); + // public static void main(String[] args) throws DecoderException { + // String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1 FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA AB"; + // String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符 + // byte[] bytes = Hex.decodeHex(cleanHex); + // DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); + // System.out.println(JsonUtils.toJsonString(runParam)); - runParam.setLeftBackwardGain(0.2f); - runParam.setLeftForwardGain(0.2f); - runParam.setRightForwardGain(0.2f); - runParam.setRightBackwardGain(0.2f); + // runParam.setLeftBackwardGain(0.2f); + // runParam.setLeftForwardGain(0.2f); + // runParam.setRightForwardGain(0.2f); + // runParam.setRightBackwardGain(0.2f); - byte[] newB = runParam.toWriteBytes(); - System.out.println(Hex.encodeHexString(newB)); + // byte[] newB = runParam.toWriteBytes(); + // System.out.println(Hex.encodeHexString(newB)); - } + // } } \ No newline at end of file diff --git a/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java b/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java index 4188a9a..eaa0050 100644 --- a/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java +++ b/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java @@ -43,12 +43,11 @@ public class TransferDeviceService { @Autowired private DeviceMapper deviceMapper; - public AjaxResult bind(DeviceBindDTO bindDTO, LoginUser user) { try { String deviceId = bindDTO.getDeviceId(); String deviceAlias = bindDTO.getDeviceAlias(); - //判断当前设备是否存 + // 判断当前设备是否存 Device device = iDeviceService.selectDeviceBySerialNumber(deviceId); if (device == null) { return AjaxResult.error("设备不存在"); @@ -65,7 +64,7 @@ public class TransferDeviceService { device.setDeviceAlias(deviceAlias); device.setActiveTime(new Date()); iDeviceService.updateDeviceBySelf(device); -// deviceMapper.updateById(device); + // deviceMapper.updateById(device); return AjaxResult.success(true); } } catch (Exception e) { @@ -77,7 +76,7 @@ public class TransferDeviceService { public AjaxResult unbind(DeviceBindDTO bindDTO, LoginUser user) { try { String deviceId = bindDTO.getDeviceId(); - //判断当前设备是否存 + // 判断当前设备是否存 Device device = iDeviceService.selectDeviceBySerialNumber(deviceId); if (device == null) { return AjaxResult.error("设备不存在"); @@ -93,9 +92,9 @@ public class TransferDeviceService { device.setTenantName(""); device.setUpdateTime(LocalDateTime.now()); device.setDeviceAlias(""); -// deviceMapper.updateById(device); + // deviceMapper.updateById(device); iDeviceService.updateDeviceBySelf(device); - //判断是否正在控制 如果正在控制,删除控制状态 + // 判断是否正在控制 如果正在控制,删除控制状态 LambdaQueryWrapper lambdaWrapper = new LambdaQueryWrapper<>(); lambdaWrapper.eq(UserClient::getDeviceName, deviceId); List users = userClientMapper.selectList(lambdaWrapper); @@ -108,12 +107,15 @@ public class TransferDeviceService { NettyDevice deviceMaster = sessionManager.getDevice(masterId); if (deviceMaster != null) { String oldSlave = userClient.getDeviceName(); - //删除主的连接关系 - deviceMaster.getConnectedConnectors().removeIf(x -> x.getConnectorId().equals(oldSlave)); - //删除从的连接关系 + // 删除主的连接关系 + deviceMaster.getConnectedConnectors() + .removeIf(x -> x.getConnectorId().equals(oldSlave)); + // 删除从的连接关系 NettyDevice oldSlaveDevice = sessionManager.getDevice(oldSlave); - if (oldSlaveDevice != null && !CollectionUtils.isEmpty(oldSlaveDevice.getConnectedConnectors())) { - Set connectedDevices = oldSlaveDevice.getConnectedConnectors(); + if (oldSlaveDevice != null + && !CollectionUtils.isEmpty(oldSlaveDevice.getConnectedConnectors())) { + Set connectedDevices = oldSlaveDevice + .getConnectedConnectors(); connectedDevices.removeIf(x -> x.getConnectorId().equals(masterId)); } } @@ -130,21 +132,20 @@ public class TransferDeviceService { } } - public AjaxResult updateDeviceAlias(DeviceBindDTO bindDTO, LoginUser user) { try { String deviceId = bindDTO.getDeviceId(); - //判断当前设备是否存 + // 判断当前设备是否存 Device device = iDeviceService.selectDeviceBySerialNumber(deviceId); if (device == null) { return AjaxResult.error("设备不存在"); } else { // Long tenantId = device.getTenantId(); // if (tenantId == -1) { - // return AjaxResult.error("设备未绑定"); + // return AjaxResult.error("设备未绑定"); // } // if (!tenantId.equals(user.getUserId())) { - // return AjaxResult.error("无操作权限"); + // return AjaxResult.error("无操作权限"); // } device.setDeviceAlias(bindDTO.getDeviceAlias()); device.setUpdateTime(LocalDateTime.now()); @@ -158,76 +159,76 @@ public class TransferDeviceService { } } -// public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser user) { -// try { -// String slaveId = bindDTO.getDeviceId(); -// String platform = bindDTO.getPlatform(); -// String userName = user.getUsername(); -// String masterId = userName + ":" + platform; -// //todo 判断是否有权限 正在控制才能切 -// //todo 离线没有控制权的怎么切 -// log.info("switchDevice:{}", masterId); -// NettyDevice deviceMaster = sessionManager.getDevice(masterId); -// log.info("deviceMaster:{}", deviceMaster); -// if (deviceMaster != null) { -// log.info("ConnectorStatus:{}", deviceMaster.getConnectorStatus()); -// if (ConnectorStatus.RECEIVER.equals(deviceMaster.getConnectorStatus())) { -// //当前账号没有控制则可以切换为控制? -// NettyDevice activeDevice = sessionManager.getUserControl(userName); -// deviceMaster.getConnectedConnectors().clear(); -// if (activeDevice == null) { -// log.info("bindConnector ACTIVE :{}", masterId); -// sessionManager.bindConnector(masterId, slaveId); -// deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE); -// deviceMaster.setCurrentSlaveId(slaveId); -// sysUserClientService.updateAliveStatus(masterId, slaveId, 1); -// } else { -// log.info("bindConnector RECEIVER :{}", masterId); -// sessionManager.bindConnector(masterId, slaveId); -// deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); -// deviceMaster.setCurrentSlaveId(slaveId); -// sysUserClientService.updateAliveStatus(masterId, slaveId, 2); -// } -// } else { -// //从关联其他设备切换到 当前禁言 假如有控制且不是当前更新为2 -// List controls = sessionManager.getSlaveControl(slaveId); -// if (CollectionUtils.isEmpty(controls)) { -// deviceMaster.getConnectedConnectors().clear(); -// log.info("bindConnector 1:{}", masterId); -// sessionManager.bindConnector(masterId, slaveId); -// deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE); -// deviceMaster.setCurrentSlaveId(slaveId); -// sysUserClientService.updateAliveStatus(masterId, slaveId, 1); -// } else { -// NettyDevice controlDevice = controls.get(0); -// if (!masterId.equals(controlDevice.getConnectorId())) { -// //当前的设备有控制 的主机 -// deviceMaster.getConnectedConnectors().clear(); -// log.info("bindConnector RECEIVER 2:{}", masterId); -// sessionManager.bindConnector(masterId, slaveId); -// deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); -// deviceMaster.setCurrentSlaveId(slaveId); -// sysUserClientService.updateAliveStatus(masterId, slaveId, 2); -// } -// //当前 切当前不做操作 -// } -// } -// return true; -// } -// } catch (Exception e) { -// log.error("切换设备失败: {}", e.getMessage(), e); -// } -// return false; -// } + // public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser + // user) { + // try { + // String slaveId = bindDTO.getDeviceId(); + // String platform = bindDTO.getPlatform(); + // String userName = user.getUsername(); + // String masterId = userName + ":" + platform; + // //todo 判断是否有权限 正在控制才能切 + // //todo 离线没有控制权的怎么切 + // log.info("switchDevice:{}", masterId); + // NettyDevice deviceMaster = sessionManager.getDevice(masterId); + // log.info("deviceMaster:{}", deviceMaster); + // if (deviceMaster != null) { + // log.info("ConnectorStatus:{}", deviceMaster.getConnectorStatus()); + // if (ConnectorStatus.RECEIVER.equals(deviceMaster.getConnectorStatus())) { + // //当前账号没有控制则可以切换为控制? + // NettyDevice activeDevice = sessionManager.getUserControl(userName); + // deviceMaster.getConnectedConnectors().clear(); + // if (activeDevice == null) { + // log.info("bindConnector ACTIVE :{}", masterId); + // sessionManager.bindConnector(masterId, slaveId); + // deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE); + // deviceMaster.setCurrentSlaveId(slaveId); + // sysUserClientService.updateAliveStatus(masterId, slaveId, 1); + // } else { + // log.info("bindConnector RECEIVER :{}", masterId); + // sessionManager.bindConnector(masterId, slaveId); + // deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); + // deviceMaster.setCurrentSlaveId(slaveId); + // sysUserClientService.updateAliveStatus(masterId, slaveId, 2); + // } + // } else { + // //从关联其他设备切换到 当前禁言 假如有控制且不是当前更新为2 + // List controls = sessionManager.getSlaveControl(slaveId); + // if (CollectionUtils.isEmpty(controls)) { + // deviceMaster.getConnectedConnectors().clear(); + // log.info("bindConnector 1:{}", masterId); + // sessionManager.bindConnector(masterId, slaveId); + // deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE); + // deviceMaster.setCurrentSlaveId(slaveId); + // sysUserClientService.updateAliveStatus(masterId, slaveId, 1); + // } else { + // NettyDevice controlDevice = controls.get(0); + // if (!masterId.equals(controlDevice.getConnectorId())) { + // //当前的设备有控制 的主机 + // deviceMaster.getConnectedConnectors().clear(); + // log.info("bindConnector RECEIVER 2:{}", masterId); + // sessionManager.bindConnector(masterId, slaveId); + // deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); + // deviceMaster.setCurrentSlaveId(slaveId); + // sysUserClientService.updateAliveStatus(masterId, slaveId, 2); + // } + // //当前 切当前不做操作 + // } + // } + // return true; + // } + // } catch (Exception e) { + // log.error("切换设备失败: {}", e.getMessage(), e); + // } + // return false; + // } public synchronized boolean switchDevice(DeviceBindDTO bindDTO) { try { String slaveId = bindDTO.getDeviceId(); -// String platform = bindDTO.getPlatform(); -// String userName = user.getUsername(); - -// String masterId = userName + ":" + platform; + // String platform = bindDTO.getPlatform(); + // String userName = user.getUsername(); + // String masterId = userName + ":" + platform; String token = bindDTO.getToken(); @@ -247,9 +248,10 @@ public class TransferDeviceService { sessionManager.lock(slaveId, token); log.info("switchDevice bindConnector slaveId:{},token:{}", slaveId, token); } else { - List connectorIds = controls.stream().map(NettyDevice::getConnectorId).collect(Collectors.toList()); + List connectorIds = controls.stream().map(NettyDevice::getConnectorId) + .collect(Collectors.toList()); if (!connectorIds.contains(token)) { - //当前的设备有控制 的主机 + // 当前的设备有控制 的主机 deviceMaster.getConnectedConnectors().clear(); sessionManager.bindConnector(token, slaveId); deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); @@ -260,16 +262,15 @@ public class TransferDeviceService { deviceMaster.setCurrentSlaveId(slaveId); sessionManager.lock(slaveId, token); } - //当前 切当前不做操作 + // 当前 切当前不做操作 } return true; } catch (Exception e) { - log.error("切换设备失败: {}", e.getMessage(), e); + log.error("切换设备失败", e); } return false; } - public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO) { try { String token = bindDTO.getToken(); @@ -290,7 +291,6 @@ public class TransferDeviceService { return null; } - public DeviceSwitchControlDTO switchControl(DeviceBindDTO bindDTO, LoginUser user) { try { String slaveId = bindDTO.getDeviceId(); @@ -299,11 +299,11 @@ public class TransferDeviceService { String masterId = userName + ":" + platform; DeviceSwitchControlDTO dto = new DeviceSwitchControlDTO(); - //收到明确的切换设备请求了 从哪边切换到另一边 - //判断当前是否有控制的设备 + // 收到明确的切换设备请求了 从哪边切换到另一边 + // 判断当前是否有控制的设备 NettyDevice masterDevice = sessionManager.getDevice(masterId); if (masterDevice == null || !masterDevice.getChannel().isActive()) { - //主机已离线 + // 主机已离线 dto.setSwitchControl(false); dto.setReason("主机已离线"); return dto; @@ -311,8 +311,8 @@ public class TransferDeviceService { NettyDevice slaveDevice = sessionManager.getDevice(slaveId); if (slaveDevice == null || !masterDevice.getChannel().isActive()) { - //从机已离线 - //主机已离线 + // 从机已离线 + // 主机已离线 dto.setSwitchControl(false); dto.setReason("从机已离线"); return dto; @@ -321,7 +321,7 @@ public class TransferDeviceService { List controlList = sessionManager.getSlaveControl(slaveId); if (!CollectionUtils.isEmpty(controlList)) { - //如果当前设备有控制 + // 如果当前设备有控制 controlList.forEach(c -> { if (!c.getConnectorId().equals(masterId)) { c.setCurrentSlaveId(null); @@ -333,7 +333,8 @@ public class TransferDeviceService { } masterDevice.setCurrentSlaveId(slaveId); masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE); - // sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1); + // sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), + // slaveId, 1); dto.setSwitchControl(true); dto.setHolder(platform); diff --git a/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceRunParamController.java b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceRunParamController.java index 5794f4c..6e6104d 100644 --- a/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceRunParamController.java +++ b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceRunParamController.java @@ -8,13 +8,20 @@ import com.maibu.dto.BaseQueryDTO; import com.maibu.service.impl.DeviceRunParamService; import com.maibu.utils.poi.ExcelUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + @RestController @RequestMapping("/iot/deviceRunParam") public class DeviceRunParamController extends BaseController { @@ -23,7 +30,7 @@ public class DeviceRunParamController extends BaseController { private DeviceRunParamService service; @PostMapping("/save") - public AjaxResult save(@RequestBody DeviceRunParam deviceRunParam) throws ExecutionException, InterruptedException, TimeoutException { + public AjaxResult save(@RequestBody DeviceRunParam deviceRunParam) { return AjaxResult.success(service.save(deviceRunParam)); } @@ -35,7 +42,8 @@ public class DeviceRunParamController extends BaseController { } @GetMapping("/selectByDeviceId") - public AjaxResult selectByDeviceId(@RequestParam String deviceId) throws ExecutionException, InterruptedException, TimeoutException { + public AjaxResult selectByDeviceId(@RequestParam String deviceId) + throws ExecutionException, InterruptedException, TimeoutException { return AjaxResult.success(service.selectByDeviceId(deviceId)); } @@ -43,7 +51,7 @@ public class DeviceRunParamController extends BaseController { public AjaxResult delete(@RequestBody List ids) { return AjaxResult.success(service.delete(ids)); } - + @PostMapping("/importData") public AjaxResult importData(MultipartFile file) throws Exception { ExcelUtil util = new ExcelUtil(DeviceRunParam.class); @@ -51,4 +59,31 @@ public class DeviceRunParamController extends BaseController { boolean message = service.importParam(paramList); return success(message); } + + /** + * 下载机器属性导入模板 + */ + @GetMapping("/downloadTemplate") + public void downloadTemplate(HttpServletResponse response) throws IOException { + String fileName = "机器属性导入模板.xlsx"; + + try (InputStream inputStream = new ClassPathResource("机器属性导入模板.xlsx").getInputStream()) { + + response.setContentType( + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("UTF-8"); + response.setHeader( + "Content-Disposition", + "attachment; filename*=UTF-8''" + + URLEncoder.encode(fileName, "UTF-8").replace("+", "%20")); + + ServletOutputStream outputStream = response.getOutputStream(); + byte[] buffer = new byte[8192]; + int len; + while ((len = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, len); + } + outputStream.flush(); + } + } } diff --git a/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/OrderModelController.java b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/OrderModelController.java index f52780d..0643470 100644 --- a/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/OrderModelController.java +++ b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/OrderModelController.java @@ -3,14 +3,11 @@ package com.maibu.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.maibu.core.business.DeviceRunParam; import com.maibu.core.business.OrderModel; import com.maibu.core.controller.BaseController; import com.maibu.core.domain.AjaxResult; diff --git a/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceRunParamService.java b/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceRunParamService.java index 0f6d0ff..0f92622 100644 --- a/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceRunParamService.java +++ b/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceRunParamService.java @@ -1,7 +1,10 @@ package com.maibu.service.impl; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -39,47 +42,55 @@ public class DeviceRunParamService { @Autowired private DeviceSessionManager sessionManager; - public boolean save(DeviceRunParam deviceRunParam) - throws ExecutionException, InterruptedException, TimeoutException { + // public boolean save(DeviceRunParam deviceRunParam) + // throws ExecutionException, InterruptedException, TimeoutException { - NettyDevice nettyDevice = sessionManager.getDevice(deviceRunParam.getDeviceId()); - if (nettyDevice == null || !nettyDevice.getChannel().isActive()) { - throw new ServiceException("设备不在线,无法操作!"); - } + // NettyDevice nettyDevice = + // sessionManager.getDevice(deviceRunParam.getDeviceId()); + // if (nettyDevice == null || !nettyDevice.getChannel().isActive()) { + // throw new ServiceException("设备不在线,无法操作!"); + // } - CompletableFuture future = new CompletableFuture<>(); - nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future); + // CompletableFuture future = new CompletableFuture<>(); + // nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future); - try { - nettyDevice.readConfigCommand(); + // try { + // nettyDevice.readConfigCommand(); - DeviceRunParam param = future.get(5, TimeUnit.SECONDS); + // DeviceRunParam param = future.get(5, TimeUnit.SECONDS); - if (param == null) { - throw new ServiceException("获取设备当前属性失败!"); - } + // if (param == null) { + // throw new ServiceException("获取设备当前属性失败!"); + // } - param.setLeftForwardGain(deviceRunParam.getLeftForwardGain()); - param.setLeftBackwardGain(deviceRunParam.getLeftBackwardGain()); - param.setRightForwardGain(deviceRunParam.getRightForwardGain()); - param.setRightBackwardGain(deviceRunParam.getRightBackwardGain()); + // param.setLeftForwardGain(deviceRunParam.getLeftForwardGain()); + // param.setLeftBackwardGain(deviceRunParam.getLeftBackwardGain()); + // param.setRightForwardGain(deviceRunParam.getRightForwardGain()); + // param.setRightBackwardGain(deviceRunParam.getRightBackwardGain()); - nettyDevice.writeConfigCommand(param); + // nettyDevice.writeConfigCommand(param); - param.setRunSpeed(deviceRunParam.getRunSpeed()); - param.setDeviceId(deviceRunParam.getDeviceId()); - param.setSiteId(deviceRunParam.getSiteId()); - param.setOrgId(deviceRunParam.getOrgId()); - param.setId(deviceRunParam.getId()); + // param.setRunSpeed(deviceRunParam.getRunSpeed()); + // param.setDeviceId(deviceRunParam.getDeviceId()); + // param.setSiteId(deviceRunParam.getSiteId()); + // param.setOrgId(deviceRunParam.getOrgId()); + // param.setId(deviceRunParam.getId()); + + // SiteMemory siteMemory = GlobalMemory.getSiteMemory(deviceRunParam.getOrgId(), + // deviceRunParam.getSiteId()); + // if (siteMemory != null) { + // siteMemory.saveDeviceRunParam(param); + // } + // return deviceRunParamMapper.saveOrUpdate(param); + // } finally { + // nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null); + // } + // } + + public boolean save(DeviceRunParam deviceRunParam) { + + return deviceRunParamMapper.saveOrUpdate(deviceRunParam); - SiteMemory siteMemory = GlobalMemory.getSiteMemory(deviceRunParam.getOrgId(), deviceRunParam.getSiteId()); - if (siteMemory != null) { - siteMemory.saveDeviceRunParam(param); - } - return deviceRunParamMapper.saveOrUpdate(param); - } finally { - nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null); - } } public List list(BaseQueryDTO dto) { @@ -127,6 +138,49 @@ public class DeviceRunParamService { // return null; // } + // public DeviceRunParam selectByDeviceId(String deviceId) + // throws ExecutionException, InterruptedException, TimeoutException { + + // LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + // if (!StringUtils.isEmpty(deviceId)) { + // queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId); + // } + // DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper); + // if (result != null && result.getHasHost() != null && result.getHasHost() == + // 1) { + // return result; + // } else { + // NettyDevice nettyDevice = sessionManager.getDevice(deviceId); + // CompletableFuture future = new CompletableFuture<>(); + // if (nettyDevice != null && nettyDevice.getChannel() != null && + // nettyDevice.getChannel().isActive()) { + // nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future); + // try { + // nettyDevice.readConfigCommand(); + // DeviceRunParam param = future.get(5, TimeUnit.SECONDS); + + // // LambdaQueryWrapper queryWrapper = new + // LambdaQueryWrapper<>(); + // // if (!StringUtils.isEmpty(deviceId)) { + // // queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId); + // // } + // // DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper); + // if (result != null) { + // param.setId(result.getId()); + // param.setDeviceId(result.getDeviceId()); + // param.setRunSpeed(result.getRunSpeed()); + // param.setOrgId(nettyDevice.getDevice().getOrgId()); + // param.setSiteId(nettyDevice.getDevice().getSiteId()); + // } + // return param; + // } finally { + // nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null); + // } + // } + // } + // return null; + // } + public DeviceRunParam selectByDeviceId(String deviceId) throws ExecutionException, InterruptedException, TimeoutException { @@ -135,36 +189,7 @@ public class DeviceRunParamService { queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId); } DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper); - if (result != null && result.getHasHost() != null && result.getHasHost() == 1) { - return result; - } else { - NettyDevice nettyDevice = sessionManager.getDevice(deviceId); - CompletableFuture future = new CompletableFuture<>(); - if (nettyDevice != null && nettyDevice.getChannel() != null && nettyDevice.getChannel().isActive()) { - nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future); - try { - nettyDevice.readConfigCommand(); - DeviceRunParam param = future.get(5, TimeUnit.SECONDS); - - // LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - // if (!StringUtils.isEmpty(deviceId)) { - // queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId); - // } - // DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper); - if (result != null) { - param.setId(result.getId()); - param.setDeviceId(result.getDeviceId()); - param.setRunSpeed(result.getRunSpeed()); - param.setOrgId(nettyDevice.getDevice().getOrgId()); - param.setSiteId(nettyDevice.getDevice().getSiteId()); - } - return param; - } finally { - nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null); - } - } - } - return null; + return result; } public int delete(List ids) { @@ -211,20 +236,51 @@ public class DeviceRunParamService { } if (deviceRunParam != null) { deviceRunParam.setCapabilityList(x.getCapabilityList()); + + deviceRunParam.setDeviceId(x.getDeviceId()); + + parseSn(x.getDeviceId(), deviceRunParam); + deviceRunParam.setProductModel(x.getProductModel()); - deviceRunParam.setRtkMode(x.getRtkMode()); deviceRunParam.setDeviceType(x.getDeviceType()); - deviceRunParam.setPowerType(x.getPowerType()); + deviceRunParam.setRtkMode(x.getRtkMode()); deviceRunParam.setCameraNum(x.getCameraNum()); + deviceRunParam.setPowerType(x.getPowerType()); deviceRunParam.setWheelType(x.getWheelType()); deviceRunParam.setEngineType(x.getEngineType()); deviceRunParam.setHasHost(x.getHasHost()); + + deviceRunParam.setBatteryType(x.getBatteryType()); + deviceRunParam.setWalkingDriveType(x.getWalkingDriveType()); + deviceRunParam.setCutterDriveType(x.getCutterDriveType()); + deviceRunParam.setRtkAntennasNum(x.getRtkAntennasNum()); + deviceRunParam.setHandleType(x.getHandleType()); + deviceRunParam.setPcbVersion(x.getPcbVersion()); + deviceRunParam.setDimensions(x.getDimensions()); + deviceRunParam.setBladeWidth(x.getBladeWidth()); + deviceRunParam.setTyreSize(x.getTyreSize()); + deviceRunParam.setSpeedRatio(x.getSpeedRatio()); + deviceRunParam.setCellularInfo(x.getCellularInfo()); + deviceRunParam.setWifiName(x.getWifiName()); + deviceRunParam.setBluetoothName(x.getBluetoothName()); + deviceRunParam.setHardwareIdentifiers(x.getHardwareIdentifiers()); + deviceRunParam.setImuModel(x.getImuModel()); + deviceRunParam.setTempHumiditySensor(x.getTempHumiditySensor()); + deviceRunParam.setBarometerPresent(x.getBarometerPresent()); + deviceRunParam.setUltrasonicPresent(x.getUltrasonicPresent()); + deviceRunParam.setDacPresent(x.getDacPresent()); + deviceRunParam.setOperator(x.getOperator()); + deviceRunParam.setInspectionNo(x.getInspectionNo()); + deviceRunParam.setFirmwareVersion(x.getFirmwareVersion()); + deviceRunParam.setDealer(x.getDealer()); + saveList.add(deviceRunParam); } else { + parseSn(x.getDeviceId(), x); saveList.add(x); } }); - //todo 增加 解析sn码的功能 + // todo 增加 解析sn码的功能 return deviceRunParamMapper.saveOrUpdateBatch(saveList); } } @@ -234,4 +290,21 @@ public class DeviceRunParamService { } } + public static void parseSn(String sn, DeviceRunParam deviceRunParam) { + if (sn == null || sn.length() != 21) { + throw new IllegalArgumentException("SN 必须是 21 位字符串"); + } + + deviceRunParam.setProductModel(sn.substring(0, 2)); + deviceRunParam.setFactoryCode(sn.substring(2, 4)); + deviceRunParam.setLineNum(sn.substring(4, 6)); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd"); + LocalDate date = LocalDate.parse(sn.substring(6, 12), formatter); + deviceRunParam.setProductionDate(date); + + deviceRunParam.setSerialNumber(sn.substring(12, 17)); + + } + } diff --git a/maibu-service/maibu-iot-service/src/main/resources/机器属性导入模板.xlsx b/maibu-service/maibu-iot-service/src/main/resources/机器属性导入模板.xlsx new file mode 100755 index 0000000000000000000000000000000000000000..7843badbd5e64050a04a4b74ab6d89fabf33f2ab GIT binary patch literal 11105 zcmeHtWm_ES)^(%7-3jilL4s>=cZbH^C1`MW8V&9a!8N#haJK|W0tEM`XXczYGnqN> zA2_EzRM*v2d-qj$uf6WIMM)M48VdjmfCB&kWPmNYW_=e30DuS<0Kf#mLF$S**t?q9 zyBex_IhwiXGkeRLuo3uknCdol8Ue z)Z>oN!X>GZY?VLBR52b&g3^5dZpn_JL1XUVdXu&o)t1N4e zY!oZrGL5k!Fod|{$TY#4?#}EFIJR8{;H&F0YGW33@4l>njsDo{Rm-W`ZX{l~$hvEw z=E4RgcyMX&xo-Q!f07&JTIST5XV zZCnZka|aMLfkKO6p4Gz3`x@&V=dTmZkNn6H)bN}d9Jhz}fEjx%v=i?7^seN~p>Con ziY;KU5tjd&O)ftyix6G7YfxC)$vxm?<(}t&SU&JvDgtBchWRUbLDi%Hyhu1gmuSK9 z4_{stg7<6gmgfqA{0r?mMy{Vt?_=b`conw=@1OyI=VvH@(qCc~)1b=?5*(|W;7~*a z$Eu;TnXL;8^Ka+>#pr)=VE*aVD--2qq1ezuPXeFG#yj~|>B(npStJhRO&=lH(jSeu z)8h-<9&jl)9@TTLogNs|f#%k=X!$=VYLwvFLWW4rG{IclL`Kx@5yduh;TE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