From 2eecb1a7d658479ed7ac0990b6dbdddc91fe8480 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期二, 18 六月 2024 16:38:14 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java |   93 +++++++++++++++++++++++++++++-----------------
 1 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
index 1f91941..082eeb2 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
@@ -10,6 +10,7 @@
 import com.zy.asrs.framework.common.SpringUtils;
 import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.common.ExecuteSupport;
+import com.zy.asrs.wcs.core.domain.dto.BasLiftStaDto;
 import com.zy.asrs.wcs.core.entity.BasLift;
 import com.zy.asrs.wcs.core.model.command.LiftCommand;
 import com.zy.asrs.wcs.core.model.enums.LiftCommandModeType;
@@ -21,7 +22,6 @@
 import com.zy.asrs.wcs.rcs.entity.Device;
 import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
 import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
-import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
 import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
 import com.zy.asrs.wcs.rcs.thread.LiftThread;
@@ -29,7 +29,6 @@
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 @Slf4j
@@ -41,7 +40,7 @@
     private LiftProtocol liftProtocol;
     private SiemensS7Net siemensS7Net;
     private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>();
-    private List<Sta> staList = new ArrayList<>();
+    private List<BasLiftStaDto> staList = new ArrayList<>();
 
     public NyLiftThread(Device device, RedisUtil redisUtil) {
         this.device = device;
@@ -51,9 +50,9 @@
         BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
         BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>()
                 .eq(BasLift::getDeviceId, device.getId()));
-        List<Sta> staList = JSON.parseArray(basLift.getSta(), Sta.class);
+        List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class);
         this.staList = staList;
-        for (Sta sta : staList) {
+        for (BasLiftStaDto sta : staList) {
             LiftStaProtocol liftStaProtocol = new LiftStaProtocol();
             liftStaProtocol.setStaNo(sta.getStaNo());//绔欑偣鍙�
             liftStaProtocol.setLev(sta.getLev());//绔欑偣妤煎眰
@@ -142,7 +141,7 @@
                 liftProtocol.setLev((int) lev);
 
                 //************琛ュ厖鎵╁睍瀛楁*************
-                InnerLiftExtend liftExtend = JSON.parseObject(JSON.toJSONString(liftProtocol.getExtend()), InnerLiftExtend.class);
+                InnerLiftExtend liftExtend = (InnerLiftExtend) liftProtocol.getExtend();
                 //浠诲姟鍙�
                 liftExtend.setLiftTaskNo(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result1.Content, 2)));
                 liftProtocol.setExtend(liftExtend);
@@ -209,6 +208,31 @@
 
                 //鏇存柊閲囬泦鏃堕棿
                 liftProtocol.setDeviceDataLog(System.currentTimeMillis());
+            }
+
+            //灏嗘彁鍗囨満鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+            BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
+            BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>()
+                    .eq(BasLift::getLiftNo, device.getDeviceNo())
+                    .eq(BasLift::getHostId, device.getHostId()));
+            if (basLift == null) {
+                basLift = new BasLift();
+                //鎻愬崌鏈哄彿
+                basLift.setLiftNo(Integer.valueOf(device.getDeviceNo()));
+                basLift.setStatus(1);
+                basLift.setDeleted(0);
+                basLift.setHostId(device.getHostId());
+                basLift.setDeviceId(device.getId());
+                basLiftService.save(basLift);
+            }
+            //浠诲姟鍙�
+            basLift.setTaskNo(liftProtocol.getTaskNo().intValue());
+            //淇敼鏃堕棿
+            basLift.setUpdateTime(new Date());
+            //璁惧鐘舵��
+            basLift.setProtocol(JSON.toJSONString(liftProtocol));
+            if (basLiftService.updateById(basLift)) {
+                OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), device.getDeviceNo()));
             }
 
         } catch (Exception e) {
@@ -302,15 +326,35 @@
     }
 
     @Override
-    public LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
+    public synchronized boolean setProtocolStatus(LiftProtocolStatusType status) {
+        this.liftProtocol.setProtocolStatus(status);
+        return true;
+    }
+
+    @Override
+    public synchronized boolean setSyncTaskNo(Integer taskNo) {
+        this.liftProtocol.setTaskNo(taskNo);
+        return true;
+    }
+
+    @Override
+    public boolean isLock(ExecuteSupport support) {
+        if (support != null) {
+            return support.judgement();
+        }
+        return true;
+    }
+
+    @Override
+    public LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
         /**
          * 浠诲姟绫诲瀷
          * 1=绉绘墭鐩橈紱鍗囬檷鏈哄皢婧愮珯鍙版墭鐩樼Щ鍒扮洰鏍囩珯鍙�
          * 2=绉诲皬杞︼紝鍗囬檷鏈虹Щ鍒扮洰鏍囧眰锛岀瓑寰�
          */
         short taskMode = 2;
-        if (mode == null) {
-            taskMode = mode.shortValue();
+        if (mode.equals(LiftCommandModeType.PALLET_INOUT)) {
+            taskMode = 1;
         }
 
         // 寮�濮嬩换鍔�
@@ -334,25 +378,23 @@
     }
 
     @Override
-    public LiftCommand getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
-        return getMoveCommand(taskNo, sourceLev, targetLev, 2);
+    public LiftCommand getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
+        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
     }
 
     @Override
-    public LiftCommand getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, Integer mode) {
-        return getMoveCommand(taskNo, sourceLev, targetLev, 1);
+    public LiftCommand getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, LiftCommandModeType mode) {
+        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
     }
 
     @Override
     public LiftCommand getLockCommand(Integer taskNo, Boolean lock) {
-        LiftCommand command = new LiftCommand();
-        return command;
+        return null;
     }
 
     @Override
     public LiftCommand getShuttleSignalCommand(Integer taskNo, Boolean signal) {
-        LiftCommand command = new LiftCommand();
-        return command;
+        return null;
     }
 
     @Override
@@ -478,23 +520,6 @@
          * 鎻愬崌鏈哄彿
          */
         private Integer liftNo;
-
-    }
-
-    @Data
-    public static class Sta {
-
-        // 鎻愬崌鏈虹珯鐐瑰彿
-        private Integer staNo;
-
-        //杈撻�佺珯鐐规帓
-        private Integer row;
-
-        //杈撻�佺珯鐐瑰垪
-        private Integer bay;
-
-        // 灞�
-        private Integer lev;
 
     }
 

--
Gitblit v1.9.1