Explorar o código

编写称重、倒角、铣面、轧制、大散盘定时任务及对接mes系统

zhifei hai 1 ano
pai
achega
b64a48fe5c
Modificáronse 41 ficheiros con 1116 adicións e 818 borrados
  1. 234 0
      warewms-admin/src/main/resources/application-test.yml
  2. 6 0
      warewms-system/src/main/java/com/warewms/hailiang/MES/MesService.java
  3. 24 2
      warewms-system/src/main/java/com/warewms/hailiang/MES/impl/MesServiceImpl.java
  4. 14 0
      warewms-system/src/main/java/com/warewms/hailiang/config/CodeReadProperties.java
  5. 54 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader12Connect.java
  6. 29 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java
  7. 29 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java
  8. 82 20
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader3Connect.java
  9. 77 14
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader5Connect.java
  10. 56 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader6Connect.java
  11. 54 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader7Connect.java
  12. 29 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader8Connect.java
  13. 29 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader9Connect.java
  14. 91 30
      warewms-system/src/main/java/com/warewms/hailiang/connect/InkjetPrintersConnect.java
  15. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader12Handler.java
  16. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader13Handler.java
  17. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader14Handler.java
  18. 0 49
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader3Handler.java
  19. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader5Handler.java
  20. 0 46
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader6Handler.java
  21. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader7Handler.java
  22. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader8Handler.java
  23. 0 45
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader9Handler.java
  24. 0 50
      warewms-system/src/main/java/com/warewms/hailiang/connect/handler/InkjetPrintersHandler.java
  25. 3 1
      warewms-system/src/main/java/com/warewms/hailiang/domain/Device.java
  26. 8 0
      warewms-system/src/main/java/com/warewms/hailiang/domain/DeviceLog.java
  27. 9 97
      warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveHistory.java
  28. 4 92
      warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveNow.java
  29. 24 0
      warewms-system/src/main/java/com/warewms/hailiang/enums/DaSanPanPlcEnum.java
  30. 5 1
      warewms-system/src/main/java/com/warewms/hailiang/enums/DaoJiaoPlcEnum.java
  31. 9 1
      warewms-system/src/main/java/com/warewms/hailiang/enums/DeviceNameEnum.java
  32. 2 2
      warewms-system/src/main/java/com/warewms/hailiang/enums/InkjetPrintersDirectivesEnum.java
  33. 3 3
      warewms-system/src/main/java/com/warewms/hailiang/enums/WeighPlcEnum.java
  34. 20 0
      warewms-system/src/main/java/com/warewms/hailiang/enums/XiMianPlcEnum.java
  35. 20 0
      warewms-system/src/main/java/com/warewms/hailiang/enums/ZhaZhiPlcEnum.java
  36. 28 14
      warewms-system/src/main/java/com/warewms/hailiang/init/TcpServiceRunner.java
  37. 47 10
      warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java
  38. 8 2
      warewms-system/src/main/java/com/warewms/hailiang/service/ProcessRealizationService.java
  39. 48 19
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/ProcessRealizationServiceImpl.java
  40. 67 0
      warewms-system/src/main/java/com/warewms/hailiang/util/InkjetPrintersSetUpTools.java
  41. 3 1
      warewms-system/src/main/java/com/warewms/hailiang/util/ParseMsgTools.java

+ 234 - 0
warewms-admin/src/main/resources/application-test.yml

@@ -0,0 +1,234 @@
+# 项目相关配置
+warewms:
+  # 名称
+  name: automated warehouse management system
+  # 版本
+  version: 1.0
+  # 版权年份
+  copyrightYear: 2023
+  # 实例演示开关
+  demoEnabled: true
+  # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
+  profile: D:/warewms/uploadPath
+  # 获取ip地址开关
+  addressEnabled: false
+  # 验证码类型 math 数组计算 char 字符验证
+  captchaType: math
+
+# 开发环境配置
+server:
+  # 服务器的HTTP端口,默认为8080
+  port: 8080
+  servlet:
+    # 应用的访问路径
+    context-path: /
+  tomcat:
+    # tomcat的URI编码
+    uri-encoding: UTF-8
+    # 连接数满后的排队数,默认为100
+    accept-count: 1000
+    threads:
+      # tomcat最大线程数,默认为200
+      max: 800
+      # Tomcat启动初始化的线程数,默认值10
+      min-spare: 100
+
+# 日志配置
+logging:
+  level:
+    com.ruoyi: debug
+    org.springframework: warn
+
+# 用户配置
+user:
+  password:
+    # 密码最大错误次数
+    maxRetryCount: 5
+    # 密码锁定时间(默认10分钟)
+    lockTime: 10
+
+# Spring配置
+spring:
+  # 资源信息
+  messages:
+    # 国际化资源文件路径
+    basename: i18n/messages
+  # 文件上传
+  servlet:
+     multipart:
+       # 单个文件大小
+       max-file-size:  10MB
+       # 设置总上传的文件大小
+       max-request-size:  20MB
+  # 数据源配置
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driverClassName: com.mysql.cj.jdbc.Driver
+    druid:
+      # 主库数据源
+      master:
+        url: jdbc:mysql://localhost:3306/ahhl_tarece?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+        username: root
+        password: root
+      # 从库数据源
+      slave:
+        # 从数据源开关/默认关闭
+        enabled: false
+        url:
+        username:
+        password:
+      # 初始连接数
+      initialSize: 5
+      # 最小连接池数量
+      minIdle: 10
+      # 最大连接池数量
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置连接超时时间
+      connectTimeout: 30000
+      # 配置网络超时时间
+      socketTimeout: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      # 配置一个连接在池中最大生存的时间,单位是毫秒
+      maxEvictableIdleTimeMillis: 900000
+      # 配置检测连接是否有效
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      webStatFilter:
+        enabled: true
+      statViewServlet:
+        enabled: true
+        # 设置白名单,不填则允许所有访问
+        allow:
+        url-pattern: /druid/*
+        # 控制台管理用户名和密码
+        login-username: admin
+        login-password: 123456
+      filter:
+        stat:
+          enabled: true
+          # 慢SQL记录
+          log-slow-sql: true
+          slow-sql-millis: 1000
+          merge-sql: true
+        wall:
+          config:
+            multi-statement-allow: true
+  # redis 配置
+  redis:
+    # 地址
+    host: localhost
+    # 端口,默认为6379
+    port: 6379
+    # 数据库索引
+    database: 0
+    # 密码
+    password:
+    # 连接超时时间
+    timeout: 10s
+    lettuce:
+      pool:
+        # 连接池中的最小空闲连接
+        min-idle: 0
+        # 连接池中的最大空闲连接
+        max-idle: 8
+        # 连接池的最大数据库连接数
+        max-active: 8
+        # #连接池最大阻塞等待时间(使用负值表示没有限制)
+        max-wait: -1ms
+
+# token配置
+token:
+    # 令牌自定义标识
+    header: Authorization
+    # 令牌密钥
+    secret: abcdefghijklmnopqrstuvwxyz
+    # 令牌有效期(默认30分钟)
+    expireTime: 30
+
+# MyBatis Plus配置
+mybatis-plus:
+
+  mapper-locations: classpath*:/mapper/**/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml
+  #实体扫描,多个package用逗号或者分号分隔
+  # 不支持多包, 如有需要可在注解配置 或 提升扫包等级
+  # 例如 com.**.**.mapper
+  mapperPackage: com.warewms.**.mapper
+  # 实体扫描,多个package用逗号或者分号分隔
+  typeAliasesPackage: com.warewms.**.domain
+  configuration:
+    # 自动驼峰命名规则(camel case)映射
+    mapUnderscoreToCamelCase: true
+    # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
+    # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
+    logImpl: org.apache.ibatis.logging.stdout.StdOutImpl
+  global-config:
+    # 是否打印 Logo banner
+    banner: false
+    dbConfig:
+      # 主键类型
+      # AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID
+      idType: AUTO
+      logic-delete-field: deleted # 全局逻辑删除的实体字段名
+      logic-delete-value: 1 # 逻辑已删除值(默认为 1)
+      logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
+
+
+# Knife4j配置
+knife4j:
+  #开启增强配置
+  enable: true
+  #开启生产环境屏蔽
+  production: false
+  basic:
+    enable: false
+    username: admin
+    password: 123456
+
+# 防止XSS攻击
+xss:
+  # 过滤开关
+  enabled: true
+  # 排除链接(多个用逗号分隔)
+  excludes: /system/notice
+  # 匹配链接
+  urlPatterns: /system/*,/monitor/*,/tool/*
+
+# plc连接配置
+plc:
+  plcList[0]:
+    ip: 172.20.52.21
+    enable: false
+    name: ChengZhongPlc
+    ePlcType: S1200
+    heartbeat:
+  plcList[1]:
+    ip: 172.20.27.2
+    enable: false
+    name: DaoJiaoJiPlc
+    ePlcType: S200_SMART
+    heartbeat:
+  plcList[2]:
+    ip: 172.20.52.22
+    enable: false
+    name: XiMianPlc
+    ePlcType: S1200
+    heartbeat: BD200.0.0
+  plcList[3]:
+    ip: 172.20.52.24
+    enable: false
+    name: ZhaZhiPlc
+    ePlcType: S1500
+    heartbeat: BD300.0.0
+  plcList[4]:
+    ip: 172.20.54.121
+    enable: false
+    name: DaSanPanPlc
+    ePlcType: S1500
+    heartbeat: BD200.0.0

+ 6 - 0
warewms-system/src/main/java/com/warewms/hailiang/MES/MesService.java

@@ -28,4 +28,10 @@ public interface MesService {
      * @return
      */
     public JSONObject getBatchNoResult(String batchNo,boolean result);
+
+
+    /**
+     * 工艺反馈接口
+     */
+    public JSONObject processFeedback(String batchNo,String type);
 }

+ 24 - 2
warewms-system/src/main/java/com/warewms/hailiang/MES/impl/MesServiceImpl.java

@@ -34,6 +34,8 @@ public class MesServiceImpl implements MesService {
     @Value("${MES.getBatchNoResultUrl}")
     private String getBatchNoResultURl;
 
+    @Value("${MES.processFeedbackUrl}")
+    private String processFeedbackUrl;
 
 
     @Override
@@ -45,7 +47,6 @@ public class MesServiceImpl implements MesService {
         String body = null;
         try {
           body = HttpRequest.post(MESAddress + getBatchNoUrl).body(entries.toString()).execute().body();
-
         }catch (Exception e){
             log.error("调用MES系统拿铜管批次号失败,msg:{}",e.getMessage());
             return null;
@@ -64,6 +65,27 @@ public class MesServiceImpl implements MesService {
         entries.set("BatchNo",batchNo);
         entries.set("Result",result);
         String body = HttpRequest.post(MESAddress + getBatchNoResultURl).body(entries.toString()).execute().body();
-        return  JSONUtil.parseObj(body);
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        if ("false".equals(jsonObject.get("ret"))){
+            log.error("喷码成功反馈MES失败,msg:{}",jsonObject.get("message"));
+            return null;
+        }
+
+        return jsonObject;
+    }
+
+    @Override
+    public JSONObject processFeedback(String batchNo, String type) {
+        JSONObject entries = new JSONObject();
+        entries.set("BatchNo",batchNo);
+        entries.set("Type",type);
+        String body = HttpRequest.post(MESAddress + processFeedbackUrl).body(entries.toString()).execute().body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        if ("false".equals(jsonObject.get("ret"))){
+            log.error("喷码成功反馈MES失败,msg:{}",jsonObject.get("message"));
+            return null;
+        }
+
+        return jsonObject;
     }
 }

+ 14 - 0
warewms-system/src/main/java/com/warewms/hailiang/config/CodeReadProperties.java

@@ -0,0 +1,14 @@
+package com.warewms.hailiang.config;
+
+
+public class CodeReadProperties {
+    /**
+     * 触发读码
+     */
+    public static String startTheCommand = "T";
+
+    /**
+     * 失败返回
+     */
+    public static String failureReturnInstruction ="NG";
+}

+ 54 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader12Connect.java

@@ -2,18 +2,22 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader12Handler;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
+import javax.annotation.Resource;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -37,7 +41,7 @@ public class CodeReader12Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader12";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -45,7 +49,10 @@ public class CodeReader12Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
 
+    @Resource
+    RetroactiveNowService retroactiveNowService;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +66,20 @@ public class CodeReader12Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader12Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +142,31 @@ public class CodeReader12Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+    @Override
+    public void processMessages(String message) {
+        try {
+            log.info("大散盘4号行车读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setBatchNo(message);
+                retroactiveNow.setStatus("8");
+                retroactiveNow.setDeviceId("Z1_DaSanPan_DMQ-4-27.12");
+                retroactiveNowService.updateData(retroactiveNow);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("大散盘4号行车读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
+    }
 }

+ 29 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java

@@ -2,16 +2,15 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader13Handler;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.Callable;
@@ -45,7 +44,7 @@ public class CodeReader13Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
-
+    private ChannelPipeline pipeline;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +58,20 @@ public class CodeReader13Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader13Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +134,14 @@ public class CodeReader13Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return null;
+    }
+
+    @Override
+    public void processMessages(String message) {
+
+    }
 }

+ 29 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java

@@ -2,16 +2,15 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader14Handler;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.Callable;
@@ -45,7 +44,7 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
-
+    private ChannelPipeline pipeline;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +58,20 @@ public class CodeReader14Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader14Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +134,14 @@ public class CodeReader14Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return null;
+    }
+
+    @Override
+    public void processMessages(String message) {
+
+    }
 }

+ 82 - 20
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader3Connect.java

@@ -2,18 +2,29 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader3Handler;
+import com.jhlabs.image.OilFilter;
+import com.warewms.hailiang.MES.MesService;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.enums.DaoJiaoPlcEnum;
+import com.warewms.hailiang.enums.DeviceNameEnum;
+import com.warewms.hailiang.init.PlcConnectServiceRunner;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -33,11 +44,11 @@ public class CodeReader3Connect implements TCPConnectBase {
 
     private final String IP_ADDR = "172.20.27.3";
 
-    private final String deviceName ="CodeReader3";
+    private final String deviceName = "CodeReader3";
 
     private final int PORT = 51236;
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -45,12 +56,19 @@ public class CodeReader3Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
 
+    @Resource
+    MesService mesService;
+    @Resource
+    RetroactiveNowService retroactiveNowService;
+    @Resource
+    PlcConnectServiceRunner plcConnectServiceRunner;
 
     @Override
     public void init() throws InterruptedException {
-        if (enable){
-            log.info("ip:{},deviceName:{}正在进行连接",IP_ADDR,deviceName);
+        if (enable) {
+            log.info("ip:{},deviceName:{}正在进行连接", IP_ADDR, deviceName);
             group = new NioEventLoopGroup();
             try {
                 bootstrap = new Bootstrap();
@@ -59,21 +77,35 @@ public class CodeReader3Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader3Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter() {
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!", deviceName);
+                                        retry();
+                                    }
+
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
                 future.addListener((channelFuture) -> {
                     if (channelFuture.isSuccess()) {
-                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
-                        log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
-                    }else {
-                        log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
+                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
+                        log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                    } else {
+                        log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
                     }
                 });
             } catch (Exception e) {
-                log.error("ip:{},deviceName:{}连接异常,{},准备重试",IP_ADDR,deviceName, e.getMessage());
+                log.error("ip:{},deviceName:{}连接异常,{},准备重试", IP_ADDR, deviceName, e.getMessage());
                 retry();
             }
         }
@@ -90,17 +122,18 @@ public class CodeReader3Connect implements TCPConnectBase {
         try {
             retryer.call(new Callable<Boolean>() {
                 AtomicBoolean isSuccess = new AtomicBoolean(false);
+
                 @Override
                 public Boolean call() throws Exception {
-                    log.info("ip:{},deviceName:{}连接重试",IP_ADDR,deviceName);
+                    log.info("ip:{},deviceName:{}连接重试", IP_ADDR, deviceName);
                     future = bootstrap.connect(IP_ADDR, PORT).sync();
                     future.addListener((channelFuture) -> {
                         isSuccess.set(channelFuture.isSuccess());
                         if (channelFuture.isSuccess()) {
-                            SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
-                            log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
-                        }else {
-                            log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
+                            SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
+                            log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        } else {
+                            log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         }
                     });
                     Thread.sleep(3000);
@@ -122,4 +155,33 @@ public class CodeReader3Connect implements TCPConnectBase {
         return deviceName;
     }
 
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+    @Override
+    public void processMessages(String message) {
+        try {
+            log.info("倒角机读码器读码结果,{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                //读码失败
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJia_DMQ-1-27.3", deviceName, "未识别到码", "2"));
+                return;
+            }
+            //修改数据库信息
+            RetroactiveNow retroactiveNow = new RetroactiveNow();
+            retroactiveNow.setBatchNo(message);
+            retroactiveNow.setStatus("");
+            retroactiveNowService.updateData(retroactiveNow);
+            //上传MES系统
+            mesService.getBatchNoResult(message, true);
+            //回写PLC读码完成
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeBoolean(DaoJiaoPlcEnum.RETURNOUTCOME.getMetadata(),false);
+        }catch (Exception e){
+            log.error("倒角读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJia_DMQ-1-27.3", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
+    }
+
 }

+ 77 - 14
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader5Connect.java

@@ -2,18 +2,26 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader5Handler;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.enums.DeviceNameEnum;
+import com.warewms.hailiang.enums.XiMianPlcEnum;
+import com.warewms.hailiang.init.PlcConnectServiceRunner;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -26,16 +34,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Date: 2023/8/9
  * Time: 15:45
  * To change this template use File | Settings | File Templates.
- * Description:倒角读码器连接
+ * Description:铣面读码器连接
  **/
 @Slf4j
+@Service
 public class CodeReader5Connect implements TCPConnectBase {
 
     private final String IP_ADDR = "172.20.27.5";
 
     private final int PORT = 51236;
 
-    private final String deviceName ="CodeReader5";
+    private final String deviceName = "CodeReader5";
 
     private boolean enable = false;
 
@@ -45,8 +54,15 @@ public class CodeReader5Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
 
 
+    @Resource
+    RetroactiveNowService retroactiveNowService;
+
+    @Resource
+    PlcConnectServiceRunner plcConnectServiceRunner;
+
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -58,14 +74,30 @@ public class CodeReader5Connect implements TCPConnectBase {
                         .option(ChannelOption.TCP_NODELAY, true)
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
-                            protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader5Handler());
+                            protected void initChannel(SocketChannel socketChannel) {
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter() {
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        log.error("设备:{}连接已断开!", deviceName);
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        retry();
+                                    }
+
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
                 future.addListener((channelFuture) -> {
                     if (channelFuture.isSuccess()) {
+
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
+
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
@@ -90,17 +122,18 @@ public class CodeReader5Connect implements TCPConnectBase {
         try {
             retryer.call(new Callable<Boolean>() {
                 AtomicBoolean isSuccess = new AtomicBoolean(false);
+
                 @Override
                 public Boolean call() throws Exception {
-                    log.info("ip:{},deviceName:{}连接重试",IP_ADDR,deviceName);
+                    log.info("ip:{},deviceName:{}连接重试", IP_ADDR, deviceName);
                     future = bootstrap.connect(IP_ADDR, PORT).sync();
                     future.addListener((channelFuture) -> {
                         isSuccess.set(channelFuture.isSuccess());
                         if (channelFuture.isSuccess()) {
-                            SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
-                            log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
-                        }else {
-                            log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
+                            SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
+                            log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        } else {
+                            log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         }
                     });
                     Thread.sleep(3000);
@@ -121,4 +154,34 @@ public class CodeReader5Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+    @Override
+    public void processMessages(String message) {
+        try {
+            log.info("铣面读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setBatchNo(message);
+                retroactiveNow.setStatus("6");
+                retroactiveNow.setDeviceId("Z1_XiMian_DMQ-1-27.5");
+                retroactiveNowService.updateData(retroactiveNow);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.XIMIANPLC.getDeviceName()).writeBoolean(XiMianPlcEnum.ISREAD.getMetadata(), false);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "识别到码:" + message, "1"));
+            }
+        } catch (Exception e) {
+            log.error("铣面读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
+    }
+
+
 }

+ 56 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader6Connect.java

@@ -2,18 +2,23 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader6Handler;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -29,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Description:倒角读码器连接
  **/
 @Slf4j
+@Service
 public class CodeReader6Connect implements TCPConnectBase {
 
     private final String IP_ADDR = "172.20.27.6";
@@ -37,7 +43,7 @@ public class CodeReader6Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader6";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -45,7 +51,10 @@ public class CodeReader6Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
 
+    @Resource
+    RetroactiveNowService retroactiveNowService;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +68,20 @@ public class CodeReader6Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader6Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -121,4 +143,31 @@ public class CodeReader6Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+    @Override
+    public void processMessages(String message) {
+        try {
+            log.info("轧制读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setBatchNo(message);
+                retroactiveNow.setStatus("7");
+                retroactiveNow.setDeviceId("Z1_ZhaZhi_DMQ-1-27.6");
+                retroactiveNowService.updateData(retroactiveNow);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("轧制读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
+    }
 }

+ 54 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader7Connect.java

@@ -2,18 +2,22 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader7Handler;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
+import javax.annotation.Resource;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -37,7 +41,7 @@ public class CodeReader7Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader7";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -45,7 +49,10 @@ public class CodeReader7Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
 
+    @Resource
+    RetroactiveNowService retroactiveNowService;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +66,20 @@ public class CodeReader7Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader7Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +142,31 @@ public class CodeReader7Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+    @Override
+    public void processMessages(String message) {
+        try {
+            log.info("大散盘1号行车读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setBatchNo(message);
+                retroactiveNow.setStatus("8");
+                retroactiveNow.setDeviceId("Z1_DaSanPan_DMQ-1-27.7");
+                retroactiveNowService.updateData(retroactiveNow);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("大散盘1号行车读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
+    }
 }

+ 29 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader8Connect.java

@@ -2,16 +2,15 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader8Handler;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.Callable;
@@ -45,7 +44,7 @@ public class CodeReader8Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
-
+    private ChannelPipeline pipeline;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +58,20 @@ public class CodeReader8Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader8Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +134,14 @@ public class CodeReader8Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return null;
+    }
+
+    @Override
+    public void processMessages(String message) {
+
+    }
 }

+ 29 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader9Connect.java

@@ -2,16 +2,15 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.CodeReader9Handler;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.Callable;
@@ -45,7 +44,7 @@ public class CodeReader9Connect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
-
+    private ChannelPipeline pipeline;
 
     @Override
     public void init() throws InterruptedException {
@@ -59,7 +58,20 @@ public class CodeReader9Connect implements TCPConnectBase {
                         .handler(new ChannelInitializer<SocketChannel>() {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
-                                socketChannel.pipeline().addLast(new CodeReader9Handler());
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!",deviceName);
+                                        retry();
+                                    }
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
+                                    }
+                                });
                             }
                         });
                 future = bootstrap.connect(IP_ADDR, PORT).sync();
@@ -122,4 +134,14 @@ public class CodeReader9Connect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return null;
+    }
+
+    @Override
+    public void processMessages(String message) {
+
+    }
 }

+ 91 - 30
warewms-system/src/main/java/com/warewms/hailiang/connect/InkjetPrintersConnect.java

@@ -1,15 +1,20 @@
 package com.warewms.hailiang.connect;
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
-import com.warewms.hailiang.connect.handler.InkjetPrintersHandler;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
+import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.enums.InkjetPrintersDirectivesEnum;
+import com.warewms.hailiang.util.ParseMsgTools;
 import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
-import lombok.CustomLog;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -30,9 +35,11 @@ public class InkjetPrintersConnect implements TCPConnectBase {
 
     private final String IP_ADDR = "172.20.27.4";
 
-    private final int PORT = 9999;
+    private final int PORT = 51236;
 
-    private final String deviceName ="InkjetPrinters";
+    private final String deviceName = "InkjetPrinters";
+
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -40,34 +47,57 @@ public class InkjetPrintersConnect implements TCPConnectBase {
 
     private EventLoopGroup group;
 
+    private ChannelPipeline pipeline;
+
+    private boolean isInitRoutine = false;
+
+    private String movement;
 
 
     @Override
     public void init() throws InterruptedException {
-        log.info("喷码机正在进行连接");
-        group = new NioEventLoopGroup();
-        try {
-            bootstrap = new Bootstrap();
-            bootstrap.group(group).channel(NioSocketChannel.class)
-                    .option(ChannelOption.TCP_NODELAY, true)
-                    .handler(new ChannelInitializer<SocketChannel>() {
-                        @Override
-                        protected void initChannel(SocketChannel socketChannel) throws Exception {
-                            socketChannel.pipeline().addLast(new InkjetPrintersHandler());
-                        }
-                    });
-            future = bootstrap.connect(IP_ADDR, PORT).sync();
-            future.addListener((channelFuture) -> {
-                if (channelFuture.isSuccess()) {
-                    log.info("喷码机连接成功");
-                }else {
-                    log.info("连接失败等待重试!");
-                    retry();
-                }
-            });
-        } catch (Exception e) {
-            log.error("喷码设备连接异常,{},准备重试", e.getMessage());
-            retry();
+        if (enable) {
+            log.info("喷码机正在进行连接");
+            group = new NioEventLoopGroup();
+            try {
+                bootstrap = new Bootstrap();
+                bootstrap.group(group).channel(NioSocketChannel.class)
+                        .option(ChannelOption.TCP_NODELAY, true)
+                        .handler(new ChannelInitializer<SocketChannel>() {
+                            @Override
+                            protected void initChannel(SocketChannel socketChannel) throws Exception {
+                                pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new ChannelInboundHandlerAdapter() {
+                                    @Override
+                                    public void channelInactive(ChannelHandlerContext ctx) {
+                                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        log.error("设备:{}连接已断开!", deviceName);
+                                        retry();
+                                    }
+
+                                    @Override
+                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                                        ByteBuf byteBuf = (ByteBuf) msg;
+                                        processMessages(ParseMsgTools.StringTohexString(byteBuf.toString(CharsetUtil.US_ASCII)));
+                                    }
+                                });
+                            }
+                        });
+                future = bootstrap.connect(IP_ADDR, PORT).sync();
+                future.addListener((channelFuture) -> {
+                    if (channelFuture.isSuccess()) {
+                        initRoutine();
+                        SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
+                        log.info("喷码机连接成功");
+                    } else {
+                        log.info("连接失败等待重试!");
+                        retry();
+                    }
+                });
+            } catch (Exception e) {
+                log.error("喷码设备连接异常,{},准备重试", e.getMessage());
+                retry();
+            }
         }
     }
 
@@ -82,6 +112,7 @@ public class InkjetPrintersConnect implements TCPConnectBase {
         try {
             retryer.call(new Callable<Boolean>() {
                 AtomicBoolean isSuccess = new AtomicBoolean(false);
+
                 @Override
                 public Boolean call() throws Exception {
                     log.info("喷码机连接重试");
@@ -89,8 +120,10 @@ public class InkjetPrintersConnect implements TCPConnectBase {
                     future.addListener((channelFuture) -> {
                         isSuccess.set(channelFuture.isSuccess());
                         if (channelFuture.isSuccess()) {
+                            initRoutine();
+                            SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                             log.info("喷码机连接成功");
-                        }else {
+                        } else {
                             log.info("连接失败等待重试!");
                         }
                     });
@@ -113,4 +146,32 @@ public class InkjetPrintersConnect implements TCPConnectBase {
     public String getDeviceName() {
         return deviceName;
     }
+
+    @Override
+    public ChannelPipeline getChannel() {
+        return pipeline;
+    }
+
+
+    @Override
+    public void processMessages(String message) {
+        log.info("喷码器消息:{}", message);
+        if ("f7".equalsIgnoreCase(message)) {
+            log.info("喷码机打印成功!");
+        }
+        if ("6".equals(message)){
+            log.info(movement+"完成");
+        }
+    }
+
+    /**
+     * 初始化打印设置
+     */
+    private void initRoutine() {
+        if (!isInitRoutine) {
+            log.info("初始化打印设置");
+            movement = "初始化打印设置";
+            pipeline.writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.hexString2Bytes(InkjetPrintersDirectivesEnum.CODE41.getCode())));
+        }
+    }
 }

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader12Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader12Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader12";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader13Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader13Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader13";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader14Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader14Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader14";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 49
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader3Handler.java

@@ -1,49 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.enums.CodeReaderEnum;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import com.warewms.hailiang.util.ParseMsgTools;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader3Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader3";
-
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer(CodeReaderEnum.readCode.toString(), CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader5Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader5Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader5";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 46
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader6Handler.java

@@ -1,46 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader6Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader6";
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader7Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader7Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader7";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader8Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader8Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader8";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 45
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/CodeReader9Handler.java

@@ -1,45 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class CodeReader9Handler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="CodeReader9";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer("T", CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 0 - 50
warewms-system/src/main/java/com/warewms/hailiang/connect/handler/InkjetPrintersHandler.java

@@ -1,50 +0,0 @@
-package com.warewms.hailiang.connect.handler;
-
-import com.warewms.common.annotation.Log;
-import com.warewms.hailiang.connect.InkjetPrintersConnect;
-import com.warewms.hailiang.init.TcpServiceRunner;
-import com.warewms.hailiang.util.ParseMsgTools;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-
-/**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
-@Slf4j
-@Component
-public class InkjetPrintersHandler extends ChannelInboundHandlerAdapter  {
-
-    private final String deviceName ="InkjetPrinters";
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        ctx.writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.StringTohexString(""), CharsetUtil.UTF_8));
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        ByteBuf byteBuf = (ByteBuf) msg;
-        log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("设备:{}连接已断开!",deviceName);
-        InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList((deviceName));
-        inkjetPrintersConnect.retry();
-        super.channelInactive(ctx);
-    }
-}

+ 3 - 1
warewms-system/src/main/java/com/warewms/hailiang/domain/Device.java

@@ -10,10 +10,11 @@ import java.io.Serializable;
 
 /**
  * 设备表
+ *
  * @TableName device
  */
 @Data
-public class Device extends BaseEntity implements Serializable  {
+public class Device extends BaseEntity implements Serializable {
 
     /**
      * 设备编号
@@ -63,6 +64,7 @@ public class Device extends BaseEntity implements Serializable  {
         this.ip = ip;
         this.port = port;
         this.connectionType = connectionType;
+        this.status = status;
     }
 
     public Device(String deviceName, String status) {

+ 8 - 0
warewms-system/src/main/java/com/warewms/hailiang/domain/DeviceLog.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.warewms.common.core.domain.base.BaseEntity;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 
@@ -14,6 +15,7 @@ import java.io.Serializable;
  */
 @Data
 @TableName("device_log")
+@NoArgsConstructor
 public class DeviceLog extends BaseEntity implements Serializable  {
     /**
      * 日志编号
@@ -43,4 +45,10 @@ public class DeviceLog extends BaseEntity implements Serializable  {
 
     private static final long serialVersionUID = 1L;
 
+    public DeviceLog(String deviceId, String deviceName, String content, String status) {
+        this.deviceId = deviceId;
+        this.deviceName = deviceName;
+        this.content = content;
+        this.status = status;
+    }
 }

+ 9 - 97
warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveHistory.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+
+import com.warewms.common.core.domain.base.BaseEntity;
 import lombok.Data;
 
 /**
@@ -13,11 +15,16 @@ import lombok.Data;
  */
 @TableName(value ="retroactive_history")
 @Data
-public class RetroactiveHistory implements Serializable {
+public class RetroactiveHistory extends BaseEntity {
+
     /**
-     * 追溯id
+     * 历史追溯编号
      */
     @TableId
+    private Long historyId;
+    /**
+     * 追溯id
+     */
     private String retroactiveId;
 
     /**
@@ -50,99 +57,4 @@ public class RetroactiveHistory implements Serializable {
      */
     private String deviceId;
 
-    /**
-     * 创建者
-     */
-    private String createBy;
-
-    /**
-     * 创建时间
-     */
-    private LocalDateTime createTime;
-
-    /**
-     * 更新者
-     */
-    private String updateBy;
-
-    /**
-     * 更新时间
-     */
-    private LocalDateTime updateTime;
-
-    /**
-     * 备注
-     */
-    private String remark;
-
-    @TableField(exist = false)
-    private static final long serialVersionUID = 1L;
-
-    @Override
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        }
-        if (that == null) {
-            return false;
-        }
-        if (getClass() != that.getClass()) {
-            return false;
-        }
-        RetroactiveHistory other = (RetroactiveHistory) that;
-        return (this.getRetroactiveId() == null ? other.getRetroactiveId() == null : this.getRetroactiveId().equals(other.getRetroactiveId()))
-            && (this.getProductionLine() == null ? other.getProductionLine() == null : this.getProductionLine().equals(other.getProductionLine()))
-            && (this.getBatchNo() == null ? other.getBatchNo() == null : this.getBatchNo().equals(other.getBatchNo()))
-            && (this.getLotNo() == null ? other.getLotNo() == null : this.getLotNo().equals(other.getLotNo()))
-            && (this.getWeight() == null ? other.getWeight() == null : this.getWeight().equals(other.getWeight()))
-            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
-            && (this.getDeviceId() == null ? other.getDeviceId() == null : this.getDeviceId().equals(other.getDeviceId()))
-            && (this.getCreateBy() == null ? other.getCreateBy() == null : this.getCreateBy().equals(other.getCreateBy()))
-            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
-            && (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()))
-            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
-            && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()));
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((getRetroactiveId() == null) ? 0 : getRetroactiveId().hashCode());
-        result = prime * result + ((getProductionLine() == null) ? 0 : getProductionLine().hashCode());
-        result = prime * result + ((getBatchNo() == null) ? 0 : getBatchNo().hashCode());
-        result = prime * result + ((getLotNo() == null) ? 0 : getLotNo().hashCode());
-        result = prime * result + ((getWeight() == null) ? 0 : getWeight().hashCode());
-        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
-        result = prime * result + ((getDeviceId() == null) ? 0 : getDeviceId().hashCode());
-        result = prime * result + ((getCreateBy() == null) ? 0 : getCreateBy().hashCode());
-        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
-        result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
-        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
-        result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getClass().getSimpleName());
-        sb.append(" [");
-        sb.append("Hash = ").append(hashCode());
-        sb.append(", retroactiveId=").append(retroactiveId);
-        sb.append(", productionLine=").append(productionLine);
-        sb.append(", batchNo=").append(batchNo);
-        sb.append(", lotNo=").append(lotNo);
-        sb.append(", weight=").append(weight);
-        sb.append(", status=").append(status);
-        sb.append(", deviceId=").append(deviceId);
-        sb.append(", createBy=").append(createBy);
-        sb.append(", createTime=").append(createTime);
-        sb.append(", updateBy=").append(updateBy);
-        sb.append(", updateTime=").append(updateTime);
-        sb.append(", remark=").append(remark);
-        sb.append(", serialVersionUID=").append(serialVersionUID);
-        sb.append("]");
-        return sb.toString();
-    }
 }

+ 4 - 92
warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveNow.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+
+import com.warewms.common.core.domain.base.BaseEntity;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
@@ -15,7 +17,7 @@ import lombok.NoArgsConstructor;
 @TableName(value ="retroactive_now")
 @Data
 @NoArgsConstructor
-public class RetroactiveNow implements Serializable {
+public class RetroactiveNow extends BaseEntity {
     /**
      * 追溯id
      */
@@ -52,101 +54,10 @@ public class RetroactiveNow implements Serializable {
      */
     private String deviceId;
 
-    /**
-     * 创建者
-     */
-    private String createBy;
-
-    /**
-     * 创建时间
-     */
-    private LocalDateTime createTime;
-
-    /**
-     * 更新者
-     */
-    private String updateBy;
-
-    /**
-     * 更新时间
-     */
-    private LocalDateTime updateTime;
-
-    /**
-     * 备注
-     */
-    private String remark;
 
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
 
-    @Override
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        }
-        if (that == null) {
-            return false;
-        }
-        if (getClass() != that.getClass()) {
-            return false;
-        }
-        RetroactiveHistory other = (RetroactiveHistory) that;
-        return (this.getRetroactiveId() == null ? other.getRetroactiveId() == null : this.getRetroactiveId().equals(other.getRetroactiveId()))
-                && (this.getProductionLine() == null ? other.getProductionLine() == null : this.getProductionLine().equals(other.getProductionLine()))
-                && (this.getBatchNo() == null ? other.getBatchNo() == null : this.getBatchNo().equals(other.getBatchNo()))
-                && (this.getLotNo() == null ? other.getLotNo() == null : this.getLotNo().equals(other.getLotNo()))
-                && (this.getWeight() == null ? other.getWeight() == null : this.getWeight().equals(other.getWeight()))
-                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
-                && (this.getDeviceId() == null ? other.getDeviceId() == null : this.getDeviceId().equals(other.getDeviceId()))
-                && (this.getCreateBy() == null ? other.getCreateBy() == null : this.getCreateBy().equals(other.getCreateBy()))
-                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
-                && (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()))
-                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
-                && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()));
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((getRetroactiveId() == null) ? 0 : getRetroactiveId().hashCode());
-        result = prime * result + ((getProductionLine() == null) ? 0 : getProductionLine().hashCode());
-        result = prime * result + ((getBatchNo() == null) ? 0 : getBatchNo().hashCode());
-        result = prime * result + ((getLotNo() == null) ? 0 : getLotNo().hashCode());
-        result = prime * result + ((getWeight() == null) ? 0 : getWeight().hashCode());
-        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
-        result = prime * result + ((getDeviceId() == null) ? 0 : getDeviceId().hashCode());
-        result = prime * result + ((getCreateBy() == null) ? 0 : getCreateBy().hashCode());
-        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
-        result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
-        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
-        result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getClass().getSimpleName());
-        sb.append(" [");
-        sb.append("Hash = ").append(hashCode());
-        sb.append(", retroactiveId=").append(retroactiveId);
-        sb.append(", productionLine=").append(productionLine);
-        sb.append(", batchNo=").append(batchNo);
-        sb.append(", lotNo=").append(lotNo);
-        sb.append(", weight=").append(weight);
-        sb.append(", status=").append(status);
-        sb.append(", deviceId=").append(deviceId);
-        sb.append(", createBy=").append(createBy);
-        sb.append(", createTime=").append(createTime);
-        sb.append(", updateBy=").append(updateBy);
-        sb.append(", updateTime=").append(updateTime);
-        sb.append(", remark=").append(remark);
-        sb.append(", serialVersionUID=").append(serialVersionUID);
-        sb.append("]");
-        return sb.toString();
-    }
 
     /**
      *
@@ -165,4 +76,5 @@ public class RetroactiveNow implements Serializable {
                 .append(String.valueOf(weight).split("\\.")[0]).toString();
     }
 
+
 }

+ 24 - 0
warewms-system/src/main/java/com/warewms/hailiang/enums/DaSanPanPlcEnum.java

@@ -0,0 +1,24 @@
+package com.warewms.hailiang.enums;
+
+public enum DaSanPanPlcEnum {
+    /**
+     * 一号下料读码信号
+     */
+    ISREAD_one("DB200.0.1"),
+    /**
+     * 四号下料读码信号
+     */
+    ISREAD_fourth("DB200.0.2");
+
+
+    private String metadata;
+
+
+    DaSanPanPlcEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 5 - 1
warewms-system/src/main/java/com/warewms/hailiang/enums/DaoJiaoPlcEnum.java

@@ -5,7 +5,11 @@ package com.warewms.hailiang.enums;
  */
 public enum DaoJiaoPlcEnum {
 
-    CHECKFINISH("");
+    CHECKFINISH("Q1.6"),
+
+    READCODE("Q1.7"),
+
+    RETURNOUTCOME("");
 
     private String metadata;
 

+ 9 - 1
warewms-system/src/main/java/com/warewms/hailiang/enums/DeviceNameEnum.java

@@ -6,7 +6,13 @@ package com.warewms.hailiang.enums;
 public enum DeviceNameEnum {
     WEIGHTPLC("ChengZhongPlc"),
 
-    DAOJIAOPLC("DaoJiaoJiPlc");
+    DAOJIAOPLC("DaoJiaoJiPlc"),
+
+    XIMIANPLC("XiMianPlc"),
+
+    ZHAZHIPLC("ZhaZhiPlc"),
+
+    DASANPANPLC("DaSanPanPlc");
 
     private String deviceName;
 
@@ -22,4 +28,6 @@ public enum DeviceNameEnum {
     public void setDeviceName(String deviceName) {
         this.deviceName = deviceName;
     }
+
+
 }

+ 2 - 2
warewms-system/src/main/java/com/warewms/hailiang/enums/InkjetPrintersDirectivesEnum.java

@@ -27,9 +27,9 @@ public enum InkjetPrintersDirectivesEnum {
     CODEE6("E6 00 00 E6"),
 
     /**
-     * 运行发码程序
+     * 设置打印反馈
      */
-    CODE41("41 00 01 01 41"),
+    CODE41("4100010141"),
 
     /**
      * 触发打印

+ 3 - 3
warewms-system/src/main/java/com/warewms/hailiang/enums/WeighPlcEnum.java

@@ -13,17 +13,17 @@ public enum WeighPlcEnum {
     /**
      * 是否可以读取重量
      */
-    IsRead(""),
+    IsRead("DB200.0.0"),
 
     /**
      * 读取重量
      */
-    ReadWeight(""),
+    ReadWeight("DB200.2.0"),
 
     /**
      * 读取重量反馈
      */
-    returnWeight("");
+    returnWeight("DB200.10.0");
 
     private String metadata;
 

+ 20 - 0
warewms-system/src/main/java/com/warewms/hailiang/enums/XiMianPlcEnum.java

@@ -0,0 +1,20 @@
+package com.warewms.hailiang.enums;
+
+public enum XiMianPlcEnum {
+    /**
+     * 读码信号
+     */
+    ISREAD("DB200.0.1");
+
+
+    private String metadata;
+
+
+    XiMianPlcEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 20 - 0
warewms-system/src/main/java/com/warewms/hailiang/enums/ZhaZhiPlcEnum.java

@@ -0,0 +1,20 @@
+package com.warewms.hailiang.enums;
+
+public enum ZhaZhiPlcEnum {
+    /**
+     * 读码信号
+     */
+    ISREAD("DB300.0.1");
+
+
+    private String metadata;
+
+
+    ZhaZhiPlcEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 28 - 14
warewms-system/src/main/java/com/warewms/hailiang/init/TcpServiceRunner.java

@@ -1,7 +1,10 @@
 package com.warewms.hailiang.init;
 
 import cn.hutool.core.util.ClassUtil;
-import com.warewms.hailiang.connect.TCPConnectBase;
+import cn.hutool.core.util.ObjectUtil;
+import com.warewms.common.exception.ServiceException;
+import com.warewms.hailiang.connect.base.TCPConnectBase;
+import com.warewms.hailiang.service.DeviceService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
@@ -9,6 +12,7 @@ import org.springframework.core.annotation.Order;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Set;
@@ -31,7 +35,10 @@ public class TcpServiceRunner implements CommandLineRunner {
     @Autowired
     ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
-    private static HashMap<String,TCPConnectBase> TCPInstanceList = new HashMap<>();
+    @Resource
+    DeviceService deviceService;
+
+    private HashMap<String,TCPConnectBase> TCPInstanceList = new HashMap<>();
 
     @Override
     public void run(String... args) throws Exception {
@@ -40,22 +47,29 @@ public class TcpServiceRunner implements CommandLineRunner {
             Object o = aClass.newInstance();
             if (o instanceof TCPConnectBase) {
                 TCPConnectBase nodeModel = (TCPConnectBase) o;
-                threadPoolTaskExecutor.execute(() -> {
-                    try {
-                        nodeModel.init();
-                        TCPInstanceList.put(nodeModel.getDeviceName(),nodeModel);
-                    } catch (IOException e) {
-                        nodeModel.close();
-                        throw new RuntimeException(e);
-                    } catch (InterruptedException e) {
-                        throw new RuntimeException(e);
-                    }
-                });
+//                threadPoolTaskExecutor.execute(() -> {
+//                    try {
+//                        nodeModel.init();
+//                        TCPInstanceList.put(nodeModel.getDeviceName(),nodeModel);
+//                    } catch (IOException e) {
+//                        nodeModel.close();
+//                        throw new RuntimeException(e);
+//                    } catch (InterruptedException e) {
+//                        throw new RuntimeException(e);
+//                    }
+//                });
             }
         }
     }
 
-    public static TCPConnectBase getTCPInstanceList(String key){
+    public TCPConnectBase getTCPInstanceList(String key){
+        TCPConnectBase tcpConnectBase = TCPInstanceList.get(key);
+        if(ObjectUtil.isNull(tcpConnectBase)){
+            throw new ServiceException("设备未连接");
+        }
+        if (!deviceService.IsConnect(key)){
+            throw new ServiceException("设备连接中断");
+        }
         return TCPInstanceList.get(key);
     }
 }

+ 47 - 10
warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java

@@ -1,8 +1,7 @@
 package com.warewms.hailiang.job;
 
-import com.warewms.hailiang.enums.DaoJiaoPlcEnum;
-import com.warewms.hailiang.enums.DeviceNameEnum;
-import com.warewms.hailiang.enums.WeighPlcEnum;
+import com.warewms.common.core.redis.RedisCache;
+import com.warewms.hailiang.enums.*;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import com.warewms.hailiang.init.TcpServiceRunner;
 import com.warewms.hailiang.service.ProcessRealizationService;
@@ -26,6 +25,16 @@ public class TraceJob {
     @Autowired
     ProcessRealizationService processRealizationService;
 
+    @Autowired
+    private RedisCache redisCache;
+
+
+    /**
+     * 测试
+     */
+    public void test() throws InterruptedException {
+
+    }
 
     /**
      * 获取称重信号
@@ -41,13 +50,25 @@ public class TraceJob {
     }
 
     /**
-     * 获取倒角完成信号
+     * 获取喷码信号
      */
     public void getTheChamferCompletionSignal() {
         boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.CHECKFINISH.getMetadata());
-        log.info("倒角完成信号:{}", b);
+        log.info("喷码信号:{}", b);
+        if (b) {
+            processRealizationService.DaoJiaoCodingCodeProcess();
+        }
+    }
+
+    /**
+     * 获取倒角机读码信号
+     */
+
+    public void obtainTheChamferingMachineCodeReadingSignal (){
+        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.READCODE.getMetadata());
+        log.info("倒角机读码信号,{}",b);
         if (b) {
-            processRealizationService.DaoJiaoProcess();
+            processRealizationService.CodeReadingProcess("CodeReader3");
         }
     }
 
@@ -55,21 +76,33 @@ public class TraceJob {
      * 获取铣面读码信号
      */
     public void obtainTheMillingFaceReadingSignal() {
-
+        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.XIMIANPLC.getDeviceName()).readBoolean(XiMianPlcEnum.ISREAD.getMetadata());
+        log.info("铣面读码信号:{}", b);
+        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader5");
+        }
     }
 
     /**
      * 获取轧制读码信号
      */
     public void getARollingReadingSignal() {
-
+        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.ZHAZHIPLC.getDeviceName()).readBoolean(ZhaZhiPlcEnum.ISREAD.getMetadata());
+        log.info("轧制读码信号:{}", b);
+        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader6");
+        }
     }
 
     /**
      * 获取行车1读码信号
      */
     public void getTheDriving1CodeReadingSignal() {
-
+        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_one.getMetadata());
+        log.info("大散盘1号行车读码信号:{}", b);
+        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader7");
+        }
     }
 
     /**
@@ -90,7 +123,11 @@ public class TraceJob {
      * 获取行车4读码信号
      */
     public void getTheDriving4CodeReadingSignal() {
-
+        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_fourth.getMetadata());
+        log.info("大散盘4号行车读码信号:{}", b);
+        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader12");
+        }
     }
 
     /**

+ 8 - 2
warewms-system/src/main/java/com/warewms/hailiang/service/ProcessRealizationService.java

@@ -11,7 +11,13 @@ public interface ProcessRealizationService {
     void weightProcess() throws InterruptedException;
 
     /**
-     * 倒角工艺完成喷码、读码流程实现
+     * 倒角工艺中喷码流程实现
      */
-    void DaoJiaoProcess();
+    void DaoJiaoCodingCodeProcess();
+
+    /**
+     * 读码触发实现
+     */
+    void CodeReadingProcess(String codeReadName);
+
 }

+ 48 - 19
warewms-system/src/main/java/com/warewms/hailiang/service/impl/ProcessRealizationServiceImpl.java

@@ -1,8 +1,12 @@
 package com.warewms.hailiang.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.warewms.common.core.redis.RedisCache;
 import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.MES.MesService;
+import com.warewms.hailiang.config.CodeReadProperties;
+import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.enums.DeviceNameEnum;
 import com.warewms.hailiang.enums.WeighPlcEnum;
@@ -10,9 +14,17 @@ import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import com.warewms.hailiang.init.TcpServiceRunner;
 import com.warewms.hailiang.service.ProcessRealizationService;
 import com.warewms.hailiang.service.RetroactiveNowService;
+import com.warewms.hailiang.util.InkjetPrintersSetUpTools;
+import com.warewms.hailiang.util.ParseMsgTools;
+import io.netty.buffer.Unpooled;
+import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.concurrent.TimeUnit;
+
 /**
  * 工艺流程实现
  */
@@ -31,44 +43,61 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
 
     @Autowired
     RetroactiveNowService retroactiveNowService;
+
+    @Autowired
+    private RedisCache redisCache;
+
     @Override
+    @Transactional
     public void weightProcess() throws InterruptedException {
         //读取称重信息
         double weight = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).readFloat64(WeighPlcEnum.ReadWeight.getMetadata());
-        if(weight==0){
+        if (weight == 0) {
             log.error("重量信息有误,为0");
-        }else {
+        } else {
             //调用MES系统拿到批次号
             String BatchNo = mesService.getBatchNoByWeight(weight, "Z1");
-            if (StringUtils.isNotEmpty(BatchNo)){
+            if (StringUtils.isNotEmpty(BatchNo)) {
                 //数据库记录批次号
-                RetroactiveNow z1 = new RetroactiveNow(weight,BatchNo,"Z1");
-                z1.setCreateBy("system");
-                z1.setStatus("1");
-                int insert = retroactiveNowService.insertData(z1);
-                if (insert==1){
-                    log.info("追溯记录生成成功,BatchNo:{}",BatchNo);
-                    //反馈plc成功拿到重量生成追溯记录
-                    plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).writeBoolean(WeighPlcEnum.returnWeight.getMetadata(),true);
-                    Thread.sleep(5000);
-                    plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).writeBoolean(WeighPlcEnum.IsRead.getMetadata(),false);
-                }else {
-                    log.info("追溯记录生成失败,BatchNo:{}",BatchNo);
-                }
+                RetroactiveNow retroactiveNow = new RetroactiveNow(weight, BatchNo, "Z1");
+                retroactiveNow.setCreateBy("system");
+                retroactiveNow.setStatus("1");
+                retroactiveNowService.insertData(retroactiveNow);
+                //反馈plc成功拿到重量生成追溯记录
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).writeBoolean(WeighPlcEnum.returnWeight.getMetadata(), true);
+                Thread.sleep(5000);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).writeBoolean(WeighPlcEnum.returnWeight.getMetadata(), false);
+                //更新喷码机条码内容
+                String updateCode = InkjetPrintersSetUpTools.updateCode(retroactiveNow.getBatchNo());
+                tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(ParseMsgTools.hexString2Bytes(updateCode));
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJia_DMQ-1-27.3", "InkjetPrinters", "喷码内容修改完成,内容为:"+retroactiveNow.getBatchNo(), "1"));
+                log.info("追溯记录生成成功,BatchNo:{}", BatchNo);
             }
         }
 
     }
 
     @Override
-    public void DaoJiaoProcess() {
+    public void DaoJiaoCodingCodeProcess() {
         //获取数据库中的批次号
         RetroactiveNow retroactiveNow = new RetroactiveNow();
         retroactiveNow.setStatus("1");
-        retroactiveNow =  retroactiveNowService.selectTheOneByParameter(retroactiveNow);
-        if (ObjectUtil.isNotNull(retroactiveNow)){
+        retroactiveNow = retroactiveNowService.selectTheOneByParameter(retroactiveNow);
+        if (ObjectUtil.isNotNull(retroactiveNow)) {
             //更新喷码机条码内容
+            String updateCode = InkjetPrintersSetUpTools.updateCode(retroactiveNow.getBatchNo());
+            tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(ParseMsgTools.hexString2Bytes(updateCode));
 
         }
     }
+
+    @Override
+    public void CodeReadingProcess(String codeReadName) {
+        if (redisCache.hasKey(codeReadName)){
+            log.info("读码器{}正在读码!",codeReadName);
+            return;
+        }
+        tcpServiceRunner.getTCPInstanceList(codeReadName).getChannel().writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+        redisCache.expire(codeReadName,30, TimeUnit.SECONDS);
+    }
 }

+ 67 - 0
warewms-system/src/main/java/com/warewms/hailiang/util/InkjetPrintersSetUpTools.java

@@ -0,0 +1,67 @@
+package com.warewms.hailiang.util;
+
+import com.warewms.hailiang.enums.InkjetPrintersDirectivesEnum;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.util.CharsetUtil;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+public class InkjetPrintersSetUpTools {
+
+    private boolean isFirst = true;
+
+    /**
+     * 生成修改条码内容的命令
+     */
+    public static String updateCode(String code){
+        StringBuffer stringBuffer = new StringBuffer();
+        stringBuffer.append("E800");
+        stringBuffer.append("0").append(Integer.toHexString(code.length()+3));
+        stringBuffer.append("01000").append(Integer.toHexString((code.length())));
+        for (char c : code.toCharArray()) {
+            stringBuffer.append(Integer.toHexString(c));
+        }
+        return addAChecksum(stringBuffer.toString());
+    }
+
+    /**
+     *  添加校验和
+     * @param code
+     * @return
+     */
+   public static String addAChecksum(String code){
+       int l = code.length() / 2;
+       String[] s2 =new String[l];
+       for (int i = 0; i < l; i++) {
+           s2[i] = code.substring(i * 2, i * 2 + 2);
+       }
+       int i  =Integer.parseInt(s2[0],16) ^ Integer.parseInt(s2[1],16) ;
+       for (int i1 = 1; i1 < s2.length-1; i1++) {
+           i = i ^ Integer.parseInt(s2[i1+1],16);
+       }
+       return code+Integer.toHexString(i);
+   }
+
+
+
+    public static void main(String[] args) {
+        String a ="237191209000";
+//        StringBuffer stringBuffer = new StringBuffer();
+//        stringBuffer.append("E8 ");
+//        int length = a.length();
+//        System.out.println(Integer.toHexString(length));
+//        System.out.println(Integer.toHexString(length+3));
+//        int length =  ;
+//        System.out.println(ParseMsgTools.StringTohexString("237191209000"));
+//        String b ="E8 00 0F 01 00 0C 32 33 37 31 39 31 32 30 39 30 30 30";
+//        System.out.println(InkjetPrintersSetUpTools.addAChecksum(b));
+//        String s = "E8000f01000c323337313931323039303030EE";
+        System.out.println(updateCode(a));
+//        ByteBuf byteBuf = Unpooled.copiedBuffer(s, CharsetUtil.UTF_16);
+//        System.out.println(Arrays.toString(byteBuf.array()));
+//        System.out.println(Arrays.toString(ParseMsgTools.hexString2Bytes(s)));
+    }
+}

+ 3 - 1
warewms-system/src/main/java/com/warewms/hailiang/util/ParseMsgTools.java

@@ -1,6 +1,7 @@
 package com.warewms.hailiang.util;
 
 import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
 
 /**
  * Created with IntelliJ IDEA.
@@ -41,6 +42,7 @@ public class ParseMsgTools {
         }
         return sb.toString();
     }
+
     public static void main(String[] args) throws UnsupportedEncodingException {
 //        String str = "23";
 //        StringBuffer sb = new StringBuffer();
@@ -65,7 +67,7 @@ public class ParseMsgTools {
 //        }
 //        System.out.println(Integer.toHexString(i));
 
-//        System.out.println(Integer.parseInt("23",16));
+        System.out.println(Integer.parseInt("30",16));
 //        System.out.println(Arrays.toString(hexString2Bytes("8000")));
 
 //        System.out.println(Integer.parseInt("E8",16));