From b5768fb9a6bf4216aba11d7f784e8cefc8fdaf9b Mon Sep 17 00:00:00 2001
From: zyx <zyx123456>
Date: 星期三, 27 三月 2024 14:54:48 +0800
Subject: [PATCH] 定时任务完成

---
 src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java |  138 +++++++++++++++++++++++++++-------------------
 1 files changed, 81 insertions(+), 57 deletions(-)

diff --git a/src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java b/src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
index a616b3d..94cae13 100644
--- a/src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
@@ -11,37 +11,45 @@
 import com.zy.asrs.service.*;
 import com.zy.asrs.task.AbstractHandler;
 import com.zy.asrs.task.core.ReturnT;
+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.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
 public class AgvWrkMastHandler extends AbstractHandler<String> {
 
+    @Value("${agvBasDev.maxWorkNum}")
+    private int maxWrokNum;
+
     @Autowired
-    AgvWrkMastService agvWrkMastService;
+    private AgvWrkMastService agvWrkMastService;
     @Autowired
-    AgvLocMastService agvLocMastService;
+    private AgvLocMastService agvLocMastService;
     @Autowired
-    AgvLocDetlService agvLocDetlService;
+    private AgvLocDetlService agvLocDetlService;
     @Autowired
-    AgvWrkMastLogService agvWrkMastLogService;
+    private AgvWrkMastLogService agvWrkMastLogService;
     @Autowired
-    AgvWrkDetlService agvWrkDetlService;
+    private AgvWrkDetlService agvWrkDetlService;
     @Autowired
-    AgvWrkDetlLogService agvWrkDetlLogService;
+    private AgvWrkDetlLogService agvWrkDetlLogService;
     @Autowired
-    AgvWaitPakinService agvWaitPakinService;
+    private AgvWaitPakinService agvWaitPakinService;
     @Autowired
-    AgvWaitPakinLogService agvWaitPakinLogService;
+    private AgvWaitPakinLogService agvWaitPakinLogService;
     @Autowired
-    OrderService orderService;
+    private OrderService orderService;
+    @Autowired
+    private AgvBasDevpService agvBasDevpService;
 
     @Transactional
     public ReturnT<String> completedPutWayWrk(AgvWrkMast agvWrkMast) {
@@ -52,13 +60,9 @@
         //淇敼宸ヤ綔妗g姸鎬佷负207.搴撳瓨鏇存柊瀹屾垚
         agvWrkMast.setWrkSts(207L);
         agvWrkMastService.updateById(agvWrkMast);
-        if(agvWrkMast.getIoType() == 10){
-            // 绌烘澘鍏ュ簱 璁剧疆搴撲綅鐘舵�佷负D.绌烘《/绌烘爤鏉�
-            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"D");
-        }else{
-            //淇敼鐩爣搴撲綅鐘舵�佷负F.鍦ㄥ簱
-            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"F");
-        }
+        // 绌烘澘鍏ュ簱 璁剧疆搴撲綅鐘舵�佷负D.绌烘《/绌烘爤鏉�
+        String locSts = agvWrkMast.getIoType() == 10 ? "D" : "F";
+        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),locSts,agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
         //鐢熸垚AGV宸ヤ綔鍘嗗彶妗�
         agvWrkMastLogService.save(agvWrkMast);
         //鐢熸垚AGV宸ヤ綔鏄庣粏鍘嗗彶妗�
@@ -79,7 +83,7 @@
             //鏇存柊搴撳瓨鏄庣粏
             agvLocDetlService.updateStock(agvWrkMast.getSourceLocNo(),agvWrkMast.getLocNo());
             //淇敼婧愬簱浣嶇姸鎬佷负O
-            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O");
+            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",null);
         }
 
         //鍒犻櫎AGV宸ヤ綔妗�
@@ -110,7 +114,7 @@
         agvWrkMast.setWrkSts(207L);
         agvWrkMastService.updateById(agvWrkMast);
         //淇敼婧愬簱浣嶇姸鎬佷负O
-        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O");
+        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",null);
         if(agvWrkMast.getIoType() == 101){
             //鏇存柊鐩爣搴撲綅鏄庣粏 101.鍑哄簱 鍒犻櫎婧愬簱浣嶅簱瀛樻槑缁�
             agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no",agvWrkMast.getSourceLocNo()));
@@ -138,58 +142,65 @@
     }
 
     @Transactional
-    public ReturnT<String> startPutWayWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
+    public ReturnT<String> startPutWayWrk(AgvWrkMast agvWrkMast) throws IOException {
 
         //涓嬪彂浠诲姟
-        int startWrkCode = agvWrkMastService.startWrk(agvWrkMastList,"putaway");
+        int startWrkCode = agvWrkMastService.startWrk(agvWrkMast);
         if(startWrkCode != 0){
             throw new CoolException("浠诲姟涓嬪彂澶辫触");
         }
 
-        //涓嬪彂瀹瑰櫒鍏ュ満鎸囦护 锛堢紦瀛樿揣鏋讹級
-        int code = agvWrkMastService.containerMoveIn(agvWrkMastList);
-
-        if(code == 0){
-            for(AgvWrkMast agvWrkMast : agvWrkMastList){
-                //涓嬪彂瀹瑰櫒杈惧埌閫氱煡 锛堣緭閫佺嚎锛�
-                if("Y".equals(agvWrkMast.getMk())){
-                    int containerArrivedCode = agvWrkMastService.containerArrived(agvWrkMast);
-                    if(containerArrivedCode != 0){
-                        log.error("瀹瑰櫒鍒拌揪鎸囦护涓嬪彂澶辫触");
-                        continue;
-                    }
-                }
-
-                //202.RCS鍙栬揣涓�
-                agvWrkMast.setWrkSts(202L);
-                agvWrkMastService.updateById(agvWrkMast);
-                if(agvWrkMast.getIoType() == 1){
-                    //淇敼AGV鍏ュ簱閫氱煡妗g姸鎬佸叆鍑虹姸鎬佷负Y
-                    agvWaitPakinService.updateIoStatus(agvWrkMast.getWrkNo(),"Y");
-                }
-            }
-
-            return SUCCESS;
+        agvWrkMast.setWrkSts(202L);
+        agvWrkMastService.updateById(agvWrkMast);
+        if(agvWrkMast.getIoType() == 1){
+            //淇敼AGV鍏ュ簱閫氱煡妗g姸鎬佸叆鍑虹姸鎬佷负Y
+            agvWaitPakinService.updateIoStatus(agvWrkMast.getWrkNo(),"Y");
         }
+        return SUCCESS;
 
-        return FAIL;
     }
 
+//    @Transactional
+//    public ReturnT<String> startCarryWrk(AgvWrkMast agvWrkMast) throws IOException {
+//        //log.info(agvWrkMastList.toString());
+//        //浠诲姟杩囨护锛岃繃婊ゆ帀宸插瓨鍦ㄧ浉鍚岀洰鏍囧簱浣嶇殑宸ヤ綔妗�
+//        //agvWrkMastList = filter(agvWrkMastList);
+//        int code = agvWrkMastService.startWrk(agvWrkMast);
+//        //log.info(agvWrkMastList.toString());
+//        if (Cools.isEmpty(agvWrkMastList)){
+//            return SUCCESS;
+//        }
+//        if(code == 0){
+//            agvWrkMastList.forEach(agvWrkMast -> {
+//                //202.RCS鍙栬揣涓�
+//                agvWrkMast.setWrkSts(202L);
+//                agvWrkMastService.updateById(agvWrkMast);
+//            });
+//            //agvWrkMastService.updateBatchById(agvWrkMastList);
+//
+//            return SUCCESS;
+//        }
+//
+//        return FAIL;
+//    }
+
+    @Synchronized
     @Transactional
-    public ReturnT<String> startCarryWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
-        int code = agvWrkMastService.startWrk(agvWrkMastList,"carry");
-        if(code == 0){
-            agvWrkMastList.forEach(agvWrkMast -> {
-                //202.RCS鍙栬揣涓�
-                agvWrkMast.setWrkSts(202L);
+    public ReturnT<String> dealWatiWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
+
+        agvWrkMastList.forEach(agvWrkMast -> {
+            //鏌ヨ璇ョ珯鐐规墍鏈夋殏瀛樹綅鍦ㄥ伐浣滄。涓嚭鐜扮殑娆℃暟
+            List<Map<String, Object>> devNoMaps = agvBasDevpService.selectDevNoAndNumBystationCode(agvWrkMast.getLocNo());
+            //鍙栫涓�涓殏瀛樹綅锛屽苟鏌ヨ鍏舵鏁颁笌閰嶇疆鐨勬鏁板仛姣旇緝
+            Map<String, Object> devNoMap = devNoMaps.get(0);
+            if((int)devNoMap.get("num") < maxWrokNum){
+                agvWrkMast.setLocNo(devNoMap.get("dev_no").toString());
                 agvWrkMastService.updateById(agvWrkMast);
-            });
-            //agvWrkMastService.updateBatchById(agvWrkMastList);
+                log.info("after锛�" + devNoMap.toString()  +  ", wrkNo:" + agvWrkMast.getWrkNo() + ", locNo: " + agvWrkMast.getLocNo());
+            }
+        });
 
-            return SUCCESS;
-        }
-
-        return FAIL;
+        return SUCCESS;
     }
 
     private String getOrderNoByWrkNo(int wrkNo){
@@ -214,4 +225,17 @@
             }
         }
     }
+
+    private List<AgvWrkMast> filter(List<AgvWrkMast> agvWrkMastList){
+        return agvWrkMastList.stream().filter(agvWrkMast -> {
+            AgvWrkMast agvWrkMastWroking = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("source_loc_no", agvWrkMast.getLocNo()));
+            if(!Cools.isEmpty(agvWrkMastWroking) && agvWrkMastWroking.getWrkSts()<=202){
+                System.out.println("source_loc_no > 1");
+                return false;
+            }
+            log.info(agvWrkMast.toString());
+            int num = agvWrkMastService.selectCount(new EntityWrapper<AgvWrkMast>().eq("loc_no", agvWrkMast.getLocNo()));
+            return num <= maxWrokNum;
+        }).collect(Collectors.toList());
+    }
 }

--
Gitblit v1.9.1