From e1554a9250bed6038ac754786f11b58c68fe0458 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期五, 24 十一月 2023 18:01:10 +0800
Subject: [PATCH] #堆垛机出入库

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |   74 ++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 2ec4a9a..1c4f054 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -9,13 +9,12 @@
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
+import com.zy.asrs.domain.enums.TaskStatusType;
 import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.entity.CommandInfo;
+import com.zy.asrs.entity.CommandInfoLog;
 import com.zy.asrs.entity.TaskWrk;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.asrs.service.CommandInfoService;
-import com.zy.asrs.service.DeviceErrorService;
-import com.zy.asrs.service.TaskWrkService;
+import com.zy.asrs.service.*;
 import com.zy.core.DevpThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
@@ -247,23 +246,23 @@
 //
 //            }
 
-        //RGV鍙拌溅浣嶇疆
-        Thread.sleep(200);
-        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.0",(short)4);
-        if (result3.IsSuccess) {
-            for (int i = 0; i < 2; i++) {
-                Integer siteId = i==0 ? 112 : 212; // 绔欑偣缂栧彿
-                StaProtocol staProtocol = station.get(siteId);
-                if (null == staProtocol) {
-                    staProtocol = new StaProtocol();
-                    staProtocol.setSiteId(siteId);
-                    station.put(siteId, staProtocol);
-                }
-                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2)));
-//                String aa = staProtocol.getNearbySta();
-//                System.out.println(siteId + "===>>" + staProtocol.getNearbySta());
-            }
-        }
+//        //RGV鍙拌溅浣嶇疆
+//        Thread.sleep(200);
+//        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.0",(short)4);
+//        if (result3.IsSuccess) {
+//            for (int i = 0; i < 2; i++) {
+//                Integer siteId = i==0 ? 1 : 2; // 绔欑偣缂栧彿
+//                StaProtocol staProtocol = station.get(siteId);
+//                if (null == staProtocol) {
+//                    staProtocol = new StaProtocol();
+//                    staProtocol.setSiteId(siteId);
+//                    station.put(siteId, staProtocol);
+//                }
+//                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2)));
+////                String aa = staProtocol.getNearbySta();
+////                System.out.println(siteId + "===>>" + staProtocol.getNearbySta());
+//            }
+//        }
 
 //        OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0");
 //        if (result2.IsSuccess) {
@@ -317,6 +316,27 @@
         array[1] = staProtocol.getStaNo();
 //        OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
 
+        //鏇存柊鍛戒护鏃ュ織
+        CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
+        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
+        CommandInfo commandInfo = commandInfoService.selectById(staProtocol.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(staProtocol));
+            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("鎵嬪姩鍛戒护");
+        }
+
         OperateResult writeResult;
         //浠诲姟涓嬪彂娆℃暟
         int writeCount = 0;
@@ -324,6 +344,10 @@
         boolean writeFlag = false;
         while(writeCount < 5){
             writeResult = siemensS7Net.Write("DB100." + index*4, array);    // 宸ヤ綔鍙枫�佺洰鏍囩珯
+            //鏇存柊鎸囦护鏃ュ織
+            commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛");
+            commandInfoLogService.insert(commandInfoLog);
+
             if(writeResult.IsSuccess){
                 Thread.sleep(200);
                 OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index*4, (short)4);
@@ -346,12 +370,20 @@
                     OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
                             slave.getId(), JSON.toJSON(staProtocol), writeCount));
                     log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
+
+                    //鏇存柊鎸囦护鏃ュ織
+                    commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触");
+                    commandInfoLogService.insert(commandInfoLog);
                 }
             } else {
                 writeCount++;
                 OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
                         slave.getId(), JSON.toJSON(staProtocol),writeCount));
                 log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
+
+                //鏇存柊鎸囦护鏃ュ織
+                commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触");
+                commandInfoLogService.insert(commandInfoLog);
             }
             Thread.sleep(200);
         }

--
Gitblit v1.9.1