diff --git a/wms-common/src/main/java/top/wms/admin/common/enums/CommandTypeEnum.java b/wms-common/src/main/java/top/wms/admin/common/enums/CommandTypeEnum.java index cdcf5d8..09af9a9 100644 --- a/wms-common/src/main/java/top/wms/admin/common/enums/CommandTypeEnum.java +++ b/wms-common/src/main/java/top/wms/admin/common/enums/CommandTypeEnum.java @@ -1,6 +1,5 @@ package top.wms.admin.common.enums; - /** * DPA6024V-2T-1.0 数字控制器命令类型枚举 * 定义控制器支持的指令字 @@ -35,6 +34,7 @@ public enum CommandTypeEnum { /** * 获取指令字字符 + * * @return 指令字 (如 '1', '2', '3', '4') */ public char getCommandCode() { @@ -43,6 +43,7 @@ public enum CommandTypeEnum { /** * 根据指令字获取对应的命令类型 + * * @param commandCode 指令字字符 * @return 对应的CommandType,找不到返回null */ diff --git a/wms-module-system/src/main/java/top/wms/admin/light/LightService.java b/wms-module-system/src/main/java/top/wms/admin/light/LightService.java index 4c26f20..7e8dbae 100644 --- a/wms-module-system/src/main/java/top/wms/admin/light/LightService.java +++ b/wms-module-system/src/main/java/top/wms/admin/light/LightService.java @@ -30,7 +30,7 @@ public class LightService { serialHandler.close(); serialHandler = null; } - + // 使用COM1串口 String portName = "COM1"; // 默认波特率9600 @@ -74,6 +74,7 @@ public class LightService { /** * 检查是否已连接 + * * @return 已连接返回true,否则返回false */ public boolean isConnected() { @@ -84,6 +85,7 @@ public class LightService { /** * 检查连接状态并尝试重连 + * * @return 重连成功返回true,否则返回false */ public boolean checkAndReconnect() { @@ -98,6 +100,7 @@ public class LightService { /** * 重新连接控制器 + * * @return 重连成功返回true,否则返回false */ public boolean reconnect() { @@ -117,6 +120,7 @@ public class LightService { /** * 打开指定通道 + * * @param channel 通道号 (1-2) */ public boolean turnOn(int channel) { @@ -125,6 +129,7 @@ public class LightService { /** * 关闭指定通道 + * * @param channel 通道号 (1-2) */ public boolean turnOff(int channel) { @@ -133,7 +138,8 @@ public class LightService { /** * 设置通道亮度 - * @param channel 通道号 (1-2) + * + * @param channel 通道号 (1-2) * @param brightness 亮度等级 (0-255) */ public boolean setBrightness(int channel, int brightness) { @@ -147,6 +153,7 @@ public class LightService { /** * 读取通道亮度 + * * @param channel 通道号 (1-2) * @return 亮度等级 (0-255),失败返回-1 */ @@ -230,7 +237,7 @@ public class LightService { char cmdChar = type.getCommandCode(); // 通道字 (1-2) - char channelChar = (char) (channel + '0'); + char channelChar = (char)(channel + '0'); // 数据: 3字节,亮度的十六进制表示,高位在前 // 亮度值范围0-255,需要转换为3个十六进制ASCII字符 @@ -286,6 +293,7 @@ public class LightService { /** * 便捷方法:设置所有通道亮度 + * * @param brightness 亮度等级 (0-255) */ public void setAllBrightness(int brightness) { @@ -314,5 +322,5 @@ public class LightService { turnOn(channel); } } - + } \ No newline at end of file diff --git a/wms-module-system/src/main/java/top/wms/admin/light/SerialPortHandler.java b/wms-module-system/src/main/java/top/wms/admin/light/SerialPortHandler.java index be618b4..63de24b 100644 --- a/wms-module-system/src/main/java/top/wms/admin/light/SerialPortHandler.java +++ b/wms-module-system/src/main/java/top/wms/admin/light/SerialPortHandler.java @@ -1,6 +1,5 @@ package top.wms.admin.light; - import com.fazecast.jSerialComm.SerialPort; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -20,13 +19,13 @@ public class SerialPortHandler { private InputStream inputStream; private OutputStream outputStream; private SerialPort serialPort; - + /** * 串口名称 */ @Getter private final String portName; - + /** * 波特率 */ @@ -35,6 +34,7 @@ public class SerialPortHandler { /** * 构造函数 + * * @param portName 串口名称,如 "COM3" (Windows) 或 "/dev/ttyUSB0" (Linux) * @param baudRate 波特率 */ @@ -45,6 +45,7 @@ public class SerialPortHandler { /** * 打开串口连接 + * * @return 打开成功返回true,失败返回false */ public boolean open() { @@ -99,6 +100,7 @@ public class SerialPortHandler { /** * 检查串口是否已打开 + * * @return 已打开返回true,否则返回false */ public boolean isOpen() { @@ -107,6 +109,7 @@ public class SerialPortHandler { /** * 发送数据 + * * @param data 要发送的字节数组 */ public void sendData(byte[] data) { @@ -116,7 +119,7 @@ public class SerialPortHandler { log.error("串口 {} 未打开,无法发送数据", portName); return; } - + if (outputStream == null) { log.error("串口 {} 输出流未初始化", portName); return; @@ -131,6 +134,7 @@ public class SerialPortHandler { /** * 发送字符串数据 + * * @param data 要发送的字符串 */ public void sendData(String data) { @@ -144,6 +148,7 @@ public class SerialPortHandler { /** * 接收响应数据 + * * @param timeoutMs 超时时间(毫秒) * @return 接收到的字符串,超时或无数据返回null */ @@ -154,7 +159,7 @@ public class SerialPortHandler { log.error("串口 {} 未打开,无法接收数据", portName); return null; } - + // 验证输入流是否初始化 if (inputStream == null) { log.error("串口 {} 输入流未初始化", portName); @@ -163,8 +168,7 @@ public class SerialPortHandler { // 等待数据到达 long startTime = System.currentTimeMillis(); - while (inputStream.available() == 0 && - (System.currentTimeMillis() - startTime) < timeoutMs) { + while (inputStream.available() == 0 && (System.currentTimeMillis() - startTime) < timeoutMs) { Thread.sleep(10); } @@ -185,7 +189,8 @@ public class SerialPortHandler { /** * 接收指定长度的响应数据 - * @param length 期望接收的字节数 + * + * @param length 期望接收的字节数 * @param timeoutMs 超时时间(毫秒) * @return 接收到的字符串,超时或无数据返回null */ @@ -196,7 +201,7 @@ public class SerialPortHandler { log.error("串口 {} 未打开,无法接收数据", portName); return null; } - + // 验证输入流是否初始化 if (inputStream == null) { log.error("串口 {} 输入流未初始化", portName); @@ -207,8 +212,7 @@ public class SerialPortHandler { int bytesRead = 0; long startTime = System.currentTimeMillis(); - while (bytesRead < length && - (System.currentTimeMillis() - startTime) < timeoutMs) { + while (bytesRead < length && (System.currentTimeMillis() - startTime) < timeoutMs) { if (inputStream.available() > 0) { int read = inputStream.read(buffer, bytesRead, length - bytesRead); if (read > 0) { @@ -276,7 +280,7 @@ public class SerialPortHandler { } } catch (IOException e) { log.error("关闭串口失败: {}", e.getMessage()); - }finally { + } finally { serialPort = null; } } diff --git a/wms-module-system/src/main/java/top/wms/admin/material/model/entity/MaterialInfoDO.java b/wms-module-system/src/main/java/top/wms/admin/material/model/entity/MaterialInfoDO.java index 004d4ee..88457f2 100644 --- a/wms-module-system/src/main/java/top/wms/admin/material/model/entity/MaterialInfoDO.java +++ b/wms-module-system/src/main/java/top/wms/admin/material/model/entity/MaterialInfoDO.java @@ -38,9 +38,9 @@ public class MaterialInfoDO extends BaseDO { private BigDecimal unitWeight; /* - 物料规格 + 物料直径 */ - private String materialSpec; + private Double materialSpec; /** * 物料照片地址 @@ -61,4 +61,9 @@ public class MaterialInfoDO extends BaseDO { * 灯光等级 */ private Integer lightLevel; + + /** + * 颜色 + */ + private String color; } diff --git a/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialImportRowReq.java b/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialImportRowReq.java index 30d8ac3..393f356 100644 --- a/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialImportRowReq.java +++ b/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialImportRowReq.java @@ -46,10 +46,10 @@ public class MaterialImportRowReq implements Serializable { private String lightLevelName; /* - * 物料规格 + * 物料直径 * */ - @Schema(description = "物料规格") - private String materialSpec; + @Schema(description = "物料直径") + private Double materialSpec; /** * 物料类型名称 @@ -63,4 +63,10 @@ public class MaterialImportRowReq implements Serializable { @Schema(description = "物料流程") private String materialProcess; + /** + * 颜色 + */ + @Schema(description = "颜色") + private String color; + } diff --git a/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialInfoReq.java b/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialInfoReq.java index dd7b88a..986957c 100644 --- a/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialInfoReq.java +++ b/wms-module-system/src/main/java/top/wms/admin/material/model/req/MaterialInfoReq.java @@ -48,10 +48,10 @@ public class MaterialInfoReq implements Serializable { private Double unitWeight; /* - * 物料规格 + * 物料直径 * */ - @Schema(description = "物料规格") - private String materialSpec; + @Schema(description = "物料直径") + private Double materialSpec; /** * 物料照片地址 @@ -79,4 +79,10 @@ public class MaterialInfoReq implements Serializable { */ @Schema(description = "灯光等级") private Integer lightLevel; + + /** + * 颜色 + */ + @Schema(description = "颜色") + private String color; } diff --git a/wms-module-system/src/main/java/top/wms/admin/material/model/resp/MaterialInfoResp.java b/wms-module-system/src/main/java/top/wms/admin/material/model/resp/MaterialInfoResp.java index 31bd33b..059145a 100644 --- a/wms-module-system/src/main/java/top/wms/admin/material/model/resp/MaterialInfoResp.java +++ b/wms-module-system/src/main/java/top/wms/admin/material/model/resp/MaterialInfoResp.java @@ -45,11 +45,11 @@ public class MaterialInfoResp extends BaseDetailResp { private Double unitWeight; /** - * 物料规格 + * 物料直径 */ - @Schema(description = "物料规格") - @ExcelProperty(value = "物料规格", order = 5) - private String materialSpec; + @Schema(description = "物料直径") + @ExcelProperty(value = "物料直径", order = 5) + private Double materialSpec; /** * 物料照片地址 @@ -100,4 +100,11 @@ public class MaterialInfoResp extends BaseDetailResp { @ExcelProperty(value = "灯光等级", converter = LightLevelEnumConverter.class, order = 4) private Integer lightLevel; + /** + * 颜色 + */ + @Schema(description = "颜色") + @ExcelProperty(value = "颜色", order = 6) + private String color; + } diff --git a/wms-module-system/src/main/java/top/wms/admin/material/service/impl/MaterialInfoServiceImpl.java b/wms-module-system/src/main/java/top/wms/admin/material/service/impl/MaterialInfoServiceImpl.java index 65e5279..ece9466 100644 --- a/wms-module-system/src/main/java/top/wms/admin/material/service/impl/MaterialInfoServiceImpl.java +++ b/wms-module-system/src/main/java/top/wms/admin/material/service/impl/MaterialInfoServiceImpl.java @@ -51,7 +51,6 @@ import top.wms.admin.material.model.resp.MaterialImportParseResp; import top.wms.admin.material.model.resp.MaterialInfoImportResp; import top.wms.admin.material.model.resp.MaterialInfoResp; import top.wms.admin.material.service.MaterialInfoService; -import top.wms.admin.materialProcess.model.entity.MaterialProcessDO; import top.wms.admin.materialType.mapper.MaterialTypeMapper; import top.wms.admin.materialType.model.entity.MaterialTypeDO; import top.wms.admin.system.service.FileService; @@ -238,8 +237,11 @@ public class MaterialInfoServiceImpl extends BaseServiceImpl().eq("encoding", materialCode)); + CheckUtils.throwIf(ObjectUtil.isEmpty(materialInfoDO), "物料数据异常"); + CheckUtils.throwIf(StrUtil.isBlank(materialInfoDO.getMaterialProcess()), "物料流程编码不能为空"); // 1. 检查连接 Channel channel = channelManager.getFirstChannel(); @@ -38,16 +50,42 @@ public class VmCommandController { } // 2. 清空之前的响应队列,避免影响当前请求 requestMatcher.clear(); - channel.writeAndFlush(materialProcess); + channel.writeAndFlush(materialInfoDO.getMaterialProcess()); // 3. 等待响应 String response = requestMatcher.waitForResponse(20); log.info("sendAndWait-收到响应: {}", response); CheckUtils.throwIf("TIMEOUT".equals(response), "响应超时,请重试"); CheckUtils.throwIf("ERROR".equals(response), "设备连接异常!"); + //如果是圆管,数据格式为yg_yellow_139.092或者yg_yellow + if (response.contains("yg_")) { + CheckUtils.throwIf(null == materialInfoDO.getMaterialSpec(), "物料直径不能为空"); + + String[] split = response.split("_"); + if (split.length != 3) { + throw new BusinessException("位置摆放不标准,未检查出直径"); + } + if (!StrUtil.equals(split[1], materialInfoDO.getColor())) { + throw new BusinessException("颜色不匹配"); + } + + try { + double measuredDiameter = Double.parseDouble(split[2]); + double difference = Math.abs(measuredDiameter - materialInfoDO.getMaterialSpec()); + if (difference > 5) { + throw new BusinessException("直径不匹配"); + } + } catch (NumberFormatException e) { + throw new BusinessException("相机识别异常"); + } + + } else if (StrUtil.equals(response, materialCode)) { + response = "success"; + } else { + response = "failed"; + } return response; } - @PostMapping("/start") public boolean startTask() { return saveBmpTaskService.startTask(); @@ -57,4 +95,4 @@ public class VmCommandController { public boolean stopTask() { return saveBmpTaskService.stopTask(); } -} +} \ No newline at end of file diff --git a/wms-webapi/src/main/resources/templates/import/materialInfo.xlsx b/wms-webapi/src/main/resources/templates/import/materialInfo.xlsx index c9f532d..785e6c7 100644 Binary files a/wms-webapi/src/main/resources/templates/import/materialInfo.xlsx and b/wms-webapi/src/main/resources/templates/import/materialInfo.xlsx differ