From f6e955d57bf5e885afde54a8c6eefe80bc1bec26 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期四, 30 十一月 2023 17:00:06 +0800
Subject: [PATCH] #出入库任务下发

---
 src/main/java/com/zy/core/thread/SiemensCrnThread.java |  136 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 118 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index f3d986c..9761ec6 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * 鍫嗗灈鏈虹嚎绋�
@@ -76,7 +77,7 @@
                         break;
                     // 鍐欏叆鏁版嵁
                     case 2:
-                        write((CrnCommand) task.getData());
+                        write2((CrnCommand) task.getData());
                         break;
                     // 澶嶄綅
                     case 3:
@@ -411,6 +412,93 @@
 //        }else if (rowFour.contains(command.getSourcePosX())){
 //            array[4] = (short)4;
 //        }else {
+        array[4] = command.getSourcePosX();
+//        }
+        array[5] = command.getSourcePosY();
+
+        array[6] = command.getDestinationPosZ();
+//        if (rowOne.contains(command.getDestinationPosX())){
+//            array[7] = (short)1;
+//        }else if (rowTwo.contains(command.getDestinationPosX())){
+//            array[7] = (short)2;
+//        }else if (rowThree.contains(command.getDestinationPosX())){
+//            array[7] = (short)3;
+//        }else if (rowFour.contains(command.getDestinationPosX())){
+//            array[7] = (short)4;
+//        }else {
+        array[7] = command.getDestinationPosX();
+//        }
+        array[8] = command.getDestinationPosY();
+        array[9] = command.getCommand();
+
+        // 浣滀笟淇℃伅
+        OperateResult result = siemensNet.Write("DB100.0", array);
+
+        if (command.getAckFinish() != 1) {
+            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
+            BasCrnOpt basCrnOpt = new BasCrnOpt(
+                    command.getTaskNo().intValue(),    // 浠诲姟鍙�
+                    command.getCrnNo(),    // 鍫嗗灈鏈篬闈炵┖]
+                    new Date(),    // 涓嬪彂鏃堕棿
+                    command.getTaskModeType() == null ? null : command.getTaskModeType().toString(),    // 妯″紡
+                    command.getSourcePosX().intValue(),    // 婧愭帓
+                    command.getSourcePosY().intValue(),    // 婧愬垪
+                    command.getSourcePosZ().intValue(),    // 婧愬眰
+                    null,    // 婧愮珯
+                    command.getDestinationPosX().intValue(),    // 鐩爣鎺�
+                    command.getDestinationPosY().intValue(),    // 鐩爣鍒�
+                    command.getDestinationPosZ().intValue(),    // 鐩爣灞�
+                    null,    // 鐩爣绔�
+                    null,    // 鍝嶅簲缁撴灉
+                    null,    // 淇敼鏃堕棿
+                    null    // 淇敼浜哄憳
+            );
+            bean.insert(basCrnOpt);
+        }
+
+        if (result.IsSuccess) {
+            log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
+            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+            return true;
+        } else {
+            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
+            log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+            return false;
+        }
+    }
+
+    /**
+     * 鍐欏叆鏁版嵁
+     */
+    private boolean write2(CrnCommand command){
+        if (null == command) {
+            log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+            return false;
+        }
+        if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) {
+            command.setTaskNo((short) 9999);
+        }
+
+        command.setCrnNo(slave.getId());
+        short[] array = new short[10];
+        if (Cools.isEmpty(command.getAckFinish())) {
+            array[0] = 5;
+        } else {
+            array[0] = command.getAckFinish();
+        }
+        array[1] = command.getTaskNo();
+        array[2] = command.getTaskMode();
+
+        array[3] = command.getSourcePosZ();
+//        if (rowOne.contains(command.getSourcePosX())){
+//            array[4] = (short)1;
+//        }else if (rowTwo.contains(command.getSourcePosX())){
+//            array[4] = (short)2;
+//        }else if (rowThree.contains(command.getSourcePosX())){
+//            array[4] = (short)3;
+//        }else if (rowFour.contains(command.getSourcePosX())){
+//            array[4] = (short)4;
+//        }else {
             array[4] = command.getSourcePosX();
 //        }
         array[5] = command.getSourcePosY();
@@ -453,7 +541,7 @@
                         command.getTaskNo().intValue(),    // 浠诲姟鍙�
                         command.getCrnNo(),    // 鍫嗗灈鏈篬闈炵┖]
                         new Date(),    // 涓嬪彂鏃堕棿
-                        command.getTaskModeType().toString(),    // 妯″紡
+                        command.getTaskModeType() == null ? null : command.getTaskModeType().toString(),    // 妯″紡
                         command.getSourcePosX().intValue(),    // 婧愭帓
                         command.getSourcePosY().intValue(),    // 婧愬垪
                         command.getSourcePosZ().intValue(),    // 婧愬眰
@@ -474,32 +562,44 @@
         CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
         CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
         CommandInfo commandInfo = commandInfoService.selectById(command.getCommandId());
-        CommandInfoLog commandInfoLog = new CommandInfoLog();
-        if (commandInfo != null) {
-            commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
-            commandInfoLog.setId(null);
-        }else {
-            Date now = new Date();
-            commandInfoLog.setCommand(JSON.toJSONString(command));
-            commandInfoLog.setCommandStatus(3);
-            commandInfoLog.setStartTime(now);
-            commandInfoLog.setExecuteTime(now);
-            commandInfoLog.setCompleteTime(now);
-            commandInfoLog.setDevice(SlaveType.Devp.toString());
-            commandInfoLog.setWrkNo(9999);
-            commandInfoLog.setTaskNo("9999");
-            commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护");
-        }
+        CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
+        commandInfoLog.setId(null);
+//        CommandInfoLog commandInfoLog = new CommandInfoLog();
+//        if (commandInfo != null) {
+//            commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
+//            commandInfoLog.setId(null);
+//        }else {
+//            Date now = new Date();
+//            commandInfoLog.setCommand(JSON.toJSONString(command));
+//            commandInfoLog.setCommandStatus(3);
+//            commandInfoLog.setStartTime(now);
+//            commandInfoLog.setExecuteTime(now);
+//            commandInfoLog.setCompleteTime(now);
+//            commandInfoLog.setDevice(SlaveType.Devp.toString());
+//            commandInfoLog.setWrkNo(9999);
+//            commandInfoLog.setTaskNo("9999");
+//            commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护");
+//        }
 
 
         if (result.IsSuccess) {
             log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
 
+            Date now = new Date();
+
             //鏇存柊鎸囦护鏃ュ織
             commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛");
             commandInfoLogService.insert(commandInfoLog);
 
+            //绾跨▼鏆傚瓨鎸囦护ID
+            crnProtocol.setCommandId(command.getCommandId());
+
+            //鏇存柊鎸囦护鐘舵��
+            commandInfo.setCommandStatus(CommandStatusType.EXECUTE.id);//鎵ц涓�
+            commandInfo.setExecuteTime(now);
+            commandInfoService.updateById(commandInfo);
+
             //鏇存柊浠诲姟姝ュ簭
             TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
             TaskWrk taskWrk = taskWrkService.selectByWrkNo(command.getTaskNo().intValue());

--
Gitblit v1.9.1