From bc20e7dc43b97367b7b70b678e71140a33846ff0 Mon Sep 17 00:00:00 2001
From: tzsk <Administrator@qq.com>
Date: 星期三, 30 七月 2025 22:36:49 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java |  283 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 181 insertions(+), 102 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java
index 0a5fcc4..92324ab 100644
--- a/src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java
@@ -15,9 +15,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 绉诲姩绔湇鍔℃牳蹇冪被
@@ -37,8 +36,15 @@
     private OrderDetlService orderDetlService;
     @Autowired
     private AgvBasDevpService agvBasDevpService;
+    @Autowired
+    private AgvLocDetlService agvLocDetlService;
+    @Autowired
+    private AgvWrkMastService agvWrkMastService;
 
 
+    /*
+    缁勬墭 + 缁戝畾鏆傚瓨浣�
+     */
     @Override
     @Transactional
     public String comb(CombParam param, Long userId) {
@@ -46,107 +52,164 @@
             throw new CoolException(BaseRes.PARAM);
         }
 
-        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().
-                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
-            throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
+        //妫�鏌ユ槸鍚﹀凡瀛樺湪鐩稿悓鐨勬墭鐩樻潯鐮侊紝瀛樺湪鍒欐姏鍑哄紓甯�
+        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) {
+            throw new CoolException(param.getBarcode() + "鏂欐兂鐮佸凡瀛樺湪AGV鍏ュ簱閫氱煡妗d腑");
         }
 
-        Date now = new Date();
-        //鏃犲崟缁勬墭
+        //妫�鏌ュ簱瀛樻槸鍚︽湁鐩稿悓鏂欑锛屽瓨鍦ㄥ垯鎶涘嚭寮傚父
+        if (!Cools.isEmpty(agvLocDetlService.selectOne(new EntityWrapper<AgvLocDetl>().eq("supp_code", param.getBarcode())))) {
+            throw new CoolException(param.getBarcode() + "鏂欑鐮佸凡瀛樺湪AGV搴撳瓨鏄庣粏涓�");
+        }
+
+        //鏌ョ湅宸ヤ綔妗f槸鍚︽湁鐩稿悓鏂欑锛屽瓨鍦ㄥ垯鎶涘嚭寮傚父
+        if (!Cools.isEmpty(agvWrkMastService.selectByContainerCode(param.getBarcode()))) {
+            throw new CoolException(param.getBarcode() + "鏂欑鐮佸凡瀛樺湪AGV宸ヤ綔妗d腑");
+        }
+        List<CombParam.CombMat> combMats = param.getCombMats();
+        Map<String, String> map = new HashMap<>();
+        for (CombParam.CombMat combMat : combMats) {
+            String batch = Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch();
+            if (!Cools.isEmpty(map.get(combMat.getMatnr() + batch))) {
+                throw new CoolException(param.getBarcode() + "缁勬墭鐨勭墿鏂欐槑缁嗛噸澶�,璇锋鏌ユ槸鍚﹂噸澶嶆壂鐮�");
+            } else {
+                map.put(combMat.getMatnr() + batch, combMat.getMatnr());
+            }
+        }
+
         if (Cools.isEmpty(param.getOrderNo())) {
-            List<DetlDto> detlDtos = new ArrayList<>();
-            param.getCombMats().forEach(elem -> {
-                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
-                if (DetlDto.has(detlDtos, detlDto)) {
-                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
-                    assert one != null;
-                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
-                } else {
-                    detlDtos.add(detlDto);
-                }
-            });
-
-            detlDtos.forEach(detlDto -> {
-                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-                if (Cools.isEmpty(mat)) {
-                    throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
-                }
-                AgvWaitPakin waitPakin = new AgvWaitPakin();
-                waitPakin.sync(mat);
-                waitPakin.setBatch(detlDto.getBatch());
-                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
-                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
-                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
-                waitPakin.setStatus("Y");    // 鐘舵��
-                waitPakin.setAppeUser(userId);
-                waitPakin.setAppeTime(now);
-                waitPakin.setModiUser(userId);
-                waitPakin.setModiTime(now);
-                if (!agvWaitPakinService.insert(waitPakin)) {
-                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
-                }
-            });
-        }else {
-            //鍏宠仈缁勬墭
-            Order order = orderService.selectByNo(param.getOrderNo());
-            if (order.getSettle() > 2) {
-                throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
-            }
-            // 鐢熸垚鍏ュ簱閫氱煡妗�
-            List<DetlDto> detlDtos = new ArrayList<>();
-            param.getCombMats().forEach(elem -> {
-
-                // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
-                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch());
-                if (elem.getAnfme() > orderDetl.getEnableQty()) {
-                    throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
-                }
-                // 淇敼璁㈠崟鏄庣粏鏁伴噺
-                if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
-                    throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触");
-                }
-
-                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
-                if (DetlDto.has(detlDtos, detlDto)) {
-                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
-                    assert one != null;
-                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
-                } else {
-                    detlDtos.add(detlDto);
-                }
-            });
-            for (DetlDto detlDto : detlDtos) {
-                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-                if (Cools.isEmpty(mat)) {
-                    throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
-                }
-                AgvWaitPakin waitPakin = new AgvWaitPakin();
-                waitPakin.sync(mat);
-                waitPakin.setOrderNo(order.getOrderNo());   // 鍗曟嵁缂栧彿
-                waitPakin.setBatch(detlDto.getBatch());     // 搴忓垪鐮�
-                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
-                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
-                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
-                waitPakin.setStatus("Y");    // 鐘舵��
-                waitPakin.setAppeUser(userId);
-                waitPakin.setAppeTime(now);
-                waitPakin.setModiUser(userId);
-                waitPakin.setModiTime(now);
-                if (!agvWaitPakinService.insert(waitPakin)) {
-                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
-                }
-            }
-            orderService.updateSettle(order.getId(), 2L, userId);
+            //鏃犲崟缁勬墭
+            NoOrderComb(param, userId);
+        } else {
+            //鏈夊崟缁勬墭
+            OrderComb(param, userId);
         }
 
-        if(StringUtils.isEmpty(param.getLocno())){
+        if (StringUtils.isEmpty(param.getLocno())) {
             return "缁勬墭鎴愬姛";
-        }else {
-            combBinding(param.getBarcode(),param.getLocno());
+        } else {
+            combBinding(param.getBarcode(), param.getLocno());
             return "缁勬墭鎴愬姛锛岀粦瀹氱珯鐐规垚鍔�";
         }
 
     }
+
+    /*
+    AGV鏃犲崟缁勬墭
+     */
+    private void NoOrderComb(CombParam param, Long userId) {
+        List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param, null);
+
+        //鐢ㄤ簬缁熶竴涓�涓墭鐩樹笅鐨勫叆搴撻�氱煡妗g殑鐢熸垚鏃堕棿
+        Date now = new Date();
+        detlDtos.forEach(detlDto -> {
+            syncWaitPakin(detlDto, "", param.getBarcode(), userId, now);
+        });
+    }
+
+    /*
+    AGV鏈夊崟缁勬墭
+     */
+    private void OrderComb(CombParam param, Long userId) {
+        //鍏宠仈缁勬墭
+        Order order = orderService.selectByNo(param.getOrderNo());
+        if (Cools.isEmpty(order)) {
+            throw new CoolException("鍗曟嵁缂栧彿涓嶅瓨鍦�");
+        }
+        //璁㈠崟鐘舵��2浠ヤ笂涓哄畬鎴愭垨鑰呭彇娑堢殑璁㈠崟
+        if (order.getSettle() > 2) {
+            throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
+        }
+        // 鐢ㄤ簬鐢熸垚鍏ュ簱閫氱煡妗f墍闇�鍙傛暟
+        List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param, order);
+        //鐢ㄤ簬缁熶竴涓�涓墭鐩樹笅鐨勫叆搴撻�氱煡妗g殑鐢熸垚鏃堕棿
+        Date now = new Date();
+        for (DetlDto detlDto : detlDtos) {
+            //鍚屾鐢熸垚鍏ュ簱閫氱煡妗�
+            syncWaitPakin(detlDto, order.getOrderNo(), param.getBarcode(), userId, now);
+        }
+        //淇敼鍗曟嵁鐘舵�佷负2.浣滀笟涓�
+        orderService.updateSettle(order.getId(), 2L, userId);
+    }
+
+    /*
+    鏍规嵁PDA鎵爜鎵�浼犵殑鐗╂枡淇℃伅鍙傛暟鏄犲皠涓篋etlDto
+     */
+    private List<DetlDto> mappingDetlDtoByCombMat(CombParam param, Order order) {
+        List<DetlDto> detlDtos = new ArrayList<>();
+        param.getCombMats().forEach(combMat -> {
+
+            if (!Cools.isEmpty(order)) {
+                //妫�鏌ュ叆搴撴暟閲�
+                checkOrderQty(order, combMat);
+            }
+
+            DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(),combMat.getContainerCode(),combMat.getProddate(),combMat.getDeadline());
+            //鍚屼竴鎵樼洏涓嬬浉鍚岀墿鏂欎俊鎭拰鎵瑰彿杞负涓�涓叆搴撻�氱煡妗�
+            if (DetlDto.has(detlDtos, detlDto)) {
+                DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(), null);
+                assert one != null;
+                one.setAnfme(one.getAnfme() + detlDto.getAnfme());
+            } else {
+                detlDtos.add(detlDto);
+            }
+        });
+
+        return detlDtos;
+    }
+
+    /*
+    妫�鏌ュ叆搴撴暟閲忔槸鍚﹀皬浜庣瓑浜庡崟鎹暟閲忥紝鍚堢悊鍒欎慨鏀筄rderDetl浣滀笟鏁伴噺淇℃伅锛屽惁鍒欐姏鍑哄紓甯�
+     */
+    private void checkOrderQty(Order order, CombParam.CombMat combMat) {
+        // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙锛屽鏋滀綔涓氭暟閲忓ぇ浜庡崟鎹暟閲忓垯鎶涘嚭寮傚父
+        OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getCsocode(), combMat.getIsoseq());
+        if (Cools.isEmpty(orderDetl)) {
+            throw new CoolException("鏈尮閰嶅埌璇ュ崟鎹笅鐨勭墿鏂�");
+        }
+        if (combMat.getAnfme() > orderDetl.getEnableQty()) {
+            throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
+        }
+        // 淇敼璁㈠崟鏄庣粏鏁伴噺
+        if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq())) {
+            throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触");
+        }
+    }
+
+    /*
+    鍚屾鐢熸垚AGV鍏ュ簱閫氱煡妗f暟鎹�
+     */
+    private void syncWaitPakin(DetlDto detlDto, String orderNo, String zpallet, Long userId, Date now) {
+        Mat mat = matService.selectByMatnr(detlDto.getMatnr());
+        if (Cools.isEmpty(mat)) {
+            throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
+        }
+        AgvWaitPakin waitPakin = new AgvWaitPakin();
+        waitPakin.sync(mat);
+        waitPakin.setOrderNo(orderNo);   // 鍗曟嵁缂栧彿
+        waitPakin.setBatch(detlDto.getBatch());     // 搴忓垪鐮�
+        //waitPakin.setZpallet(zpallet);   // 鎵樼洏鐮�
+        waitPakin.setSuppCode(zpallet);   // 鎵樼洏鐮�
+        waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+        waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
+        waitPakin.setStatus("Y");    // 鐘舵��
+        waitPakin.setProddate(detlDto.getProddate());
+        waitPakin.setDeadline(detlDto.getDeadline());
+        ////閿�鍞鍗曞彿
+        waitPakin.setThreeCode(detlDto.getCsocode());
+        //閿�鍞鍗曡鍙�
+        waitPakin.setDeadTime(detlDto.getIsoseq());
+
+
+        waitPakin.setAppeUser(userId);
+        waitPakin.setAppeTime(now);
+        waitPakin.setModiUser(userId);
+        waitPakin.setModiTime(now);
+        if (!agvWaitPakinService.insert(waitPakin)) {
+            throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+        }
+    }
+
 
     @Override
     @Transactional
@@ -162,25 +225,41 @@
 
     @Override
     public void combBinding(String barcode, String stationCode) {
-        EntityWrapper<AgvBasDevp> wrapper = new EntityWrapper<>();
-        wrapper.eq("dev_no",stationCode);
-        AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(wrapper);
-        if(agvBasDevp == null){
+
+        if (Cools.isEmpty(agvWaitPakinService.selectByContainerCode(barcode))) {
+            throw new CoolException("璇ユ枡绠辨湭缁勬墭锛屾棤娉曠粦瀹氱珯鐐�");
+        }
+
+        AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", barcode));
+
+        if (!Cools.isEmpty(agvBasDevp)) {
+            throw new CoolException(barcode + "宸茬粡缁戝畾鍦�" + agvBasDevp.getDevNo() + "绔欑偣");
+        }
+
+        agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no", stationCode));
+        if (agvBasDevp == null) {
             throw new CoolException(stationCode + "绔欑偣淇℃伅閿欒");
         }
-        if(!"O".equals(agvBasDevp.getLocSts())){
+        if (!"O".equals(agvBasDevp.getLocSts())) {
             throw new CoolException(stationCode + "璇ョ珯鐐硅揣浣嶇姸鎬侀潪绌�");
+        }
+        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", agvBasDevp.getDevNo()));
+        if (!Cools.isEmpty(agvWrkMast)) {
+            throw new CoolException(stationCode + "璇ョ珯鐐瑰凡琚伐浣滃彿涓�" + agvWrkMast.getWrkNo() + "鍗犵敤锛屾棤娉曠粦瀹�");
         }
 
         agvBasDevp.setBarcode(barcode);
         agvBasDevp.setLocSts("F");
-        agvBasDevpService.update(agvBasDevp,wrapper);
+        agvBasDevpService.update(agvBasDevp, (new EntityWrapper<AgvBasDevp>().eq("dev_no", stationCode)));
     }
 
     public List<AgvBasDevp> getAgvBasDevpByFloor(int floor) {
         EntityWrapper<AgvBasDevp> wrapper = new EntityWrapper<>();
-        wrapper.eq("floor",floor).eq("cache_shelves","Y");
-        return agvBasDevpService.selectList(wrapper);
+        wrapper.eq("floor", floor).eq("cache_shelves", "Y").eq("loc_sts", "F");
+        List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(wrapper);
+        return agvBasDevpList.stream().filter(agvBasDevp -> {
+            return !Cools.isEmpty(agvWaitPakinService.selectByContainerCode(agvBasDevp.getBarcode()));
+        }).collect(Collectors.toList());
     }
 
 }

--
Gitblit v1.9.1