From 1a8e7f30035b45771d05cd4cc99aae2743576112 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期五, 17 五月 2024 00:16:46 +0800
Subject: [PATCH] # 手动调拨

---
 src/main/java/com/zy/common/web/WcsController.java |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 154 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/zy/common/web/WcsController.java b/src/main/java/com/zy/common/web/WcsController.java
index d0bb461..e820586 100644
--- a/src/main/java/com/zy/common/web/WcsController.java
+++ b/src/main/java/com/zy/common/web/WcsController.java
@@ -8,8 +8,8 @@
 import com.zy.asrs.entity.*;
 import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.*;
-import com.zy.asrs.utils.Utils;
 import com.zy.common.CodeRes;
+import com.zy.common.model.AgvBasDevpDto;
 import com.zy.common.model.LocTypeDto;
 import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
@@ -23,6 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -33,6 +34,8 @@
 @RestController
 @RequestMapping("/rpc")
 public class WcsController {
+
+    private static HashMap<String,String> currentContainerMap;
 
     @Autowired
     private WrkMastService wrkMastService;
@@ -62,6 +65,10 @@
     private WrkMastMapper wrkMastMapper;
     @Autowired
     private WrkMastLogService wrkMastLogService;
+    @Autowired
+    private AgvWrkDetlService agvWrkDetlService;
+    @Autowired
+    private AgvLocDetlService agvLocDetlService;
 //    @Autowired
 //    private ErpService erpService;
 
@@ -497,6 +504,12 @@
             }
         }
 
+        //妫�鏌ョ洰鏍囧簱浣嶏紝搴撳瓨鏄庣粏鏄惁娣诲姞鎴愬姛
+        List<LocDetl> checkLocDetls = locDetlService.selectByLocNo(dto.getLocNo());
+        if (checkLocDetls.isEmpty()) {
+            throw new CoolException("搴撳瓨鏄庣粏杩佺Щ澶辫触");
+        }
+
 //        //娓呯┖婧愬簱浣嶆暟鎹�
         LocMast locMast1 = locMastService.selectByLoc(wrkMast.getSourceLocNo());
 //        if (locMast1.getLocSts().equals("P")) {
@@ -577,24 +590,154 @@
         if(Cools.isEmpty(agvBasDevp) || !"O".equals(agvBasDevp.getLocSts())){
             throw new CoolException("褰撳墠绔欑偣涓嶅瓨鍦ㄦ垨鑰呯珯鐐逛笉涓虹┖");
         }
-        if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){
-            throw new CoolException("璇ユ枡绠变綅缁勬墭");
+        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", containerCode));
+
+        //鎷f枡銆佺洏鐐瑰畬鎴愪换鍔�
+        if(!Cools.isEmpty(agvWrkMast) && (agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107) && agvWrkMast.getWrkSts() == 205){
+            //缁戝畾绔欑偣
+            agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue());
+
+            //鐢熸垚鎷f枡銆佺洏鐐瑰啀鍏ュ簱浠诲姟
+            List<AgvWrkMast> agvWrkMastList = new ArrayList<>();
+            agvWrkMast.setMk("Y");
+            agvWrkMast.setLocNo(agvBasDevp.getDevNo());
+            agvWrkMastList.add(agvWrkMast);
+            agvWorkService.pickIn(agvWrkMastList);
+
+            return R.ok();
         }
 
-        //鍘绘壘agv宸ヤ綔妗d换鍔�
-        if(!Cools.isEmpty(agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode",containerCode)))){
-            throw new CoolException("璇ユ枡绠辨鍦ㄥ叆搴撲腑");
+        //鍏ュ簱浠诲姟
+        if (!Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){
+            //缁戝畾绔欑偣
+            agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue());
+            //鐢熸垚宸ヤ綔妗�
+            List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo()));
+            agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true);
+
+            return R.ok();
         }
-        //缁戝畾绔欑偣
-        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode);
 
-        //鐢熸垚宸ヤ綔妗�
-        List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo()));
-        agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true);
+        return R.error("娌℃湁鏌ヨ鍒拌鏂欑淇℃伅");
 
+    }
+
+    @PostMapping("/current/containerCode")
+    @ResponseBody
+    public R move(@RequestBody ReplenishmentParam param){
+
+        if(Cools.isEmpty(currentContainerMap)){
+            currentContainerMap = new HashMap<>();
+        }
+
+        String containerCode = param.getContainerCode().split(";")[0];
+
+        if(Cools.isEmpty(containerCode)){
+            throw new CoolException("鏂欑鐮佷负绌�");
+        }
+
+        if(!Character.isDigit(containerCode.charAt(0))){
+            containerCode = containerCode.substring(3,containerCode.length());
+        }
+
+
+        String devNo = param.getDevNo();
+        String currentContainerCode = currentContainerMap.get(devNo);
+
+        //鍒ゆ柇瀹瑰櫒鏄惁鍙戠敓鍙樺寲
+        if(!Cools.isEmpty(currentContainerCode) && !Cools.eq(containerCode,currentContainerCode)){
+            //鏌ヨ鏃у鍣ㄧ殑宸ヤ綔妗�
+            AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(currentContainerCode);
+            if(!Cools.isEmpty(agvWrkMast) && agvWrkMast.getIoType() == 101){
+                //灏嗗伐浣滃厷鐘舵�佹敼涓哄鍣ㄧ鍦�
+                agvWrkMast.setWrkSts(206L);
+                agvWrkMastService.updateById(agvWrkMast);
+//                //鍙戦�佸鍣ㄧ珛鍦鸿姹傦紝瀹屾垚宸ヤ綔妗�
+//                List<AgvWrkMast> agvWrkMastList = new ArrayList<>();
+//                agvWrkMastList.add(agvWrkMast);
+//                try {
+//                    int code = agvWrkMastService.containerMoveOut(agvWrkMastList);
+//                    if(code == 0){
+//                        //灏嗗伐浣滃厷鐘舵�佹敼涓哄鍣ㄧ鍦�
+//                        agvWrkMast.setWrkSts(206L);
+//                        agvWrkMastService.updateById(agvWrkMast);
+//                    }
+//                } catch (IOException e) {
+//                    log.error(e.getMessage());
+//                }
+            }
+        }
+
+        currentContainerMap.put(devNo,containerCode);
 
         return R.ok();
     }
 
+    /*
+    鏄剧ずAGV杈撻�佺嚎鎷f枡銆佺洏鐐广�佸叆搴撲俊鎭�
+     */
+    @PostMapping("/info")
+    @ResponseBody
+    public R containerMove(@RequestBody ReplenishmentParam param){
+
+        String devNo = param.getDevNo();
+        String containerCode = currentContainerMap.get(devNo);
+
+        AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto();
+
+        //鏌ユ壘璇ュ鍣ㄧ殑宸ヤ綔妗�
+        AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(containerCode);
+        if(!Cools.isEmpty(agvWrkMast)){
+            List<AgvWrkDetl> agvWrkDetlList = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", agvWrkMast.getWrkNo()));
+
+            for (AgvWrkDetl agvWrkDetl : agvWrkDetlList){
+                agvWrkDetl.setVolume(agvWrkDetl.getAnfme());
+                if(agvWrkMast.getIoType() == 103){
+                    //瀵绘壘鏄惁鏈夌浉鍚岀墿鏂欑殑宸ヤ綔妗f槑缁嗭紝骞惰繑鍥炴暟閲忎箣鍜�
+                    double anfme = getAllAnfmeInAgvWrkDetlList(agvWrkDetlList,agvWrkDetl);
+                    AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getSourceLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime());
+                    //鐢ㄤ簬缁撲綑鏁伴噺鏄剧ず
+                    agvWrkDetl.setVolume(agvLocDetl.getAnfme() - anfme);
+                }
+                if(agvWrkMast.getIoType() == 53){
+                    AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime());
+                    if(Cools.isEmpty(agvLocDetl)){
+                        agvWrkDetl.setVolume(0.0);
+                    }else {
+                        agvWrkDetl.setVolume(agvLocDetl.getAnfme());
+                    }
+                }
+            };
+
+            agvBasDevpDto.setAgvWrkDetls(agvWrkDetlList);
+            agvBasDevpDto.setAgvWrkMast(agvWrkMast);
+        }
+        //鏌ユ壘璇ュ鍣ㄧ殑鍏ュ簱閫氱煡妗�
+        List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("supp_code", containerCode));
+        if(!Cools.isEmpty(agvWaitPakinList)){
+            agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList);
+        }
+
+        System.out.println("currentContainerMap: " + currentContainerMap);
+
+
+        System.out.println("agvBasDevpDto: " + agvBasDevpDto);
+
+        return R.ok(agvBasDevpDto);
+    }
+
+    private double getAllAnfmeInAgvWrkDetlList(List<AgvWrkDetl> agvWrkDetlList, AgvWrkDetl wd0) {
+        double allAnfme = 0;
+        for (AgvWrkDetl wd1 : agvWrkDetlList){
+            if(Cools.eq(wd0.getMatnr(),wd1.getMatnr())
+                    && Cools.eq(wd0.getBatch(),wd1.getBatch())
+                    && Cools.eq(wd0.getThreeCode(),wd1.getThreeCode())
+                    && Cools.eq(wd0.getDeadTime(),wd1.getDeadTime())){
+                allAnfme += wd1.getAnfme();
+            }
+        }
+        return allAnfme;
+    }
+
 
 }

--
Gitblit v1.9.1