From cf9fac40a8e39b25ee935a743224ae6c405bbddc Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期一, 24 三月 2025 19:33:39 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/jxjdzwcs' into jxjdzwcs

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  127 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index d8ab81a..5680365 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -39,15 +39,18 @@
 import com.zy.core.thread.SiemensDevpThread;
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
+import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * 绔嬩綋浠撳簱WCS绯荤粺涓绘祦绋嬩笟鍔�
@@ -94,7 +97,10 @@
     private ApiLogService apiLogService;
     @Autowired
     private CommonService commonService;
-
+    @Value("${wms.count}")
+    private Integer maxCount;
+    @Autowired
+    private WrkMastService wrkMastService;
     @Value("${wms.url}")
     private String wmsUrl;
     @Value("${wms.inboundTaskApplyPath}")
@@ -107,6 +113,118 @@
     private CrnController crnController;
     @Autowired
     private SiteController siteController;
+    //鍑哄簱绔欑偣鑷�112寰幆绔欑偣
+    @Synchronized
+    public void shiftTargetToCyclePoint() throws IOException, InterruptedException{
+        try{
+            for (DevpSlave devp : slaveProperties.getDevp()) {
+                for (DevpSlave.Sta outSta : devp.getOutSta()) {
+                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                    StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
+                    StaProtocol staProtocol1 = devpThread.getStation().get(1001);
+                    StaProtocol staProtocol2 = devpThread.getStation().get(1002);
+                    StaProtocol staProtocol3 = devpThread.getStation().get(1003);
+                    StaProtocol staProtocol4 = devpThread.getStation().get(1004);
+                    StaProtocol staProtocol6 = devpThread.getStation().get(111);
+                    if (staProtocol == null) {
+                        continue;
+                    } else {
+                        staProtocol = staProtocol.clone();
+                    }
+                    if (staProtocol1 == null) {
+                        continue;
+                    } else {
+                        staProtocol1 = staProtocol1.clone();
+                    }
+                    if (staProtocol2 == null) {
+                        continue;
+                    } else {
+                        staProtocol2 = staProtocol2.clone();
+                    }
+                    if (staProtocol3 == null) {
+                        continue;
+                    } else {
+                        staProtocol3 = staProtocol3.clone();
+                    }
+                    if (staProtocol4 == null) {
+                        continue;
+                    } else {
+                        staProtocol4 = staProtocol4.clone();
+                    }
+                    if (staProtocol6 == null) {
+                        continue;
+                    } else {
+                        staProtocol6 = staProtocol6.clone();
+                    }
+                    boolean result = false;
+                    switch(outSta.getStaNo()){
+                        case 105: if (staProtocol1.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 105){
+                            result = true;
+                        }
+                        case 107: if (staProtocol2.isLoading()){
+                            result = true;
+                        }
+                        case 109: if (staProtocol3.isLoading()){
+                            result = true;
+                        }
+                        case 110: if ((staProtocol4.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 110) || ((staProtocol6.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 111))){
+                            result = true;
+                        }
+                        default: break;
+
+                    }
+                    if(result){
+                        if(staProtocol.getSiteId() == 107 || staProtocol.getSiteId() == 109){
+                            StaProtocol staProtocol5 = devpThread.getStation().get(staProtocol.getSiteId() - 1);
+                            if (staProtocol5== null) {
+                                continue;
+                            } else {
+                                staProtocol5 = staProtocol5.clone();
+                            }
+                            if((staProtocol5.isLoading() && staProtocol5.getStaNo() == 107) || ((staProtocol5.isLoading() && staProtocol5.getStaNo() == 109))){
+                                staProtocol5.setStaNo((short) 112);
+                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol5));
+                            }
+                        }else{
+                            staProtocol.setStaNo((short) 112);
+                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                        }
+                    }
+                }
+            }
+        }catch (Exception e) {
+            log.error("generateStoreWrkFile e", e);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+    }
+
+    //112寰幆绔欑偣鑷冲嚭搴撶珯
+    public synchronized void shiftCyclePointToTarget() throws IOException, InterruptedException{
+        try{
+            for (DevpSlave devp : slaveProperties.getDevp()) {
+                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                StaProtocol staProtocol = devpThread.getStation().get(112);
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+                if(staProtocol.getWorkNo() == 0){
+                    continue;
+                }
+                TaskWrk taskWrk = taskWrkMapper.selectStaWorking(Integer.valueOf(staProtocol.getWorkNo()));
+                if(taskWrk != null &&  taskWrk.getWrkNo() < 9001 && taskWrk.getWrkNo() > 6000){
+                    staProtocol.setStaNo(Short.valueOf(taskWrk.getTargetPoint()));
+                    MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                }
+            }
+        }catch (Exception e) {
+            log.error("generateStoreWrkFile e", e);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+    }
+
+
 
 
     public synchronized void generateStoreWrkFile1() throws IOException, InterruptedException {
@@ -722,6 +840,7 @@
                     continue;
                 }
 
+
                 // 鑾峰彇宸ヤ綔鐘舵�佷负2锛堣澶囦笂璧帮級鐨勫叆搴撳伐浣滄。
                 TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString());
                 if (null == taskWrk) {
@@ -847,6 +966,12 @@
                         if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                             break;
                         }
+                        int storeCount = taskWrkService.getStoreCount(taskWrk.getCrnNo());
+                        if(storeCount >= maxCount){
+                            log.error("{}鍙峰爢鍨涙満鏆傚瓨鏁板凡婊�!", taskWrk.getCrnNo());
+                            break;
+                        }
+
 
                         // 宸茬粡瀛樺湪鍚婅溅鎵ц浠诲姟鏃讹紝鍒欒繃婊�
                         if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {

--
Gitblit v1.9.1