2 Incheckningar 1a3826bf7e ... a81b6a2f48

Upphovsman SHA1 Meddelande Datum
  zhifei a81b6a2f48 优化PDA补码及大散盘下料数据的生成 11 månader sedan
  zhifei 024f1c0cee 修改补码接口,修复工艺状态更新问题 1 år sedan
44 ändrade filer med 1215 tillägg och 246 borttagningar
  1. 6 2
      warewms-admin/src/main/resources/application.yml
  2. 8 8
      warewms-admin/src/main/resources/logback.xml
  3. 4 1
      warewms-common/src/main/java/com/warewms/common/constant/CacheConstants.java
  4. 3 3
      warewms-framework/src/main/java/com/warewms/framework/config/CreateAndUpdateMetaObjectHandler.java
  5. 4 3
      warewms-quartz/src/main/java/com/warewms/quartz/util/AbstractQuartzJob.java
  6. 2 0
      warewms-system/pom.xml
  7. 9 1
      warewms-system/src/main/java/com/warewms/hailiang/MES/MesService.java
  8. 126 20
      warewms-system/src/main/java/com/warewms/hailiang/MES/impl/MesServiceImpl.java
  9. 5 0
      warewms-system/src/main/java/com/warewms/hailiang/config/CodeReadProperties.java
  10. 2 2
      warewms-system/src/main/java/com/warewms/hailiang/config/DeviceMessageSocket.java
  11. 75 4
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader12Connect.java
  12. 52 4
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java
  13. 63 12
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java
  14. 60 7
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader3Connect.java
  15. 66 6
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader5Connect.java
  16. 59 3
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader6Connect.java
  17. 27 18
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader7Connect.java
  18. 84 8
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader8Connect.java
  19. 31 3
      warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader9Connect.java
  20. 7 3
      warewms-system/src/main/java/com/warewms/hailiang/contoller/DeviceController.java
  21. 16 1
      warewms-system/src/main/java/com/warewms/hailiang/contoller/DeviceLogController.java
  22. 9 9
      warewms-system/src/main/java/com/warewms/hailiang/contoller/RetroactiveHistoryController.java
  23. 41 4
      warewms-system/src/main/java/com/warewms/hailiang/contoller/RetroactiveNowController.java
  24. 50 25
      warewms-system/src/main/java/com/warewms/hailiang/contoller/TestContoller.java
  25. 9 0
      warewms-system/src/main/java/com/warewms/hailiang/domain/DeviceLog.java
  26. 38 4
      warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveHistory.java
  27. 34 1
      warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveNow.java
  28. 12 3
      warewms-system/src/main/java/com/warewms/hailiang/enums/DaSanPanPlcEnum.java
  29. 4 4
      warewms-system/src/main/java/com/warewms/hailiang/enums/InkjetPrintersDirectivesEnum.java
  30. 11 11
      warewms-system/src/main/java/com/warewms/hailiang/init/TcpServiceRunner.java
  31. 27 22
      warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java
  32. 3 0
      warewms-system/src/main/java/com/warewms/hailiang/mapper/RetroactiveHistoryMapper.java
  33. 1 0
      warewms-system/src/main/java/com/warewms/hailiang/service/DeviceLogService.java
  34. 1 1
      warewms-system/src/main/java/com/warewms/hailiang/service/ProcessRealizationService.java
  35. 5 1
      warewms-system/src/main/java/com/warewms/hailiang/service/RetroactiveHistoryService.java
  36. 7 0
      warewms-system/src/main/java/com/warewms/hailiang/service/RetroactiveNowService.java
  37. 23 3
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceLogServiceImpl.java
  38. 5 5
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceServiceImpl.java
  39. 28 10
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/ProcessRealizationServiceImpl.java
  40. 27 4
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/RetroactiveHistoryServiceImpl.java
  41. 157 27
      warewms-system/src/main/java/com/warewms/hailiang/service/impl/RetroactiveNowServiceImpl.java
  42. 4 2
      warewms-system/src/main/java/com/warewms/hailiang/util/ParseMsgTools.java
  43. 2 1
      warewms-system/src/main/java/com/warewms/system/controller/monitor/CacheController.java
  44. 8 0
      warewms-system/src/main/resources/mapper/hailiang/RetroactiveHistoryMapper.xml

+ 6 - 2
warewms-admin/src/main/resources/application.yml

@@ -5,11 +5,15 @@ spring:
 
 # MES对接接口
 MES:
-  address: http://172.20.2.2:9090
+  address: http://172.20.2.4:9090
   #获取批次号
   getBatchNoUrl: /api/SprayCode/SprayBatchNo
   #获取批次号回调
-  getBatchNoResultUrl: /api/SprayCode/SprayBatchNoResult
+  getBatchNoResultUrl: /api/SprayCode/updateSprayStatus
   #工艺读码反馈
   processFeedbackUrl: /api/SprayCode/SprayMillingSurface
+  #大散盘获取批次号
+  sanPanGetBatchNoUrl: /api/WareHouse/UpdateMaterialStockNo
+  #退火上料
+  tuiHuoShangLiaoUrl: /api/Mes/SyncReceiveBlanking
 

+ 8 - 8
warewms-admin/src/main/resources/logback.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration>
     <!-- 日志存放路径 -->
-	<property name="log.path" value="/home/ruoyi/logs" />
+	<property name="log.path" value="../logs" />
     <!-- 日志输出格式 -->
 	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
 
@@ -11,7 +11,7 @@
 			<pattern>${log.pattern}</pattern>
 		</encoder>
 	</appender>
-	
+
 	<!-- 系统日志输出 -->
 	<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
 	    <file>${log.path}/sys-info.log</file>
@@ -34,7 +34,7 @@
             <onMismatch>DENY</onMismatch>
         </filter>
 	</appender>
-	
+
 	<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
 	    <file>${log.path}/sys-error.log</file>
         <!-- 循环政策:基于时间创建日志文件 -->
@@ -56,7 +56,7 @@
             <onMismatch>DENY</onMismatch>
         </filter>
     </appender>
-	
+
 	<!-- 用户访问日志输出  -->
     <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/sys-user.log</file>
@@ -70,7 +70,7 @@
             <pattern>${log.pattern}</pattern>
         </encoder>
     </appender>
-	
+
 	<!-- 系统模块日志级别控制  -->
 	<logger name="com.warewms" level="info" />
 	<!-- Spring日志级别控制  -->
@@ -79,15 +79,15 @@
 	<root level="info">
 		<appender-ref ref="console" />
 	</root>
-	
+
 	<!--系统操作日志-->
     <root level="info">
         <appender-ref ref="file_info" />
         <appender-ref ref="file_error" />
     </root>
-	
+
 	<!--系统用户操作日志-->
     <logger name="sys-user" level="info">
         <appender-ref ref="sys-user"/>
     </logger>
-</configuration> 
+</configuration>

+ 4 - 1
warewms-common/src/main/java/com/warewms/common/constant/CacheConstants.java

@@ -2,7 +2,7 @@ package com.warewms.common.constant;
 
 /**
  * 缓存的key 常量
- * 
+ *
  * @author ruoyi
  */
 public class CacheConstants
@@ -41,4 +41,7 @@ public class CacheConstants
      * 登录账户密码错误次数 redis key
      */
     public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
+
+    public static final String BATCH_NO ="InkjetPrinters" ;
+
 }

+ 3 - 3
warewms-framework/src/main/java/com/warewms/framework/config/CreateAndUpdateMetaObjectHandler.java

@@ -46,9 +46,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
         try {
             if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
                 BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
-                Date current = new Date();
-                // 更新时间填充(不管为不为空)
-                baseEntity.setUpdateTime(current);
+                if(ObjectUtil.isNull(baseEntity.getUpdateTime())){
+                    baseEntity.setUpdateTime(new Date());
+                }
                 // 当前已登录 更新人填充(为空进行填充)
                 if (StringUtils.isBlank(baseEntity.getUpdateBy())) {
                     String username = SecurityUtils.getUsername();

+ 4 - 3
warewms-quartz/src/main/java/com/warewms/quartz/util/AbstractQuartzJob.java

@@ -81,20 +81,21 @@ public abstract class AbstractQuartzJob implements Job
         sysJobLog.setStopTime(new Date());
         long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
         sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
+        sysJobLog.setCreateBy("admin");
+        sysJobLog.setUpdateBy("admin");
         if (e != null)
         {
             sysJobLog.setStatus(Constants.FAIL);
             String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
             sysJobLog.setExceptionInfo(errorMsg);
+            SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
+
         }
         else
         {
             sysJobLog.setStatus(Constants.SUCCESS);
         }
-        sysJobLog.setCreateBy("admin");
-        sysJobLog.setUpdateBy("admin");
         // 写入数据库当中
-        SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
     }
 
     /**

+ 2 - 0
warewms-system/pom.xml

@@ -36,6 +36,8 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
         </dependency>
+
+        
     </dependencies>
 
 </project>

+ 9 - 1
warewms-system/src/main/java/com/warewms/hailiang/MES/MesService.java

@@ -27,11 +27,19 @@ public interface MesService {
      * @param batchNo
      * @return
      */
-    public JSONObject getBatchNoResult(String batchNo,boolean result);
+    public JSONObject getBatchNoResult(String batchNo,int result);
 
 
     /**
      * 工艺反馈接口
      */
     public JSONObject processFeedback(String batchNo,String type);
+
+    /**
+     *  绑定批次号
+     * @param v 大散盘下料点
+     */
+    String bindLotNo(String deviceId,String lotNo);
+
+
 }

+ 126 - 20
warewms-system/src/main/java/com/warewms/hailiang/MES/impl/MesServiceImpl.java

@@ -1,18 +1,33 @@
 package com.warewms.hailiang.MES.impl;
 
+import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.github.rholder.retry.*;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 import com.warewms.common.annotation.Log;
 import com.warewms.common.exception.ServiceException;
 import com.warewms.hailiang.MES.MesService;
+import com.warewms.hailiang.config.DeviceMessageSocket;
+import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.enums.DaSanPanPlcEnum;
+import com.warewms.hailiang.enums.DeviceNameEnum;
+import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import io.swagger.util.Json;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Nullable;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
 /**
  * Created with IntelliJ IDEA.
  *
@@ -37,37 +52,58 @@ public class MesServiceImpl implements MesService {
     @Value("${MES.processFeedbackUrl}")
     private String processFeedbackUrl;
 
+    @Value("${MES.sanPanGetBatchNoUrl}")
+    private String sanPanGetBatchNoUrl;
+
+    @Autowired
+    private DeviceMessageSocket deviceMessageSocket;
+
+    @Autowired
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
+    @Autowired
+    private PlcConnectServiceRunner plcConnectServiceRunner;
 
     @Override
-    public String getBatchNoByWeight(Double weight,String prodLine) {
+    public String getBatchNoByWeight(Double weight, String prodLine) {
         JSONObject entries = new JSONObject();
-        entries.set("Weight",weight);
-        entries.set("prodLine",prodLine);
-        log.info("调用MES系统拿铜管批次号,body:{}",entries);
+        entries.set("Weight", weight);
+        entries.set("prodLine", prodLine);
+        log.info("调用MES系统拿铜管批次号,body:{}", entries);
         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;
+            body = HttpRequest.post(MESAddress + getBatchNoUrl).body(entries.toString()).execute().body();
+        } catch (Exception e) {
+            log.error("调用MES系统拿铜管批次号失败,msg:{}", e.getMessage());
+            return invokeAlarms("称重辊道PLC", "获取MES铜管批次号失败!");
         }
         JSONObject jsonObject = JSONUtil.parseObj(body);
-        if ("false".equals(jsonObject.get("ret"))){
-            log.error("调用MES系统拿铜管批次号失败,msg:{}",jsonObject.get("message"));
-            return null;
+        if ("false".equals(jsonObject.get("ret"))) {
+            log.error("调用MES系统拿铜管批次号失败,msg:{}", jsonObject.get("message"));
+            return invokeAlarms("称重辊道PLC", "获取MES铜管批次号失败!");
         }
         return JSONUtil.parseObj(body).get("BatchNo").toString();
     }
 
+    @Nullable
+    private String invokeAlarms(String deviceName, String content) {
+        DeviceLog deviceLog = new DeviceLog("", deviceName, content, "2");
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type", "notify");
+        jsonObject.set("content", JSONUtil.parse(deviceLog));
+        deviceMessageSocket.sendAllMessage(jsonObject.toString());
+        return null;
+    }
+
     @Override
-    public JSONObject getBatchNoResult(String batchNo,boolean result) {
+    public JSONObject getBatchNoResult(String batchNo, int result) {
         JSONObject entries = new JSONObject();
-        entries.set("BatchNo",batchNo);
-        entries.set("Result",result);
+        entries.set("BatchNo", batchNo);
+        entries.set("type", result);
         String body = HttpRequest.post(MESAddress + getBatchNoResultURl).body(entries.toString()).execute().body();
         JSONObject jsonObject = JSONUtil.parseObj(body);
-        if ("false".equals(jsonObject.get("ret"))){
-            log.error("喷码成功反馈MES失败,msg:{}",jsonObject.get("message"));
+        if ("false".equals(jsonObject.get("ret"))) {
+            retryTofeedback(MESAddress + processFeedbackUrl, entries, "BatchNoResult");
             return null;
         }
 
@@ -77,15 +113,85 @@ public class MesServiceImpl implements MesService {
     @Override
     public JSONObject processFeedback(String batchNo, String type) {
         JSONObject entries = new JSONObject();
-        entries.set("BatchNo",batchNo);
-        entries.set("Type",type);
+        entries.set("BatchNo", batchNo);
+        entries.set("Type", type);
+        entries.set("d", "Z1");
         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"));
+        if ("0".equals(jsonObject.get("RES_FLAG"))) {
+            retryTofeedback(MESAddress + processFeedbackUrl, entries, "process");
             return null;
         }
 
         return jsonObject;
     }
+
+
+    @Override
+    public String bindLotNo(String deviceId,String lotNot) {
+        log.info("散盘产出设备:{}",deviceId);
+        JSONObject entries = new JSONObject();
+        entries.set("StockNo", lotNot);
+        entries.set("UnitNo",deviceId );
+        entries.set("LineNo", "Z1");
+        String body = HttpRequest.post( MESAddress+ sanPanGetBatchNoUrl).body(entries.toString()).execute().body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        if ("0".equals(jsonObject.get("RES_FLAG"))) {
+            retryTofeedback(MESAddress + sanPanGetBatchNoUrl, entries, "sanpan");
+            return null;
+        }
+        log.info(body);
+        return JSONUtil.parseObj(jsonObject.get("Result")).get("mat_no").toString();
+
+    }
+
+    /**
+     *  MES反馈重试
+     * @param URl
+     * @param body
+     * @param type
+     */
+    private void retryTofeedback(String URl, JSONObject body, String type) {
+        threadPoolTaskExecutor.execute(() -> {
+            Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
+                    .retryIfResult(Boolean.FALSE::equals)
+                    .retryIfExceptionOfType(Exception.class)
+                    .withStopStrategy(StopStrategies.stopAfterAttempt(3))
+                    .withWaitStrategy(WaitStrategies.fixedWait(5, TimeUnit.SECONDS))
+                    .build();
+            try {
+                retryer.call(() -> {
+                    log.info("MES对接进行重试,url:{},body{}", URl, body);
+                    String data = HttpRequest.post(URl).body(body.toString()).execute().body();
+                    JSONObject jsonObject = JSONUtil.parseObj(data);
+                    if ("process".equals(type)) {
+                        if ("0".equals(jsonObject.get("RES_FLAG"))) {
+                            log.error("工序读码成功反馈失败,msg:{}", jsonObject.get("message"));
+                            invokeAlarms("1".equals(type) ? "铣面工序" : "轧制工序", "工序读码成功反馈MES失败!");
+                            return false;
+                        }
+                    }
+                    if ("BatchNoResult".equals(type)){
+                        if ("false".equals(jsonObject.get("ret"))) {
+                            log.error("喷码成功反馈MES失败,msg:{}", jsonObject.get("message"));
+                            invokeAlarms("喷码器", "喷码成功反馈MES失败!");
+                            return false;
+                        }
+                    }
+                    if ("sanpan".equals(type)){
+                        if ("false".equals(jsonObject.get("ret"))) {
+                            log.error("散盘托盘号反馈MES失败,msg:{}", jsonObject.get("message"));
+                            invokeAlarms("大散盘", "获取批次号失败!");
+                            return false;
+                        }
+                    }
+                    return true;
+                });
+            } catch (RetryException | ExecutionException e) {
+                e.printStackTrace();
+            }
+        });
+
+
+    }
 }

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

@@ -11,4 +11,9 @@ public class CodeReadProperties {
      * 失败返回
      */
     public static String failureReturnInstruction ="NG";
+
+    /**
+     * 心跳
+     */
+    public static String heartbeat ="HB";
 }

+ 2 - 2
warewms-system/src/main/java/com/warewms/hailiang/config/DeviceMessageSocket.java

@@ -62,7 +62,7 @@ public class DeviceMessageSocket {
      */
     @OnMessage
     public void onMessage(String message) {
-        log.info("【websocket消息】收到客户端消息:"+message);
+//        log.info("【websocket消息】收到客户端消息:"+message);
         JSONObject jsonObject = new JSONObject();
         jsonObject.set("type","heartbeat");
         jsonObject.set("content","ok");
@@ -99,7 +99,7 @@ public class DeviceMessageSocket {
         Session session = sessionPool.get(userName);
         if (session != null&&session.isOpen()) {
             try {
-                log.info("【websocket消息】 单点消息:"+message);
+//                log.info("【websocket消息】 单点消息:"+message);
                 session.getAsyncRemote().sendText(message);
             } catch (Exception e) {
                 e.printStackTrace();

+ 75 - 4
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader12Connect.java

@@ -2,24 +2,28 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+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.DaSanPanPlcEnum;
+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.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.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -50,10 +54,21 @@ public class CodeReader12Connect implements TCPConnectBase {
 
     private ChannelPipeline pipeline;
 
+    private MesService mesService;
+
     private RetroactiveNowService retroactiveNowService;
 
+    private PlcConnectServiceRunner plcConnectServiceRunner;
+
+    private ScheduledFuture<?> scheduledFuture =null;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
     {
+        mesService = SpringUtil.getBean(MesService.class);
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+        plcConnectServiceRunner = SpringUtil.getBean(PlcConnectServiceRunner.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
     }
     @Override
     public void init() throws InterruptedException {
@@ -68,11 +83,13 @@ public class CodeReader12Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
                                         log.error("设备:{}连接已断开!",deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
                                     @Override
@@ -88,6 +105,7 @@ public class CodeReader12Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -120,6 +138,7 @@ public class CodeReader12Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
                             log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
+                            ConnectsTheHeartbeat();
                         }else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
                         }
@@ -133,6 +152,23 @@ public class CodeReader12Connect implements TCPConnectBase {
         }
     }
 
+    /**
+     * 连接心跳
+     *
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
     @Override
     public void close() {
         group.shutdownGracefully();
@@ -149,19 +185,54 @@ public class CodeReader12Connect implements TCPConnectBase {
         return pipeline;
     }
 
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "未识别到码", "2"));
+//
+//                return;
+//            }
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                a++;
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
+
     @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"));
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_fourth.getMetadata(), (byte) 2);
+
+                Thread.sleep(10000L);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_fourth.getMetadata(), (byte) 0);
+
             } else {
+                float v = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readFloat32(DaSanPanPlcEnum.TASK_ADD_2.getMetadata());
+                String deviceId = v == 10 ? "Z1SZ10" : "Z1SP0" + v;
+                String batchNot = mesService.bindLotNo(deviceId, message);
+
                 //读取到批次号保存到数据库中
                 RetroactiveNow retroactiveNow = new RetroactiveNow();
                 retroactiveNow.setLotNo(message);
                 retroactiveNow.setStatus("5");
                 retroactiveNow.setDeviceId("Z1_DaSanPan_DMQ-4-27.12");
-                retroactiveNowService.updateData(retroactiveNow);
+                retroactiveNow.setBatchNo(batchNot);
+                retroactiveNow.setSanPanDevice(deviceId);
+                retroactiveNowService.DataTwins(retroactiveNow);
+                log.info("二号车号车下料点位为:{}",v);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_fourth.getMetadata(), (byte) 0);
                 //添加设备日志
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "识别到码:" + message, "1"));
             }

+ 52 - 4
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java

@@ -10,16 +10,16 @@ import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -52,8 +52,13 @@ public class CodeReader13Connect implements TCPConnectBase {
 
     private RetroactiveNowService retroactiveNowService;
 
+    private ScheduledFuture<?> scheduledFuture =null;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
     {
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
     }
 
     @Override
@@ -69,11 +74,13 @@ public class CodeReader13Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
                                         log.error("设备:{}连接已断开!",deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
                                     @Override
@@ -89,6 +96,7 @@ public class CodeReader13Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -121,6 +129,7 @@ public class CodeReader13Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
                             log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
+                            ConnectsTheHeartbeat();
                         }else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
                         }
@@ -134,6 +143,23 @@ public class CodeReader13Connect implements TCPConnectBase {
         }
     }
 
+    /**
+     * 连接心跳
+     *
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
     @Override
     public void close() {
         group.shutdownGracefully();
@@ -150,6 +176,7 @@ public class CodeReader13Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
     @Override
     public void processMessages(String message) {
         try {
@@ -157,7 +184,7 @@ public class CodeReader13Connect implements TCPConnectBase {
             if (CodeReadProperties.failureReturnInstruction.equals(message)) {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "未识别到码", "2"));
             } else {
-                //读取到批次号保存到数据库中
+//                读取到批次号保存到数据库中
                 RetroactiveNow retroactiveNow = new RetroactiveNow();
                 retroactiveNow.setLotNo(message);
                 retroactiveNow.setStatus("6");
@@ -171,4 +198,25 @@ public class CodeReader13Connect implements TCPConnectBase {
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                a++;
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
 }

+ 63 - 12
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java

@@ -10,16 +10,16 @@ import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -38,7 +38,7 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     private final int PORT = 51236;
 
-    private final String deviceName ="CodeReader14";
+    private final String deviceName = "CodeReader14";
 
     private boolean enable = true;
 
@@ -52,9 +52,15 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     private RetroactiveNowService retroactiveNowService;
 
+    private ScheduledFuture<?> scheduledFuture = null;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
     {
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
     }
+
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -68,13 +74,16 @@ public class CodeReader14Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
-                                pipeline.addLast(new ChannelInboundHandlerAdapter(){
+                                pipeline.addLast(new IdleStateHandler(1, 0, 0, TimeUnit.SECONDS));
+                                pipeline.addLast(new ChannelInboundHandlerAdapter() {
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
-                                        log.error("设备:{}连接已断开!",deviceName);
+                                        log.error("设备:{}连接已断开!", deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
+
                                     @Override
                                     public void channelRead(ChannelHandlerContext ctx, Object msg) {
                                         ByteBuf byteBuf = (ByteBuf) msg;
@@ -88,6 +97,7 @@ public class CodeReader14Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -111,17 +121,19 @@ public class CodeReader14Connect 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);
+                            ConnectsTheHeartbeat();
+                        } else {
+                            log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         }
                     });
                     Thread.sleep(3000);
@@ -133,6 +145,22 @@ public class CodeReader14Connect implements TCPConnectBase {
         }
     }
 
+    /**
+     * 连接心跳
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
     @Override
     public void close() {
         group.shutdownGracefully();
@@ -149,6 +177,7 @@ public class CodeReader14Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
     @Override
     public void processMessages(String message) {
         try {
@@ -156,7 +185,7 @@ public class CodeReader14Connect implements TCPConnectBase {
             if (CodeReadProperties.failureReturnInstruction.equals(message)) {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "未识别到码", "2"));
             } else {
-                //读取到批次号保存到数据库中
+//                读取到批次号保存到数据库中
                 RetroactiveNow retroactiveNow = new RetroactiveNow();
                 retroactiveNow.setLotNo(message);
                 retroactiveNow.setStatus("7");
@@ -165,9 +194,31 @@ public class CodeReader14Connect implements TCPConnectBase {
                 //添加设备日志
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "识别到码:" + message, "1"));
             }
+            Thread.sleep(500);
         }catch (Exception e){
             log.error("退货下料读码任务执行异常,msg:{}",e.getMessage());
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                a++;
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
 }

+ 60 - 7
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader3Connect.java

@@ -15,16 +15,16 @@ import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -60,12 +60,17 @@ public class CodeReader3Connect implements TCPConnectBase {
 
     private RetroactiveNowService retroactiveNowService;
 
-    PlcConnectServiceRunner plcConnectServiceRunner;
+    private PlcConnectServiceRunner plcConnectServiceRunner;
 
+    private ScheduledFuture<?> scheduledFuture =null;
+
+    private ScheduledExecutorService scheduledExecutorService;
     {
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
         mesService = SpringUtil.getBean(MesService.class);
         plcConnectServiceRunner = SpringUtil.getBean(PlcConnectServiceRunner.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
+
     }
 
     @Override
@@ -81,11 +86,13 @@ public class CodeReader3Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter() {
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
                                         log.error("设备:{}连接已断开!", deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
 
@@ -102,6 +109,7 @@ public class CodeReader3Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -135,6 +143,7 @@ public class CodeReader3Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                             log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                            ConnectsTheHeartbeat();
                         } else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         }
@@ -163,6 +172,47 @@ public class CodeReader3Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
+    /**
+     * 连接心跳
+     *
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
+//    private int a = 1;
+
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if( a <=300){
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//                a++;
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            log.error("倒角读码任务执行异常,msg:{}", e.getMessage());
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "读码任务出错,msg:" + StringUtils.substring(e.getMessage(), 0, 2000), "2"));
+//        }
+//    }
+
+
     @Override
     public void processMessages(String message) {
         try {
@@ -180,10 +230,13 @@ public class CodeReader3Connect implements TCPConnectBase {
             retroactiveNow.setDeviceId("Z1_DaoJiao_DMQ-1-27.3");
             retroactiveNowService.updateData(retroactiveNow);
             //上传MES系统
-            mesService.getBatchNoResult(message, true);
+            mesService.getBatchNoResult(message, 1);
             //回写PLC读码完成
-            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeInt32(DaoJiaoPlcEnum.RETURNOUTCOME.getMetadata(), 18);
-            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeInt32(DaoJiaoPlcEnum.READCODE.getMetadata(), 0);
+            byte RETURNOUTCOME = 18;
+            byte init = 0;
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeByte(DaoJiaoPlcEnum.RETURNOUTCOME.getMetadata(), RETURNOUTCOME);
+            Thread.sleep(3000L);
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeByte(DaoJiaoPlcEnum.READCODE.getMetadata(), init);
             //添加日志
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "识别到码:" + message, "1"));
         } catch (Exception e) {

+ 66 - 6
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader5Connect.java

@@ -1,7 +1,10 @@
 package com.warewms.hailiang.connect;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+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.connect.base.TCPConnectBase;
@@ -14,17 +17,17 @@ import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -62,11 +65,20 @@ public class CodeReader5Connect implements TCPConnectBase {
 
     private PlcConnectServiceRunner plcConnectServiceRunner;
 
+    private RedisCache redisCache;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
+    private ScheduledFuture<?> scheduledFuture = null;
+
     {
         mesService = SpringUtil.getBean(MesService.class);
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
         plcConnectServiceRunner = SpringUtil.getBean(PlcConnectServiceRunner.class);
+        redisCache = SpringUtil.getBean(RedisCache.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
     }
+
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -80,11 +92,13 @@ public class CodeReader5Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1, 0, 0, TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter() {
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         log.error("设备:{}连接已断开!", deviceName);
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
 
@@ -103,6 +117,7 @@ public class CodeReader5Connect implements TCPConnectBase {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
 
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -136,6 +151,11 @@ public class CodeReader5Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                             log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                            if (ObjectUtil.isNotNull(redisCache.getCacheObject(deviceName + "_retry"))) {
+                                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+                            }
+                            //心跳
+                            ConnectsTheHeartbeat();
                         } else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         }
@@ -164,6 +184,46 @@ public class CodeReader5Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
+    /**
+     * 连接心跳
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "未识别到码", "2"));
+//
+//                return;
+//            }
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//                a++;
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
+
+
     @Override
     public void processMessages(String message) {
         try {
@@ -179,13 +239,13 @@ public class CodeReader5Connect implements TCPConnectBase {
                 retroactiveNowService.updateData(retroactiveNow);
                 plcConnectServiceRunner.getPlcServer(DeviceNameEnum.XIMIANPLC.getDeviceName()).writeBoolean(XiMianPlcEnum.ISREAD.getMetadata(), false);
                 //上传ME系统
-                mesService.processFeedback(message,"1");
+                mesService.processFeedback(message, "1");
                 //添加设备日志
                 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"));
+            log.error("铣面读码任务执行异常,msg:{}", e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
         }
     }
 

+ 59 - 3
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader6Connect.java

@@ -2,26 +2,29 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+import com.warewms.common.core.domain.R;
+import com.warewms.common.core.redis.RedisCache;
 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.DeviceNameEnum;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -57,9 +60,17 @@ public class CodeReader6Connect implements TCPConnectBase {
 
     private RetroactiveNowService retroactiveNowService;
 
+    private RedisCache redisCache;
+
+    private ScheduledFuture<?> scheduledFuture =null;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
     {
         mesService = SpringUtil.getBean(MesService.class);
         retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+        redisCache = SpringUtil.getBean(RedisCache.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
     }
     @Override
     public void init() throws InterruptedException {
@@ -74,11 +85,13 @@ public class CodeReader6Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
                                         log.error("设备:{}连接已断开!",deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
                                     @Override
@@ -94,6 +107,7 @@ public class CodeReader6Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -126,6 +140,7 @@ public class CodeReader6Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
                             log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
+                            ConnectsTheHeartbeat();
                         }else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
                         }
@@ -139,6 +154,23 @@ public class CodeReader6Connect implements TCPConnectBase {
         }
     }
 
+    /**
+     * 连接心跳
+     *
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
+
     @Override
     public void close() {
         group.shutdownGracefully();
@@ -154,6 +186,29 @@ public class CodeReader6Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//                a++;
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
+
+
     @Override
     public void processMessages(String message) {
         try {
@@ -171,6 +226,7 @@ public class CodeReader6Connect implements TCPConnectBase {
                 mesService.processFeedback(message,"2");
                 //添加设备日志
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "识别到码:" + message, "1"));
+                redisCache.setCacheObject(DeviceNameEnum.ZHAZHIPLC.getDeviceName(),DeviceNameEnum.ZHAZHIPLC.getDeviceName(),30,TimeUnit.SECONDS);
             }
         }catch (Exception e){
             log.error("轧制读码任务执行异常,msg:{}",e.getMessage());

+ 27 - 18
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader7Connect.java

@@ -10,10 +10,12 @@ import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.RetroactiveNowService;
 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
@@ -68,6 +70,7 @@ public class CodeReader7Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
@@ -149,25 +152,31 @@ public class CodeReader7Connect implements TCPConnectBase {
         return pipeline;
     }
 
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "读码器识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//                a++;
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
+
     @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.setLotNo(message);
-                retroactiveNow.setStatus("5");
-                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"));
-        }
+        log.info("大散盘1号行车读码器消息:{}", message);
+        SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-1-27.7", deviceName, "读码器识别到码:" + message, "1"));
     }
 }

+ 84 - 8
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader8Connect.java

@@ -1,23 +1,32 @@
 package com.warewms.hailiang.connect;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+import com.warewms.common.core.redis.RedisCache;
+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.DaSanPanPlcEnum;
+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.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.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
-
 /**
  * Created with IntelliJ IDEA.
  *
@@ -25,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Date: 2023/8/9
  * Time: 15:45
  * To change this template use File | Settings | File Templates.
- * Description:倒角读码器连接
+ * Description:大散盘行车2号读码器
  **/
 @Slf4j
 public class CodeReader8Connect implements TCPConnectBase {
@@ -36,7 +45,7 @@ public class CodeReader8Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader8";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -46,6 +55,24 @@ public class CodeReader8Connect implements TCPConnectBase {
 
     private ChannelPipeline pipeline;
 
+    private MesService mesService;
+
+    private RetroactiveNowService retroactiveNowService;
+
+    private PlcConnectServiceRunner plcConnectServiceRunner;
+
+    private ScheduledFuture<?> scheduledFuture =null;
+
+    private ScheduledExecutorService scheduledExecutorService;
+
+
+    {
+        mesService = SpringUtil.getBean(MesService.class);
+        retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+        plcConnectServiceRunner = SpringUtil.getBean(PlcConnectServiceRunner.class);
+        scheduledExecutorService = SpringUtil.getBean(ScheduledExecutorService.class);
+    }
+
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -59,11 +86,13 @@ public class CodeReader8Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
                                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
                                         log.error("设备:{}连接已断开!",deviceName);
+                                        scheduledFuture.cancel(true);
                                         retry();
                                     }
                                     @Override
@@ -79,6 +108,7 @@ public class CodeReader8Connect implements TCPConnectBase {
                     if (channelFuture.isSuccess()) {
                         SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "1"));
                         log.info("ip:{},deviceName:{}连接成功", IP_ADDR, deviceName);
+                        ConnectsTheHeartbeat();
                     } else {
                         log.info("ip:{},deviceName:{}连接失败等待重试!", IP_ADDR, deviceName);
                         retry();
@@ -111,6 +141,7 @@ public class CodeReader8Connect implements TCPConnectBase {
                         if (channelFuture.isSuccess()) {
                             SpringUtil.getApplicationContext().publishEvent(new Device(deviceName,"1"));
                             log.info("ip:{},deviceName:{}连接成功",IP_ADDR,deviceName);
+                            ConnectsTheHeartbeat();
                         }else {
                             log.info("ip:{},deviceName:{}连接失败等待重试!",IP_ADDR,deviceName);
                         }
@@ -123,6 +154,22 @@ public class CodeReader8Connect implements TCPConnectBase {
             e.printStackTrace();
         }
     }
+    /**
+     * 连接心跳
+     *
+     */
+    private void ConnectsTheHeartbeat() {
+        scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+            try {
+                log.info("发送心跳,设备:{}", deviceName);
+                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.heartbeat, CharsetUtil.UTF_8));
+            } catch (Exception e) {
+                log.error("设备:{},连接中断", deviceName);
+                SpringUtil.getApplicationContext().publishEvent(new Device(deviceName, "2"));
+                retry();
+            }
+        }, 0, 3, TimeUnit.SECONDS);
+    }
 
     @Override
     public void close() {
@@ -137,11 +184,40 @@ public class CodeReader8Connect implements TCPConnectBase {
 
     @Override
     public ChannelPipeline getChannel() {
-        return null;
+        return pipeline;
     }
 
     @Override
     public void processMessages(String message) {
-
+        try {
+            log.info("大散盘2号行车读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-2-27.8", deviceName, "未识别到码", "2"));
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_two.getMetadata(), (byte) 2);
+
+                Thread.sleep(10000L);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_two.getMetadata(),(byte) 0);
+
+            } else {
+                //获取出料位
+                float v = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readFloat32(DaSanPanPlcEnum.TASK_ADD_1.getMetadata());
+                String deviceId = v == 10 ? "Z1SZ10" : "Z1SP0" + v;
+                String batchNo = mesService.bindLotNo(deviceId, message);
+
+                //读取到托盘号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setBatchNo(batchNo);
+                retroactiveNow.setLotNo(message);
+                retroactiveNow.setStatus("5");
+                retroactiveNow.setDeviceId("Z1_DaSanPan_DMQ-1-27.8");
+                retroactiveNow.setSanPanDevice(deviceId);
+                retroactiveNowService.DataTwins(retroactiveNow);
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).writeByte(DaSanPanPlcEnum.ISREAD_two.getMetadata(), (byte) 0);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-2-27.8", deviceName, "读码器识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("大散盘2号行车读码任务执行异常,msg:{}",e.getMessage());
+        }
     }
 }

+ 31 - 3
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader9Connect.java

@@ -2,14 +2,18 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+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 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 io.netty.handler.timeout.IdleStateHandler;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 
@@ -36,7 +40,7 @@ public class CodeReader9Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader9";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -59,6 +63,7 @@ public class CodeReader9Connect implements TCPConnectBase {
                             @Override
                             protected void initChannel(SocketChannel socketChannel) throws Exception {
                                 pipeline = socketChannel.pipeline();
+                                pipeline.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
                                 pipeline.addLast(new ChannelInboundHandlerAdapter(){
                                     @Override
                                     public void channelInactive(ChannelHandlerContext ctx) {
@@ -137,11 +142,34 @@ public class CodeReader9Connect implements TCPConnectBase {
 
     @Override
     public ChannelPipeline getChannel() {
-        return null;
+        return pipeline;
     }
 
+
     @Override
     public void processMessages(String message) {
-
+        log.info("大散盘4号行车读码器消息:{}", message);
+        SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-3-27.9", deviceName, "读码器识别到码:" + message, "1"));
     }
+
+//    private int a = 1;
+//
+//    @Override
+//    public void processMessages(String message) {
+//        try {
+//            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+//                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-3-27.9", deviceName, "未识别到码", "2"));
+//                return;
+//            }
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-3-27.9", deviceName, "读码器识别到码:" + message, "1"));
+//            Thread.sleep(500);
+//            if (a <= 300) {
+//                pipeline.writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
+//                a++;
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-3-27.9", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
+//        }
+//    }
 }

+ 7 - 3
warewms-system/src/main/java/com/warewms/hailiang/contoller/DeviceController.java

@@ -1,8 +1,9 @@
-package com.warewms.hailiang.contoller;
+package com.warewms.hailiang.controller;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.warewms.common.core.domain.R;
-import com.warewms.common.utils.StringUtils;
+import com.warewms.common.core.domain.model.LoginUser;
+import com.warewms.common.utils.SecurityUtils;
 import com.warewms.hailiang.domain.Device;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.service.DeviceService;
@@ -36,7 +37,10 @@ public class DeviceController {
     public R triggerCodeRead(@RequestBody Device device) {
         R r = processRealizationService.CodeReadingProcess(device.getDeviceName());
         if(R.isSuccess(r)){
-            SpringUtil.getApplicationContext().publishEvent(new DeviceLog(device.getDeviceId(), device.getDeviceName(), "手动触发读码", "1"));
+            DeviceLog deviceLog = new DeviceLog(device.getDeviceId(), device.getDeviceName(), "手动触发读码", "1");
+            deviceLog.setCreateBy(SecurityUtils.getUsername());
+            deviceLog.setUpdateBy(SecurityUtils.getUsername());
+            SpringUtil.getApplicationContext().publishEvent(deviceLog);
         }
         return r;
     }

+ 16 - 1
warewms-system/src/main/java/com/warewms/hailiang/contoller/DeviceLogController.java

@@ -1,14 +1,20 @@
-package com.warewms.hailiang.contoller;
+package com.warewms.hailiang.controller;
 
+import cn.hutool.core.bean.BeanUtil;
+import com.google.common.collect.Lists;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
+import com.warewms.common.utils.poi.ExcelUtil;
+import com.warewms.hailiang.domain.DTO.DeviceLogDTO;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.service.DeviceLogService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -27,4 +33,13 @@ public class DeviceLogController {
     public TableDataInfo<DeviceLog> getList(DeviceLog deviceLog, PageDomain pageDomain){
        return deviceLogService.getList(deviceLog,pageDomain);
     }
+
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, DeviceLog deviceLog)
+    {
+        List<DeviceLog> deviceLogList = deviceLogService.getList(deviceLog);
+        List<DeviceLogDTO> transform = Lists.transform(deviceLogList, item -> BeanUtil.copyProperties(item, DeviceLogDTO.class));
+        ExcelUtil<DeviceLogDTO> util = new ExcelUtil<DeviceLogDTO>(DeviceLogDTO.class);
+        util.exportExcel(response, transform, "设备日志");
+    }
 }

+ 9 - 9
warewms-system/src/main/java/com/warewms/hailiang/contoller/RetroactiveHistoryController.java

@@ -1,19 +1,13 @@
-package com.warewms.hailiang.contoller;
+package com.warewms.hailiang.controller;
 
-import com.warewms.common.annotation.Log;
 import com.warewms.common.core.domain.R;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
-import com.warewms.common.core.domain.entity.SysUser;
-import com.warewms.common.enums.BusinessType;
 import com.warewms.common.utils.poi.ExcelUtil;
 import com.warewms.hailiang.domain.DTO.RetroactiveHistoryDTO;
 import com.warewms.hailiang.domain.RetroactiveHistory;
-import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.RetroactiveHistoryService;
-import com.warewms.hailiang.service.RetroactiveNowService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author
@@ -44,8 +39,8 @@ public class RetroactiveHistoryController {
     }
 
     @GetMapping("/info")
-    public R<List<RetroactiveHistory>> getInfoList(RetroactiveHistory retroactiveHistory){
-        return R.ok( retroactiveHistoryService.getHistoryList(retroactiveHistory));
+    public R<Map<String, List<RetroactiveHistory>>> getInfoList(RetroactiveHistory retroactiveHistory){
+        return R.ok( retroactiveHistoryService.getHistoryMap(retroactiveHistory));
     }
 
     @PostMapping("/export")
@@ -63,4 +58,9 @@ public class RetroactiveHistoryController {
         ExcelUtil<RetroactiveHistoryDTO> util = new ExcelUtil<RetroactiveHistoryDTO>(RetroactiveHistoryDTO.class);
         util.exportExcel(response, historyList, "铜管信息");
     }
+
+    @GetMapping("/delList")
+    public R<List<RetroactiveHistory>> getDelList(){
+        return R.ok( retroactiveHistoryService.getDelList());
+    }
 }

+ 41 - 4
warewms-system/src/main/java/com/warewms/hailiang/contoller/RetroactiveNowController.java

@@ -1,14 +1,12 @@
-package com.warewms.hailiang.contoller;
+package com.warewms.hailiang.controller;
 
 import cn.hutool.core.util.ObjectUtil;
-import com.warewms.common.annotation.Log;
 import com.warewms.common.core.domain.R;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
 import com.warewms.common.utils.StringUtils;
-import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.warewms.hailiang.domain.RetroactiveNow;
-import com.warewms.hailiang.service.DeviceLogService;
 import com.warewms.hailiang.service.RetroactiveNowService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -59,4 +57,43 @@ public class RetroactiveNowController {
     public R complement(@Validated @RequestBody RetroactiveNow retroactiveNow){
         return retroactiveNowService.complement(retroactiveNow);
     }
+
+    @PostMapping("/bindLotNo")
+    public R update(@RequestBody RetroactiveNow retroactiveNow){
+        if(ObjectUtil.isNull(retroactiveNow.getBatchNo())){
+            return R.fail("批次号不能为空");
+        }
+        if(ObjectUtil.isNull(retroactiveNow.getLotNo())){
+            return R.fail("托盘号不能为空");
+        }
+        return retroactiveNowService.update(retroactiveNow);
+    }
+    @PostMapping("/bindShelf")
+    public R bindShelf(@RequestBody RetroactiveNow retroactiveNow){
+        if(ObjectUtil.isNull(retroactiveNow.getBatchNo())){
+            return R.fail("批次号不能为空");
+        }
+        if(ObjectUtil.isNull(retroactiveNow.getShelfNumber())){
+            return R.fail("料架号不能为空");
+        }
+        if(ObjectUtil.isNull(retroactiveNow.getLotAddress())){
+            return R.fail("位置不能为空");
+        }
+        if(ObjectUtil.isNull(retroactiveNow.getNumberOfLayers())){
+            return R.fail("层数不能为空");
+        }
+        if(ObjectUtil.isNull(retroactiveNow.getUniuCode())){
+            return R.fail("机组号不能为空");
+        }
+        System.out.println(retroactiveNow);
+        return R.ok();
+//        return retroactiveNowService.update(retroactiveNow);
+    }
+
+
+
+    @DeleteMapping("/del")
+    public R delete(RetroactiveHistory retroactiveHistory){
+        return retroactiveNowService.delete(retroactiveHistory);
+    }
 }

+ 50 - 25
warewms-system/src/main/java/com/warewms/hailiang/contoller/TestContoller.java

@@ -1,4 +1,4 @@
-package com.warewms.hailiang.contoller;
+package com.warewms.hailiang.controller;
 
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
@@ -7,6 +7,11 @@ import com.warewms.common.core.domain.R;
 import com.warewms.hailiang.config.DeviceMessageSocket;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
+import com.warewms.hailiang.init.TcpServiceRunner;
+import com.warewms.hailiang.util.InkjetPrintersSetUpTools;
+import com.warewms.hailiang.util.ParseMsgTools;
+import io.netty.buffer.Unpooled;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  **/
 @RestController
 @RequestMapping("/test")
+@Slf4j
 public class TestContoller {
 
     @Autowired
@@ -32,66 +38,85 @@ public class TestContoller {
     DeviceMessageSocket deviceMessageSocket;
 
     @GetMapping("/pclTest")
-    public Object testPlc(String plcName,String db,String type,String value){
-        if (type.equals("1")){
-            db = "V"+db;
+    public Object testPlc(String plcName, String db, String type, String value) {
+        if (type.equals("1")) {
+            db = "V" + db;
             return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
         }
-        if (type.equals("2")){
-            db = "Q"+db;
+        if (type.equals("2")) {
+            db = "Q" + db;
             return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
         }
-        if (type.equals("3")){
-            db = "I"+db;
+        if (type.equals("3")) {
+            db = "I" + db;
             return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
         }
-        if (type.equals("4")){
-            db = "DB"+db;
+        if (type.equals("4")) {
+            db = "DB" + db;
             return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
         }
-        if (type.equals("5")){
-            db = "DB"+db;
+        if (type.equals("5")) {
+            db = "DB" + db;
             plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
             return "yes";
         }
-        if (type.equals("6")){
-            db = "Q"+db;
+        if (type.equals("6")) {
+            db = "Q" + db;
             plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
             return "yes";
         }
-        if (type.equals("7")){
-            db = "I"+db;
+        if (type.equals("7")) {
+            db = "I" + db;
             plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
             return "yes";
         }
-        if (type.equals("8")){
-            db = "M"+db;
+        if (type.equals("8")) {
+            db = "M" + db;
             return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
         }
-        if (type.equals("9")){
-            db = "M"+db;
+        if (type.equals("9")) {
+            db = "M" + db;
             plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
             return "yes";
         }
         return null;
     }
+
     @GetMapping("/getStatus")
-    public Object getStatus(String plcName){
+    public Object getStatus(String plcName) {
         return plcConnectServiceRunner.getPlcServer(plcName).checkConnected();
     }
 
     @GetMapping("/testNotify")
     @Anonymous
-    public R testNotify(String content,String status) throws InterruptedException {
+    public R testNotify(String content, String status) throws InterruptedException {
         Thread.sleep(3000);
-        DeviceLog deviceLog = new DeviceLog("1","倒角读码器",content,status);
+        DeviceLog deviceLog = new DeviceLog("1", "倒角读码器", content, status);
         deviceLog.setCreateBy("system");
         deviceLog.setUpdateBy("system");
         JSONObject jsonObject = new JSONObject();
-        jsonObject.set("type","notify");
-        jsonObject.set("content",JSONUtil.parse(deviceLog));
+        jsonObject.set("type", "notify");
+        jsonObject.set("content", JSONUtil.parse(deviceLog));
         //推送消息
         deviceMessageSocket.sendAllMessage(jsonObject.toString());
         return R.ok();
     }
+
+    @Autowired
+    TcpServiceRunner tcpServiceRunner;
+
+    @GetMapping("/testCode")
+    @Anonymous
+    public R testCode(String code) {
+        String updateCode = InkjetPrintersSetUpTools.updateCode(code);
+        log.info(code);
+        tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.hexString2Bytes(updateCode)));
+        return R.ok();
+    }
+
+    public static void main(String[] args) {
+        System.out.println(InkjetPrintersSetUpTools.updateCode("237191409000"));
+    }
+
+
 }

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

@@ -4,11 +4,15 @@ package com.warewms.hailiang.domain;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.warewms.common.annotation.Excel;
 import com.warewms.common.core.domain.base.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * 设备日志表
@@ -27,23 +31,28 @@ public class DeviceLog extends BaseEntity implements Serializable  {
     /**
      * 设备编号
      */
+    @Excel(name = "设备编号")
     private String deviceId;
 
     /**
      * 设备名称
      */
+    @Excel(name = "设备名称")
     private String deviceName;
 
     /**
      * 日志内容
      */
+    @Excel(name = "日志内容")
     private String content;
 
     /**
      * 状态(1:信息:2报警)
      */
+    @Excel(name = "类型",readConverterExp="1=信息,2=报警")
     private String status;
 
+
     private static final long serialVersionUID = 1L;
 
     public DeviceLog(String deviceId, String deviceName, String content, String status) {

+ 38 - 4
warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveHistory.java

@@ -1,9 +1,7 @@
 package com.warewms.hailiang.domain;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 
@@ -61,4 +59,40 @@ public class RetroactiveHistory extends BaseEntity {
      */
     private String deviceId;
 
+    /**
+     * 删除标识
+     */
+    @TableLogic
+    private String delFlag;
+
+    /**
+     * 删除原因
+     */
+    private String delRemark;
+
+    /**
+     * 料架号
+     */
+    private String shelfNumber;
+
+    /**
+     * 位置
+     */
+    private String lotAddress;
+
+    /**
+     * 层数
+     */
+    private String numberOfLayers;
+
+    /**
+     * 机组号
+     */
+    private String uniuCode;
+
+
+    /**
+     * 大散盘产出地址
+     */
+    private String sanPanDevice;
 }

+ 34 - 1
warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveNow.java

@@ -1,5 +1,6 @@
 package com.warewms.hailiang.domain;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -20,10 +21,16 @@ import javax.validation.constraints.NotBlank;
 @Data
 @NoArgsConstructor
 public class RetroactiveNow extends BaseEntity {
+
+    /**
+     * 追溯id
+     */
+    @TableId(type = IdType.ASSIGN_ID)
+    private String nowId;
+
     /**
      * 追溯id
      */
-    @TableId
     private String retroactiveId;
 
     /**
@@ -37,16 +44,42 @@ public class RetroactiveNow extends BaseEntity {
      */
     private String batchNo;
 
+    /**
+     * 料架号
+     */
+    private String shelfNumber;
+
+    /**
+     * 位置
+     */
+    private String lotAddress;
+
+    /**
+     * 层数
+     */
+    private String numberOfLayers;
+
     /**
      * 托盘号
      */
     private String lotNo;
 
+    /**
+     * 机组号
+     */
+    private String uniuCode;
+
     /**
      * 重量
      */
     private Double weight;
 
+    /**
+     * 大散盘产出地址
+     */
+    private String sanPanDevice;
+
+
     /**
      * 生产状态
      */

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

@@ -2,15 +2,24 @@ package com.warewms.hailiang.enums;
 
 public enum DaSanPanPlcEnum {
     /**
-     * 号下料读码信号
+     * 号下料读码信号
      */
-    ISREAD_one("DB200.0.1"),
+    ISREAD_two("DB200.1.0"),
     /**
      * 四号下料读码信号
      */
-    ISREAD_fourth("DB200.0.2");
+    ISREAD_fourth("DB200.2.0"),
+
+    /**
+     *一号车任务位置
+     */
+    TASK_ADD_1("DB200.2.0"),
 
 
+    /**
+     *二号车任务位置
+     */
+    TASK_ADD_2("DB200.8.0");
     private String metadata;
 
 

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

@@ -14,17 +14,17 @@ public enum InkjetPrintersDirectivesEnum {
     /**
      * 开机
      */
-    BOOT("30 00 01 FF CE"),
+    BOOT("300001FFCE"),
 
     /**
      * 关机
      */
-    SHUTDOWN("30 00 01 00 31"),
+    SHUTDOWN("3000010031"),
 
     /**
      * 消除故障
      */
-    CODEE6("E6 00 00 E6"),
+    CODEE6("E60000E6"),
 
     /**
      * 设置打印反馈
@@ -34,7 +34,7 @@ public enum InkjetPrintersDirectivesEnum {
     /**
      * 触发打印
      */
-    CODE94("94 00 00 94");
+    CODE94("94000094");
 
 
     private String code;

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

@@ -47,17 +47,17 @@ 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);
+                    }
+                });
             }
         }
     }

+ 27 - 22
warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java

@@ -1,11 +1,13 @@
 package com.warewms.hailiang.job;
 
+import cn.hutool.core.util.ObjectUtil;
 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;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -17,16 +19,16 @@ import javax.annotation.Resource;
 @Slf4j
 public class TraceJob {
 
-    @Resource
+    @Autowired
     private PlcConnectServiceRunner plcConnectServiceRunner;
 
-    @Resource
+    @Autowired
     private TcpServiceRunner tcpServiceRunner;
 
-    @Resource
+    @Autowired
     private ProcessRealizationService processRealizationService;
 
-    @Resource
+    @Autowired
     private RedisCache redisCache;
 
 
@@ -34,7 +36,7 @@ public class TraceJob {
      * 测试
      */
     public void test() throws InterruptedException {
-
+        processRealizationService.CodeReadingProcess("CodeReader5");
     }
 
     /**
@@ -53,12 +55,12 @@ public class TraceJob {
     /**
      * 获取喷码信号
      */
-    public void getTheChamferCompletionSignal() {
-        Integer i = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readInt32(DaoJiaoPlcEnum.CHECKFINISH.getMetadata());
+    public void getTheChamferCompletionSignal() throws InterruptedException {
+        byte i = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readByte(DaoJiaoPlcEnum.CHECKFINISH.getMetadata());
         log.info("喷码信号:{}", i);
-        if (i.equals(6)) {
+        if (i == 6) {
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.WEIGHTPLC.getDeviceName()).writeBoolean(WeighPlcEnum.returnWeight.getMetadata(), false);
             processRealizationService.DaoJiaoCodingCodeProcess();
-            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeInt32(DaoJiaoPlcEnum.CHECKFINISH.getMetadata(),0);
         }
     }
 
@@ -66,10 +68,11 @@ public class TraceJob {
      * 获取倒角机读码信号
      */
 
-    public void obtainTheChamferingMachineCodeReadingSignal (){
-        Integer i = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readInt32(DaoJiaoPlcEnum.READCODE.getMetadata());
-        log.info("倒角机读码信号,{}",i);
-        if (i.equals(16)) {
+    public void obtainTheChamferingMachineCodeReadingSignal() {
+        byte i = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readByte(DaoJiaoPlcEnum.READCODE.getMetadata());
+        log.info("倒角机读码信号,{}", i);
+        if (i == 16) {
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeByte(DaoJiaoPlcEnum.CHECKFINISH.getMetadata(), (byte) 0);
             processRealizationService.CodeReadingProcess("CodeReader3");
         }
     }
@@ -92,7 +95,9 @@ public class TraceJob {
         boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.ZHAZHIPLC.getDeviceName()).readBoolean(ZhaZhiPlcEnum.ISREAD.getMetadata());
         log.info("轧制读码信号:{}", b);
         if (b) {
-            processRealizationService.CodeReadingProcess("CodeReader6");
+            if (ObjectUtil.isNull(redisCache.getCacheObject(DeviceNameEnum.ZHAZHIPLC.getDeviceName()))){
+                processRealizationService.CodeReadingProcess("CodeReader6");
+            }
         }
     }
 
@@ -100,18 +105,18 @@ public class TraceJob {
      * 获取行车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");
-        }
+
     }
 
     /**
      * 获取行车2读码信号
      */
     public void getTheDriving2CodeReadingSignal() {
-
+        byte b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readByte(DaSanPanPlcEnum.ISREAD_two.getMetadata());
+        log.info("大散盘2号行车读码信号:{}", b);
+        if (b==1) {
+            processRealizationService.CodeReadingProcess("CodeReader8");
+        }
     }
 
     /**
@@ -125,9 +130,9 @@ public class TraceJob {
      * 获取行车4读码信号
      */
     public void getTheDriving4CodeReadingSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_fourth.getMetadata());
+        byte b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readByte(DaSanPanPlcEnum.ISREAD_fourth.getMetadata());
         log.info("大散盘4号行车读码信号:{}", b);
-        if (b) {
+        if (b==1) {
             processRealizationService.CodeReadingProcess("CodeReader12");
         }
     }

+ 3 - 0
warewms-system/src/main/java/com/warewms/hailiang/mapper/RetroactiveHistoryMapper.java

@@ -3,6 +3,8 @@ package com.warewms.hailiang.mapper;
 import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
 * @author AD
 * @description 针对表【retroactive_history(生产历史追溯表)】的数据库操作Mapper
@@ -11,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 */
 public interface RetroactiveHistoryMapper extends BaseMapper<RetroactiveHistory> {
 
+    List<RetroactiveHistory> getDelList();
 }
 
 

+ 1 - 0
warewms-system/src/main/java/com/warewms/hailiang/service/DeviceLogService.java

@@ -19,4 +19,5 @@ public interface DeviceLogService extends IService<DeviceLog> {
 
     void createLog(DeviceLog deviceLog);
 
+    List<DeviceLog> getList(DeviceLog deviceLog);
 }

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

@@ -15,7 +15,7 @@ public interface ProcessRealizationService {
     /**
      * 倒角工艺中喷码流程实现
      */
-    void DaoJiaoCodingCodeProcess();
+    void DaoJiaoCodingCodeProcess() throws InterruptedException;
 
     /**
      * 读码触发实现

+ 5 - 1
warewms-system/src/main/java/com/warewms/hailiang/service/RetroactiveHistoryService.java

@@ -5,9 +5,9 @@ import com.warewms.common.core.domain.base.page.TableDataInfo;
 import com.warewms.hailiang.domain.DTO.RetroactiveHistoryDTO;
 import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.warewms.hailiang.domain.RetroactiveNow;
 
 import java.util.List;
+import java.util.Map;
 
 /**
 * @author AD
@@ -20,5 +20,9 @@ public interface RetroactiveHistoryService extends IService<RetroactiveHistory>
 
     List<RetroactiveHistory> getHistoryList(RetroactiveHistory retroactiveHistory);
 
+    Map<String, List<RetroactiveHistory>> getHistoryMap(RetroactiveHistory retroactiveHistory);
+
     List<RetroactiveHistoryDTO> export(RetroactiveHistory retroactiveHistory, String ids);
+
+    List<RetroactiveHistory> getDelList();
 }

+ 7 - 0
warewms-system/src/main/java/com/warewms/hailiang/service/RetroactiveNowService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.warewms.common.core.domain.R;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
+import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.warewms.hailiang.domain.RetroactiveNow;
 
 import java.util.List;
@@ -26,4 +27,10 @@ public interface RetroactiveNowService extends IService<RetroactiveNow> {
     int finishProduce(RetroactiveNow retroactiveNow);
 
     R complement(RetroactiveNow retroactiveNow);
+
+    R update(RetroactiveNow retroactiveNow);
+
+    R delete(RetroactiveHistory retroactiveHistory);
+
+    int DataTwins(RetroactiveNow retroactiveNow);
 }

+ 23 - 3
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceLogServiceImpl.java

@@ -1,7 +1,6 @@
 package com.warewms.hailiang.service.impl;
 
 
-import cn.hutool.json.JSON;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -23,6 +22,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author AD
@@ -60,8 +60,10 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
     @Async
     @EventListener
     public void createLog(DeviceLog deviceLog) {
-        deviceLog.setCreateBy("system");
-        deviceLog.setUpdateBy("system");
+        if (StringUtils.isEmpty(deviceLog.getCreateBy())){
+            deviceLog.setCreateBy("system");
+            deviceLog.setUpdateBy("system");
+        }
         deviceLogMapper.insert(deviceLog);
         //推送消息
         for (Device device : deviceService.getList()) {
@@ -75,6 +77,24 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
         deviceMessageSocket.sendAllMessage(jsonObject.toString());
     }
 
+    @Override
+    public List<DeviceLog> getList(DeviceLog deviceLog) {
+        List<DeviceLog> deviceLogs = deviceLogMapper.selectList(new LambdaQueryWrapper<DeviceLog>()
+                .eq(StringUtils.isNotEmpty(deviceLog.getDeviceId()), DeviceLog::getDeviceId, deviceLog.getDeviceId())
+                .eq(StringUtils.isNotEmpty(deviceLog.getDeviceName()), DeviceLog::getDeviceName, deviceLog.getDeviceName())
+                .eq(StringUtils.isNotEmpty(deviceLog.getStatus()), DeviceLog::getStatus, deviceLog.getStatus())
+                .likeLeft(DeviceLog::getContent,deviceLog.getContent()));
+
+        return deviceLogs.stream().map(item->{
+            for (Device device : deviceService.getList()) {
+                if (item.getDeviceId().equals(device.getDeviceId())){
+                    item.setDeviceName(device.getAbbreviation());
+                }
+            }
+            return  item;
+        }).collect(Collectors.toList());
+    }
+
 }
 
 

+ 5 - 5
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceServiceImpl.java

@@ -26,10 +26,10 @@ public class DeviceServiceImpl implements DeviceService {
         devices.add(new Device("Z1_Zhazhi_PLC-1-52.24", "ZhaZhiPlc", "轧制辊道PLC", "Z1", "172.20.52.24", 102, "S7", "2"));
         devices.add(new Device("Z1_ZhaZhi_DMQ-1-27.6", "CodeReader6", "轧制读码器", "Z1", "172.20.27.6", 51236, "TCP", "2"));
         devices.add(new Device("Z1_DaSanPan_PLC-1-54.121", "DaSanPanPlc", "大散盘PLC", "Z1", "172.20.54.121", 102, "S7", "2"));
-        devices.add(new Device("Z1_DaSanPan_DMQ-1-27.7", "CodeReader7", "大散盘读码器1", "Z1", "172.20.27.7", 51236, "TCP", "2"));
-        devices.add(new Device("Z1_DaSanPan_DMQ-2-27.8", "CodeReader8", "大散盘读码器2", "Z1", "172.20.27.8", 51236, "TCP", "2"));
-        devices.add(new Device("Z1_DaSanPan_DMQ-3-27.9", "CodeReader9", "大散盘读码器3", "Z1", "172.20.27.9", 51236, "TCP", "2"));
-        devices.add(new Device("Z1_DaSanPan_DMQ-4-27.12", "CodeReader12", "大散盘读码器4", "Z1", "172.20.27.12", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_DaSanPan_DMQ-1-27.7", "CodeReader7", "大散盘一号读码器", "Z1", "172.20.27.7", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_DaSanPan_DMQ-2-27.8", "CodeReader8", "大散盘二号读码器", "Z1", "172.20.27.8", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_DaSanPan_DMQ-3-27.9", "CodeReader9", "大散盘三号读码器", "Z1", "172.20.27.9", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_DaSanPan_DMQ-4-27.12", "CodeReader12", "大散盘四号读码器", "Z1", "172.20.27.12", 51236, "TCP", "2"));
         devices.add(new Device("Z1_TuiHuoShangLiao_PLC-1-", "TuiHuoUPPlc", "退火上料PLC", "Z1", "172.20.27.13", 51236, "s7", "2"));
         devices.add(new Device("Z1_TuiHuoXiaLiao_PLC-1-", "TuiHuoDownPlc", "退火下料PLC", "Z1", "172.20.27.13", 51236, "s7", "2"));
         devices.add(new Device("Z1_TuiHuoShangLiao_DMQ-1-27.13", "CodeReader13", "退火上料读码器", "Z1", "172.20.27.13", 51236, "TCP", "2"));
@@ -59,7 +59,7 @@ public class DeviceServiceImpl implements DeviceService {
             if(device.getDeviceName().equals(d.getDeviceName())){
                 device.setStatus(d.getStatus());
                 if ("2".equals(d.getStatus())){
-                    SpringUtil.getApplicationContext().publishEvent(new DeviceLog(device.getDeviceId(), device.getDeviceName(), "连接中断,请联系管理员!",d.getStatus() ));
+                    SpringUtil.getApplicationContext().publishEvent(new DeviceLog(device.getDeviceId(), device.getDeviceName(), device.getAbbreviation()+ "连接中断,请联系管理员!",d.getStatus() ));
                 }
             }
         }

+ 28 - 10
warewms-system/src/main/java/com/warewms/hailiang/service/impl/ProcessRealizationServiceImpl.java

@@ -19,12 +19,16 @@ 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.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
 import io.netty.util.CharsetUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.HashMap;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -49,6 +53,17 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
+    private HashMap<String, Integer> rertyTime = new HashMap<>();
+
+    {
+        rertyTime.put("CodeReader5", 10);
+        rertyTime.put("CodeReader8", 60);
+        rertyTime.put("CodeReader12", 60);
+    }
+
     @Override
     @Transactional
     public void weightProcess() throws InterruptedException {
@@ -69,11 +84,9 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
                 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));
+                tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.hexString2Bytes(updateCode)));
                 redisCache.setCacheObject("InkjetPrinters", BatchNo);
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_PMQ-1-27.4", "InkjetPrinters", "喷码内容修改完成,内容为:" + retroactiveNow.getBatchNo(), "1"));
                 log.info("追溯记录生成成功,BatchNo:{}", BatchNo);
@@ -89,14 +102,17 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
         retroactiveNow.setStatus("1");
         retroactiveNow = retroactiveNowService.selectTheOneByParameter(retroactiveNow);
         if (ObjectUtil.isNotNull(retroactiveNow)) {
-            if (!redisCache.getCacheObject("InkjetPrinters").equals(retroactiveNow.getBatchNo())) {
-                //更新喷码机条码内容
-                String updateCode = InkjetPrintersSetUpTools.updateCode(retroactiveNow.getBatchNo());
-                tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(ParseMsgTools.hexString2Bytes(updateCode));
+            //更新喷码机条码内容
+            String updateCode = InkjetPrintersSetUpTools.updateCode(retroactiveNow.getBatchNo());
+            ChannelFuture channelFuture = tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.hexString2Bytes(updateCode)));
+            if (channelFuture.isSuccess()) {
+                redisCache.setCacheObject("InkjetPrinters", retroactiveNow.getBatchNo());
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_PMQ-1-27.4", "InkjetPrinters", "喷码内容修改完成,内容为:" + retroactiveNow.getBatchNo(), "1"));
+                //回写plc信号进行喷码
+                plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeByte(DaoJiaoPlcEnum.CHECKFINISH.getMetadata(), (byte) 8);
             }
-            //回写plc信号进行喷码
-            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeInt32(DaoJiaoPlcEnum.CHECKFINISH.getMetadata(),8);
+        }else {
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_PLC-1-27.2", "DaoJiaoJiPlc", "数据不存在已称重状态的铜管信息", "1"));
         }
     }
 
@@ -107,8 +123,10 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
             log.info("读码器{}正在读码!", codeReadName);
             return R.fail("该读码器正在读码,请勿重复操作");
         }
+        redisCache.setCacheObject(codeReadName + "_retry", codeReadName, 10, TimeUnit.SECONDS);
         tcpServiceRunner.getTCPInstanceList(codeReadName).getChannel().writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
-        redisCache.setCacheObject(codeReadName,codeReadName, 30, TimeUnit.SECONDS);
+        redisCache.setCacheObject(codeReadName, codeReadName, ObjectUtil.isNull(rertyTime.get(codeReadName)) ? 5 : rertyTime.get(codeReadName), TimeUnit.SECONDS);
+
         return R.ok();
     }
 }

+ 27 - 4
warewms-system/src/main/java/com/warewms/hailiang/service/impl/RetroactiveHistoryServiceImpl.java

@@ -11,7 +11,6 @@ import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.domain.DTO.RetroactiveHistoryDTO;
 import com.warewms.hailiang.domain.Device;
 import com.warewms.hailiang.domain.RetroactiveHistory;
-import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.DeviceService;
 import com.warewms.hailiang.service.RetroactiveHistoryService;
 import com.warewms.hailiang.mapper.RetroactiveHistoryMapper;
@@ -19,10 +18,10 @@ import com.warewms.system.service.impl.SysDictTypeServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.sql.Wrapper;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -51,6 +50,7 @@ public class RetroactiveHistoryServiceImpl extends ServiceImpl<RetroactiveHistor
                 .like(StringUtils.isNotEmpty(retroactiveHistory.getBatchNo()),RetroactiveHistory::getBatchNo,retroactiveHistory.getBatchNo())
                 .like(StringUtils.isNotEmpty(retroactiveHistory.getLotNo()),RetroactiveHistory::getLotNo,retroactiveHistory.getLotNo())
                 .eq(StringUtils.isNotEmpty(retroactiveHistory.getStatus()),RetroactiveHistory::getStatus,retroactiveHistory.getStatus())
+                .eq(RetroactiveHistory::getDelFlag,"0")
                 .orderByDesc(RetroactiveHistory::getCreateTime)
 
         ));
@@ -59,11 +59,29 @@ public class RetroactiveHistoryServiceImpl extends ServiceImpl<RetroactiveHistor
     @Override
     public List<RetroactiveHistory> getHistoryList(RetroactiveHistory retroactiveHistory) {
         return retroactiveHistoryMapper.selectList(new LambdaQueryWrapper<RetroactiveHistory>()
-                .like(StringUtils.isNotEmpty(retroactiveHistory.getRetroactiveId()),RetroactiveHistory::getRetroactiveId,retroactiveHistory.getRetroactiveId())
-                .eq(StringUtils.isNotEmpty(retroactiveHistory.getStatus()),RetroactiveHistory::getStatus,retroactiveHistory.getStatus())
+                .like(StringUtils.isNotEmpty(retroactiveHistory.getRetroactiveId()), RetroactiveHistory::getRetroactiveId, retroactiveHistory.getRetroactiveId())
+                .eq(StringUtils.isNotEmpty(retroactiveHistory.getStatus()), RetroactiveHistory::getStatus, retroactiveHistory.getStatus())
+                .eq(RetroactiveHistory::getDelFlag, "0")
                 .orderByAsc(RetroactiveHistory::getCreateTime));
     }
 
+    @Override
+    public Map<String, List<RetroactiveHistory>> getHistoryMap(RetroactiveHistory retroactiveHistory) {
+        Map<String, List<RetroactiveHistory>> collect = retroactiveHistoryMapper.selectList(new LambdaQueryWrapper<RetroactiveHistory>()
+                .like(StringUtils.isNotEmpty(retroactiveHistory.getRetroactiveId()), RetroactiveHistory::getRetroactiveId, retroactiveHistory.getRetroactiveId())
+                .eq(StringUtils.isNotEmpty(retroactiveHistory.getStatus()), RetroactiveHistory::getStatus, retroactiveHistory.getStatus())
+                .orderByAsc(RetroactiveHistory::getCreateTime)).stream().collect(Collectors.groupingBy(RetroactiveHistory::getStatus));
+
+        for (RetroactiveHistory history : collect.get("5")) {
+            for (Device device : deviceService.getList()) {
+                if (device.getDeviceId().equals(history.getDeviceId())){
+                    history.setDeviceId(device.getAbbreviation());
+                }
+            }
+        }
+        return collect;
+    }
+
     @Override
     public List<RetroactiveHistoryDTO> export(RetroactiveHistory retroactiveHistory, String ids) {
         LambdaQueryWrapper<RetroactiveHistory> retroactiveHistoryLambdaQueryWrapper = Wrappers.lambdaQuery(RetroactiveHistory.class);
@@ -99,6 +117,11 @@ public class RetroactiveHistoryServiceImpl extends ServiceImpl<RetroactiveHistor
             return retroactiveHistoryDTO;
         }).collect(Collectors.toList());
     }
+
+    @Override
+    public List<RetroactiveHistory> getDelList() {
+        return retroactiveHistoryMapper.getDelList();
+    }
 }
 
 

+ 157 - 27
warewms-system/src/main/java/com/warewms/hailiang/service/impl/RetroactiveNowServiceImpl.java

@@ -2,16 +2,21 @@ package com.warewms.hailiang.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.extra.spring.SpringUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.warewms.common.core.domain.R;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
 import com.warewms.common.core.domain.model.LoginUser;
+import com.warewms.common.core.redis.RedisCache;
 import com.warewms.common.exception.ServiceException;
 import com.warewms.common.utils.SecurityUtils;
 import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.MES.MesService;
+import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.mapper.RetroactiveHistoryMapper;
@@ -25,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author AD
@@ -45,6 +51,10 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
     @Autowired
     private MesService mesService;
 
+    @Autowired
+
+    private RedisCache redisCache;
+
     @Override
     public TableDataInfo<RetroactiveNow> getList(RetroactiveNow retroactiveNow, PageDomain pageDomain, List<String> inStatus) {
         Map<String, Object> params = retroactiveNow.getParams();
@@ -53,43 +63,58 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
                 .like(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
                 .like(StringUtils.isNotEmpty(retroactiveNow.getLotNo()), RetroactiveNow::getLotNo, retroactiveNow.getLotNo())
                 .in(inStatus.size() > 0, RetroactiveNow::getStatus, inStatus)
+                .orderByDesc(RetroactiveNow::getStatus)
                 .orderByDesc(RetroactiveNow::getCreateTime)
         ));
     }
 
     @Override
+    @Transactional
     public int insertData(RetroactiveNow retroactiveNow) {
+        if (ObjectUtil.isNotNull(redisCache.getCacheObject("weigh" + retroactiveNow.getBatchNo()))) {
+            return 1;
+        }
         List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
                 .eq(RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
         );
         if (retroactiveNows.size() > 0) {
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ChengZhong_PLC-1-52.21", "ChengZhongPlc", "数据库中已存在相同批次号,请联系管理员!", "2"));
             throw new ServiceException("数据库中已存在相同批次号");
         }
         retroactiveNowMapper.insert(retroactiveNow);
-        return retroactiveHistoryMapper.insert(BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class));
+        int insert = retroactiveHistoryMapper.insert(BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class));
+        redisCache.setCacheObject("weigh" + retroactiveNow.getBatchNo(), retroactiveNow.getBatchNo(), 30, TimeUnit.SECONDS);
+        return insert;
     }
 
     @Override
     public RetroactiveNow selectTheOneByParameter(RetroactiveNow retroactiveNow) {
-        return retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
+        List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
                 .eq(StringUtils.isNotEmpty(retroactiveNow.getRetroactiveId()), RetroactiveNow::getRetroactiveId, retroactiveNow.getRetroactiveId())
                 .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
                 .eq(StringUtils.isNotEmpty(retroactiveNow.getStatus()), RetroactiveNow::getStatus, retroactiveNow.getStatus())
+                .orderByDesc(RetroactiveNow::getStatus)
         );
+        if (retroactiveNows.isEmpty()) {
+            return null;
+        } else {
+            return retroactiveNows.get(0);
+        }
     }
 
     @Override
     @Transactional
     public int updateData(RetroactiveNow retroactiveNow) {
+        //校验
         RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
         baseData.setStatus(retroactiveNow.getStatus());
         baseData.setDeviceId(retroactiveNow.getDeviceId());
         baseData.setUpdateBy("system");
+        baseData.setUpdateTime(new Date());
         retroactiveNowMapper.updateById(baseData);
         RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
         retroactiveHistory.setCreateTime(baseData.getUpdateTime());
         return retroactiveHistoryMapper.insert(retroactiveHistory);
-
     }
 
     @Override
@@ -101,40 +126,122 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
         baseData.setUpdateBy("system");
         RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
         retroactiveHistory.setCreateTime(new Date());
-        retroactiveHistoryMapper.insert(retroactiveHistory);
-        return retroactiveNowMapper.deleteById(baseData);
+        int delete = retroactiveNowMapper.delete(new LambdaQueryWrapper<RetroactiveNow>().eq(RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo()));
+        if (delete == 1) {
+            retroactiveHistoryMapper.insert(retroactiveHistory);
+
+        }
+        return delete;
     }
 
     @Override
     @Transactional
     public R complement(RetroactiveNow retroactiveNow) {
-        RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
-        if ("2".equals(baseData.getStatus())){
-            mesService.getBatchNoResult(retroactiveNow.getBatchNo(), true);
+        RetroactiveNow baseData = new RetroactiveNow();
+        if (!"5".equals(retroactiveNow.getStatus())) {
+            baseData = confirmTheDataByIndex(retroactiveNow);
+            if ("2".equals(retroactiveNow.getStatus())) {
+                mesService.getBatchNoResult(retroactiveNow.getBatchNo(), 1);
+            }
+            if ("3".equals(retroactiveNow.getStatus())) {
+                mesService.processFeedback(retroactiveNow.getBatchNo(), "1");
+            }
+            if ("4".equals(retroactiveNow.getStatus())) {
+                mesService.processFeedback(retroactiveNow.getBatchNo(), "2");
+            }
+            updateData(retroactiveNow, baseData);
+        } else {
+            String batchNo = mesService.bindLotNo(retroactiveNow.getDeviceId(), retroactiveNow.getLotNo());
+            if (StringUtils.isEmpty(batchNo)) {
+                return R.fail("该大散盘设备不存在产出");
+            }
+            baseData.setBatchNo(batchNo);
+            List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
+                    .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
+            );
+            if (retroactiveNows.isEmpty()) {
+                throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
+            }
+            RetroactiveNow retroactiveNow1 = retroactiveNows.get(0);
+            if (retroactiveNows.size() == 1) {
+                if (StringUtils.isEmpty(retroactiveNow1.getLotNo())) {
+                    updateData(retroactiveNow, retroactiveNow1);
+                    return R.ok();
+                }
+            } else {
+                retroactiveNow1.setNowId(null);
+                retroactiveNow1.setLotNo(retroactiveNow.getLotNo());
+                retroactiveNow1.setSanPanDevice(retroactiveNow.getSanPanDevice());
+                retroactiveNow1.setUpdateBy(SecurityUtils.getUsername());
+                retroactiveNow1.setUpdateTime(retroactiveNow.getUpdateTime());
+                retroactiveNowMapper.insert(retroactiveNow1);
+                RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNow1, RetroactiveHistory.class);
+                retroactiveHistory.setCreateTime(baseData.getUpdateTime());
+                retroactiveNow.setRemark("PDA手动补码");
+                retroactiveHistoryMapper.insert(retroactiveHistory);
+            }
+
         }
-        if ("3".equals(baseData.getStatus())){
-            mesService.processFeedback(retroactiveNow.getBatchNo(),"1");
+
+
+        return R.ok();
+    }
+
+    @Override
+    public R update(RetroactiveNow retroactiveNow) {
+        RetroactiveNow baseData = retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
+                .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
+        );
+        if (ObjectUtil.isNull(baseData)) {
+            throw new ServiceException("数据库中不存在该批次号," + retroactiveNow.getBatchNo());
         }
-        if ("4".equals(baseData.getStatus())){
-            mesService.processFeedback(retroactiveNow.getBatchNo(),"2");
+        baseData.setLotNo(retroactiveNow.getLotNo());
+        retroactiveNowMapper.updateById(baseData);
+        return R.ok();
+    }
+
+    @Override
+    @Transactional
+    public R delete(RetroactiveHistory retroactiveHistory) {
+        retroactiveHistoryMapper.update(retroactiveHistory,
+                new UpdateWrapper<RetroactiveHistory>()
+                        .set("del_remark", retroactiveHistory.getDelRemark())
+                        .set("del_flag", "1")
+                        .eq("batch_no", retroactiveHistory.getBatchNo()));
+        retroactiveNowMapper.delete(new LambdaQueryWrapper<RetroactiveNow>().eq(RetroactiveNow::getBatchNo, retroactiveHistory.getBatchNo()));
+        return R.ok();
+    }
+
+    @Override
+    @Transactional
+    public int DataTwins(RetroactiveNow retroactiveNow) {
+        if (ObjectUtil.isNull(retroactiveNow.getBatchNo())) {
+            return 0;
         }
-        LoginUser loginUser = SecurityUtils.getLoginUser();
-        baseData.setStatus(retroactiveNow.getStatus());
-        baseData.setDeviceId("PDA");
-        baseData.setUpdateBy(loginUser.getUsername());
-        baseData.setRemark("PDA手动补码");
-        if(Integer.parseInt(retroactiveNow.getStatus())>Integer.parseInt(baseData.getStatus())){
-            retroactiveNowMapper.updateById(baseData);
+        List<RetroactiveNow> retroactiveNows = retroactiveNowMapper.selectList(new LambdaQueryWrapper<RetroactiveNow>()
+                .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
+        );
+        if (retroactiveNows.isEmpty()) {
+            throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
         }
-        baseData.setCreateBy(loginUser.getUsername());
-        if (ObjectUtil.isNull(retroactiveNow.getCreateTime())){
-            throw new ServiceException("工序完成时间为空!");
+        retroactiveNows.get(0).setStatus(retroactiveNow.getStatus());
+        retroactiveNows.get(0).setDeviceId(retroactiveNow.getDeviceId());
+        retroactiveNows.get(0).setUpdateBy("system");
+        retroactiveNows.get(0).setUpdateTime(null);
+        retroactiveNows.get(0).setSanPanDevice(retroactiveNow.getSanPanDevice());
+        if (retroactiveNows.size() == 1 && StringUtils.isEmpty(retroactiveNows.get(0).getLotNo())) {
+            retroactiveNows.get(0).setLotNo(retroactiveNow.getLotNo());
+            retroactiveNowMapper.updateById(retroactiveNows.get(0));
+        } else {
+            retroactiveNows.get(0).setNowId(null);
+            retroactiveNows.get(0).setLotNo(retroactiveNow.getLotNo());
+            retroactiveNowMapper.insert(retroactiveNows.get(0));
         }
-        baseData.setCreateTime(retroactiveNow.getCreateTime());
-        RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
-        retroactiveHistory.setCreateTime(baseData.getUpdateTime());
+        RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNows.get(0), RetroactiveHistory.class);
+        retroactiveHistory.setCreateTime(new Date());
         retroactiveHistoryMapper.insert(retroactiveHistory);
-        return R.ok();
+
+        return 0;
     }
 
     private RetroactiveNow confirmTheDataByIndex(RetroactiveNow retroactiveNow) {
@@ -145,11 +252,34 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
         if (ObjectUtil.isNull(baseData)) {
             throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
         }
-        if (baseData.getStatus().equals(retroactiveNow.getStatus())) {
+        if (baseData.getStatus().equals(retroactiveNow.getStatus()) && !"5".equals(baseData.getStatus())) {
             throw new ServiceException("数据库存在该状态相同批次号或托盘号的数据");
         }
         return baseData;
     }
+
+    private void updateData(RetroactiveNow retroactiveNow, RetroactiveNow baseData) {
+        retroactiveNow.setNowId(baseData.getNowId());
+        retroactiveNow.setRetroactiveId(baseData.getRetroactiveId());
+        retroactiveNow.setUpdateBy(SecurityUtils.getUsername());
+        if (Integer.parseInt(retroactiveNow.getStatus()) >= Integer.parseInt(baseData.getStatus())) {
+            retroactiveNowMapper.updateById(retroactiveNow);
+            if (ObjectUtil.isNull(retroactiveNow.getUpdateTime())) {
+                throw new ServiceException("工序完成时间为空!");
+            }
+            baseData = retroactiveNowMapper.selectById(baseData.getNowId());
+            baseData.setCreateBy(SecurityUtils.getUsername());
+            baseData.setCreateTime(retroactiveNow.getUpdateTime());
+            RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
+            retroactiveHistory.setCreateTime(baseData.getUpdateTime());
+            retroactiveHistoryMapper.insert(retroactiveHistory);
+        } else {
+            RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(retroactiveNow, RetroactiveHistory.class);
+            retroactiveHistory.setCreateTime(baseData.getUpdateTime());
+            retroactiveNow.setRemark("PDA手动补码");
+            retroactiveHistoryMapper.insert(retroactiveHistory);
+        }
+    }
 }
 
 

+ 4 - 2
warewms-system/src/main/java/com/warewms/hailiang/util/ParseMsgTools.java

@@ -44,6 +44,7 @@ public class ParseMsgTools {
     }
 
     public static void main(String[] args) throws UnsupportedEncodingException {
+//        System.out.println(StringTohexString("$0800"));
 //        String str = "23";
 //        StringBuffer sb = new StringBuffer();
 //        //将字符串转换为字符数组
@@ -67,10 +68,11 @@ public class ParseMsgTools {
 //        }
 //        System.out.println(Integer.toHexString(i));
 
-        System.out.println(Integer.parseInt("30",16));
+//        System.out.println(Integer.parseInt("400",16));
 //        System.out.println(Arrays.toString(hexString2Bytes("8000")));
 
-//        System.out.println(Integer.parseInt("E8",16));
+
+        System.out.println(Integer.parseInt("6E",16));
 //        for (int i = 1; i < bytes.length -1; i++) {
 //            y = y ^ bytes[i + 1];
 //            System.out.println(y);

+ 2 - 1
warewms-system/src/main/java/com/warewms/system/controller/monitor/CacheController.java

@@ -14,7 +14,7 @@ import java.util.*;
 
 /**
  * 缓存监控
- * 
+ *
  * @author ruoyi
  */
 @RestController
@@ -33,6 +33,7 @@ public class CacheController
         caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
         caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
         caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
+        caches.add(new SysCache(CacheConstants.BATCH_NO, "喷码机批次号"));
     }
 
     @PreAuthorize("@ss.hasPermi('monitor:cache:list')")

+ 8 - 0
warewms-system/src/main/resources/mapper/hailiang/RetroactiveHistoryMapper.xml

@@ -26,4 +26,12 @@
         device_id,create_by,create_time,
         update_by,update_time,remark
     </sql>
+    <select id="getDelList" resultType="com.warewms.hailiang.domain.RetroactiveHistory">
+        SELECT T1.*
+        FROM (
+                 SELECT *, ROW_NUMBER() OVER(PARTITION BY batch_no ORDER BY create_time desc) AS rn
+                 FROM retroactive_history where del_flag ='1'
+             ) T1
+        WHERE T1.rn = 1;
+    </select>
 </mapper>