From 5b8e4ab420376484abbdff166a16f4e440a169a6 Mon Sep 17 00:00:00 2001
From: chen.llin <1442464845@qq.comm>
Date: 星期二, 23 十二月 2025 15:01:42 +0800
Subject: [PATCH] 入库单据查询提示构造方法错误->修正

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  581 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 491 insertions(+), 90 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
index 09fcff6..7ad382d 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -8,11 +8,15 @@
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.*;
+import com.zy.asrs.enums.LocStsType;
+import com.zy.asrs.mapper.BasDevpMapper;
+import com.zy.asrs.mapper.BasStationMapper;
 import com.zy.asrs.mapper.LocMastMapper;
 import com.zy.asrs.mapper.ManLocDetlMapper;
 import com.zy.asrs.service.*;
+import com.zy.asrs.task.core.ReturnT;
 import com.zy.asrs.utils.MatUtils;
-import com.zy.asrs.utils.OrderInAndOutUtil;
+import com.zy.common.constant.ApiInterfaceConstant;
 import com.zy.common.constant.MesConstant;
 import com.zy.common.entity.Parameter;
 import com.zy.common.model.DetlDto;
@@ -21,12 +25,17 @@
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.HttpHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 绉诲姩绔湇鍔℃牳蹇冪被
@@ -40,10 +49,7 @@
     private MatService matService;
     @Autowired
     private WaitPakinService waitPakinService;
-    @Autowired
-    private OrderService orderService;
-    @Autowired
-    private OrderDetlService orderDetlService;
+
     @Autowired
     private BasDevpService basDevpService;
     @Autowired
@@ -96,6 +102,119 @@
     @Resource
     private OrderDetlPakoutService orderDetlPakoutService;
 
+    @Autowired
+    private LocCacheService locCacheService;
+
+    @Autowired
+    private TaskService taskService;
+
+    @Autowired
+    private TaskDetlService taskDetlService;
+    @Autowired
+    private BasStationService basStationService;
+    @Autowired
+    private BasContainerService basContainerService;
+
+    @Resource
+    private BasStationMapper basStationMapper;
+
+    @Resource
+    private BasDevpMapper basDevpMapper;
+
+    @Override
+    public R inLocCallAgv(CallAgvParam param,Long userId) {
+        int type = param.getType();
+        int sourceSite = param.getSourceSite();
+        String barcode = param.getBarcode();
+        int ioType;
+
+        switch (type) {
+            case 1:
+                // 鍒ゆ柇鏈夋病鏈夌粍鎵�
+                int count = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
+                if (count == 0) {
+                    throw new CoolException("鏉$爜鏈粍鎵橈細" + barcode);
+                }
+                ioType = 1;
+                break;
+            case 2:
+                // 鍒ゆ柇鏄嫞閫夊洖搴撴墭鐩�
+                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode));
+                if (wrkMast == null) {
+                    throw new CoolException("鏉$爜涓嶅瓨鍦細" + barcode);
+                }
+                if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107) {
+                    throw new CoolException("鏉$爜涓嶉渶瑕佸洖搴擄細" + barcode);
+                }
+                ioType = wrkMast.getIoType() - 50;
+                break;
+            case 3:
+                // 鍒ゆ柇鏉$爜鍦╳ms涓嶅瓨鍦紝鏄┖鎵樼洏
+                // 宸茬粍鎵�
+                int waitPakInCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
+                if (waitPakInCount != 0) {
+                    throw new CoolException("鏉$爜缁勬墭妗e凡瀛樺湪锛�" + barcode);
+                }
+                // 鏈変换鍔�
+                int wrkMastCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", barcode));
+                if (wrkMastCount != 0) {
+                    throw new CoolException("鏉$爜浠诲姟妗e凡瀛樺湪锛�" + barcode);
+                }
+                // 鏈夊簱瀛�
+                int locDetlCount = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", barcode));
+                if (locDetlCount != 0) {
+                    throw new CoolException("鏉$爜搴撳瓨宸插瓨鍦細" + barcode);
+                }
+                ioType = 10;
+                break;
+            default:
+                throw new CoolException("鍏ュ簱绫诲瀷閿欒,type锛�" + type);
+        }
+        // 鏉$爜瀛樺湪agv浠诲姟
+        int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode));
+        if (count > 0) {
+            throw new CoolException(barcode+ "锛氭潯鐮佸瓨鍦╝gv鎼繍浠诲姟!");
+        }
+
+        // 鍒ゆ柇鑳藉叆绔欑偣
+        List<Integer> sites = basDevpMapper.selectList(
+                new EntityWrapper<BasDevp>()
+                        .eq("canining", "Y")
+                        .in("dev_no", type == 1 ? Arrays.asList(1003, 1005, 1007) : Arrays.asList(1044, 1046, 1048))
+        ).stream().map(BasDevp::getDevNo).collect(Collectors.toList());
+
+        if (sites.isEmpty()) {
+            throw new CoolException("娌℃湁鑳藉叆绔欑偣,type锛�" + type);
+        }
+
+        // 鑾峰彇娌℃湁鍑哄簱浠诲姟鐨勭珯鐐�
+        List<Integer> canInSites = basDevpMapper.getCanInSites(sites);
+        if (canInSites.isEmpty()) {
+            throw new CoolException("璇风瓑寰呭嚭搴撳畬鎴�,type:" + type);
+        }
+
+        // 瀵绘壘鍏ュ簱浠诲姟鏈�灏戠殑绔欑偣
+        List<BasDevp> devList = basDevpMapper.selectList(new EntityWrapper<BasDevp>().in("dev_no", canInSites));
+        // 鍏ュ簱浠诲姟鏁版帓搴�
+        devList.sort(Comparator.comparing(BasDevp::getInQty));
+
+        // 鍙栧叆搴撲换鍔℃渶灏戠珯鐐�
+        BasDevp basDevp = devList.get(0);
+        int endSite = basDevp.getDevNo();
+
+        // 鍏ュ簱鏆傚瓨+1
+        basDevpMapper.incrementInQty(endSite);
+
+        // 鎻掑叆agv浠诲姟
+        Task task = new Task(0, 7L, ioType, String.valueOf(sourceSite), String.valueOf(endSite), userId, barcode);
+        taskService.insert(task);
+
+        // 鏇存柊鏆傚瓨浣嶇姸鎬佷负 R.鍑哄簱棰勭害
+        basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), "R");
+        return R.ok("agv浠诲姟鐢熸垚鎴愬姛!");
+
+    }
+
     @Override
     @Transactional
     public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long hostId, Long userId) {
@@ -117,8 +236,8 @@
         wrkMast.setIoType(8); // 鍏ュ嚭搴撶姸鎬侊細8.鎷f枡閫斾腑骞舵澘
         wrkMast.setIoPri(13D); // 浼樺厛绾�
         wrkMast.setCrnNo(1);
-        wrkMast.setSourceStaNo(1);
-        wrkMast.setStaNo(1);
+        wrkMast.setSourceStaNo(1 + "");
+        wrkMast.setStaNo(1 + "");
         wrkMast.setLocNo(param.getLocNo());
         wrkMast.setBarcode(param.getBarcode()); // 鎵樼洏鐮�
         wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
@@ -244,8 +363,8 @@
         wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細101.鐢熸垚鍑哄簱
         wrkMast.setIoType(104); // 鍏ュ嚭搴撶姸鎬�
         wrkMast.setIoPri(13D); // 浼樺厛绾э細13
-        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
-        wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
+        wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 婧愮珯
+        wrkMast.setStaNo(staDesc.getStnNo() + ""); // 鐩爣绔�
         wrkMast.setSourceLocNo(param.getLocNo()); // 婧愬簱浣�
         wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
         wrkMast.setPicking("Y"); // 鎷f枡
@@ -345,7 +464,7 @@
                     continue;
                 }
                 if (orderPakout.getSettle() == 1) {
-                    OrderInAndOutUtil.updateOrder(false, orderPakout.getId(), 2L, 9527L);
+                    orderPakoutService.updateSettle(orderPakout.getId(), 2L, 9527L);
                 }
                 OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(), combMat.getMatnr(), combMat.getBatch(),
                         combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3());
@@ -378,8 +497,8 @@
                 wrkMast.setIoType(108); // 鍏ュ嚭搴撶姸鎬侊細鍑哄簱锛屾嫞鏂欏叆搴�
                 wrkMast.setIoPri(13D); // 浼樺厛绾�
                 wrkMast.setCrnNo(1);
-                wrkMast.setSourceStaNo(1);
-                wrkMast.setStaNo(1);
+                wrkMast.setSourceStaNo(1 + "");
+                wrkMast.setStaNo(1 + "");
                 wrkMast.setSourceLocNo(combParam.getLocNo());
                 wrkMast.setBarcode(combParam.getBarcode()); // 鎵樼洏鐮�
                 wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
@@ -495,18 +614,18 @@
             typeList.add(docType.getDocId());
         }
 
-        Wrapper<Order> wrapper = new EntityWrapper<>();
+        Wrapper<OrderPakin> wrapper = new EntityWrapper<>();
         wrapper.eq("status", 1);
         wrapper.in("doc_type", typeList);
-        List<Order> orders = orderService.selectList(wrapper);
+        List<OrderPakin> orders = orderPakinService.selectList(wrapper);
 
         ArrayList<Long> orderIds = new ArrayList<>();
-        for (Order order : orders) {
+        for (OrderPakin order : orders) {
             orderIds.add(order.getId());
         }
 
         //鎼滅储鏄庣粏
-        Wrapper<OrderDetl> wrapper1 = new EntityWrapper<>();
+        Wrapper<OrderDetlPakin> wrapper1 = new EntityWrapper<>();
         wrapper1.eq("status", 1);
         wrapper1.in("order_id", orderIds);
         wrapper1.orderBy("create_time", false);
@@ -516,10 +635,10 @@
         if (!Cools.isEmpty(orderNo)) {
             wrapper1.like("order_no", orderNo);
         }
-        List<OrderDetl> list = orderDetlService.selectList(wrapper1);
+        List<OrderDetlPakin> list = orderDetlPakinService.selectList(wrapper1);
 
         ArrayList<PickMatParam> maps = new ArrayList<>();
-        for (OrderDetl orderDetl : list) {
+        for (OrderDetlPakin orderDetl : list) {
             //鍓╀綑鍙敤鏁伴噺
             double count = orderDetl.getAnfme() - orderDetl.getWorkQty();
             if (count <= 0) {
@@ -544,20 +663,18 @@
         if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
             throw new CoolException(BaseRes.PARAM);
         }
-        if (param.getCombMats().size() > 1) {
+        if (param.getCombMats().size() < 1) {
             throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
         }
         // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
         if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
-                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
+                eq("zpallet", param.getBarcode())
+                .eq("io_status", "N")) > 0) {
             throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
         }
 
         if (param.getBarcode().length() != 8) {
             throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode());
-        }
-        if (param.getCombMats().size() > 1) {
-            throw new CoolException("涓嶅厑璁告贩鏂�===>>" + param.getBarcode());
         }
 
         int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()));
@@ -568,10 +685,8 @@
         }
 
         Date now = new Date();
-
         // 鏃犲崟缁勬墭
         if (Cools.isEmpty(param.getOrderNo())) {
-
             // 鐢熸垚鍏ュ簱閫氱煡妗�
             List<DetlDto> detlDtos = new ArrayList<>();
             param.getCombMats().forEach(elem -> {
@@ -586,19 +701,21 @@
                 }
             });
 
-
             for (DetlDto detlDto : detlDtos) {
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
                     throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
                 }
+//                if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
+//                    throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟鏈�澶х粍鎵樹笂闄愪负锛�" + mat.getUpQty());
+//                }
                 WaitPakin waitPakin = new WaitPakin();
-                waitPakin.sync(mat);
+                BeanUtils.copyProperties(mat, waitPakin);
                 waitPakin.setBatch(detlDto.getBatch());
-                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
-                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
-                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
-                waitPakin.setStatus("Y");    // 鐘舵��
+                waitPakin.setZpallet(param.getBarcode());
+                waitPakin.setIoStatus("N");
+                waitPakin.setAnfme(detlDto.getAnfme());
+                waitPakin.setStatus("Y");
                 waitPakin.setAppeUser(userId);
                 waitPakin.setAppeTime(now);
                 waitPakin.setModiUser(userId);
@@ -609,30 +726,31 @@
             }
             // 鍏宠仈缁勬墭
         } else {
-//            Order order = orderService.selectByNo(param.getOrderNo());
-            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo());
-            if (Cools.isEmpty(order) || 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());
-                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
-                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
-                if (elem.getAnfme() > orderDetl.getEnableQty()) {
-                    throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
+                OrderPakin order = orderPakinService.selectByNo(elem.getOrderNo());
+                if (Cools.isEmpty(order) || order.getSettle() > 2) {
+                    throw new CoolException("鍗曟嵁姝e湪浣滀笟涓�");
                 }
-                // 淇敼璁㈠崟浣滀笟鏁伴噺
-//                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
-//                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
-//                }
-                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
+                // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
+                OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
+                        .eq("order_id", order.getId())
+                        .eq("matnr", elem.getMatnr()));
+
+                if (Objects.isNull(detls)) {
+                    throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗕笉瀛樺湪锛侊紒");
+                }
+
+                if (elem.getAnfme() > detls.getEnableQty()) {
+                    throw new CoolException(detls.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
+                }
+                orderDetlPakinService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                         elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                 DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                         elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
+                detlDto.setOrderId(order.getId());
+                detlDto.setOrderNo(order.getOrderNo());
                 if (DetlDto.has(detlDtos, detlDto)) {
                     DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                     assert one != null;
@@ -641,14 +759,45 @@
                     detlDtos.add(detlDto);
                 }
             });
+
+//            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
+//            if (Objects.isNull(container)) {
+//                throw new CoolException("鏁版嵁閿欒锛氬鍣ㄧ爜涓嶅瓨鍦紒锛�");
+//            }
+//            if (container.getMixMax() < detlDtos.size()) {
+//                throw new CoolException("瓒呭嚭瀹瑰櫒鏈�澶ф贩瑁呮暟閲忥紝褰撳墠瀹瑰櫒鏈�澶ф暟閲忎负锛�" + container.getMixMax() + "!!");
+//            }
+//            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
+//            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
+//            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
+//            if (tagIds.size() > 1) {
+//                throw new CoolException("缁勬墭鐗╂枡绫诲瀷涓嶄竴鑷达紝鍙湁鐩稿悓鐨勭墿鏂欏垎绫绘墠鍙互缁勬墭锛侊紒");
+//            }
+//            //杩樺彲浠ユ斁鍏ュ灏戠鐗╂枡
+//            Integer suplus = container.getMixMax();
             for (DetlDto detlDto : detlDtos) {
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
                     throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
                 }
+//                //鏈�澶氬彲鏀炬暟閲�
+//                Double singleMax = mat.getUpQty() * suplus;
+//                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
+//                    throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟缁勬墭涓婇檺涓猴細" + mat.getUpQty() + ",褰撳墠鎬婚噺瓒呭嚭鎵樼洏瑁呰浇涓婇檺!!");
+//                }
+//                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
+//                //褰撳墠鐗╂枡闇�瑕佸崰鐢ㄦ枡绠辨牸鏁�
+//                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
+//                suplus = suplus - curr;
+//                if (suplus < 0) {
+//                    throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + ", 瓒呭嚭褰撳墠鎵樼洏瑁呰浇涓婇檺锛侊紒");
+//                }
+
                 WaitPakin waitPakin = new WaitPakin();
-                waitPakin.sync(mat);
-                waitPakin.setOrderNo(order.getOrderNo());   // 鍗曟嵁缂栧彿
+                BeanUtils.copyProperties(mat, waitPakin);
+//                waitPakin.sync(mat);
+                waitPakin.setOrderNo(detlDto.getOrderNo());   // 鍗曟嵁缂栧彿
+                waitPakin.setOrderId(detlDto.getOrderId());
                 waitPakin.setBatch(detlDto.getBatch());     // 搴忓垪鐮�
                 waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
                 waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
@@ -662,8 +811,12 @@
                     throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
                 }
             }
-//            orderService.updateSettle(order.getId(), 2L, userId);
-            OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
+
+            Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo).collect(Collectors.toSet());
+            stringSet.forEach(orderNo -> {
+                OrderPakin order = orderPakinService.selectByNo(orderNo);
+                orderPakinService.updateSettle(order.getId(), 2L, userId);
+            });
         }
 
     }
@@ -866,7 +1019,7 @@
                 boolean success = false;
                 try {
                     response = new HttpHandler.Builder()
-                            .setUri(MesConstant.URL)
+                            .setUri(MesConstant.URI)
                             .setPath(MesConstant.PACK_DOWN_URL)
                             .setJson(JSON.toJSONString(mesCombParam))
                             .build()
@@ -875,10 +1028,10 @@
                     if (jsonObject.getInteger("code").equals(200)) {
                         success = true;
                     } else if (jsonObject.getInteger("code").equals(500)) {
-                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
+                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                         throw new CoolException(jsonObject.getString("msg"));
                     } else {
-                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
+                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                         throw new CoolException("涓婃姤mes绯荤粺澶辫触");
                     }
                 } catch (Exception e) {
@@ -889,7 +1042,7 @@
                         // 淇濆瓨鎺ュ彛鏃ュ織
                         apiLogService.save(
                                 "鎵撳寘涓嬬嚎甯墭涓婃姤",
-                                MesConstant.URL + MesConstant.PACK_DOWN_URL,
+                                MesConstant.URI + MesConstant.PACK_DOWN_URL,
                                 null,
                                 "127.0.0.1",
                                 JSON.toJSONString(mesCombParam),
@@ -911,41 +1064,35 @@
             openParam.setOrderType("鎵撳寘鍏ュ簱鍗�");
             openParam.setOrderDetails(detlDtos);
             openService.pakinOrderCreate(openParam);
-//            Order order = orderService.selectByNo(orderNo);
-            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo());
+            OrderPakin order = orderPakinService.selectByNo(param.getOrderNo());
 
             if (null == order) {
                 throw new CoolException("鐢熸垚鍗曟嵁澶辫触");
             }
-//            if (!orderService.updateSettle(order.getId(), 2L, userId)) {
-//                throw new CoolException("淇敼鍗曟嵁鐘舵�佸け璐�");
-//            }
-            OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
-
+            if (!orderPakinService.updateSettle(order.getId(), 2L, userId)) {
+                throw new CoolException("淇敼鍗曟嵁鐘舵�佸け璐�");
+            }
             // 鐢熸垚鍏ュ簱閫氱煡妗�
             for (DetlDto detlDto : detlDtos) {
 
-                // 淇敼浣滀笟鏁伴噺 ----------------------------------------
                 // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
-//                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch());
-                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
+                OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
                         , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3());
-                if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
-                    throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
+                if (detlDto.getAnfme() > orderDetlPakin.getEnableQty()) {
+                    throw new CoolException(orderDetlPakin.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
                 }
                 // 淇敼璁㈠崟浣滀笟鏁伴噺
-//                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
-//                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
-//                }
-                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
-                        , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme());
+                if (!orderDetlPakinService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
+                        , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme())) {
+                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
+                }
                 // 淇濆瓨鍏ュ簱閫氱煡妗�
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
                     throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
                 }
                 WaitPakin waitPakin = new WaitPakin();
-                waitPakin.sync(mat);
+                BeanUtils.copyProperties(mat, waitPakin);
                 waitPakin.setOrderNo(orderNo);
                 waitPakin.setBatch(detlDto.getBatch());
                 waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
@@ -980,17 +1127,15 @@
 
         BasDevp sta = basDevpService.checkSiteStatus(staNo);
         //鏍规嵁璁㈠崟鍙风敓鎴愬嚭搴撲换鍔″伐浣滄。
-        Order order = OrderInAndOutUtil.selectByNo(Boolean.FALSE, orderNo);
-//        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
+        OrderPakout order = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>().eq("order_no", orderNo));
         if (order.getSettle() != 1 && order.getSettle() != 2) {
             throw new CoolException("璇ヨ鍗曞凡澶勭悊");
         }
 
-//        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
-        List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(Boolean.FALSE, order.getId());
+        List<OrderDetlPakout> orderDetls = orderDetlPakoutService.selectByOrderId(order.getId());
 
         Date now = new Date();
-        for (OrderDetl orderDetl : orderDetls) {
+        for (OrderDetlPakout orderDetl : orderDetls) {
             //鏌ヨ鎵�鏈夊簱浣嶇姸鎬佷负F鐨勫簱浣嶄俊鎭�
             List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null);
             if (locDetls.size() == 0) {
@@ -1023,10 +1168,9 @@
                 order.setSettle(2L);
                 order.setUpdateBy(userId);
                 order.setUpdateTime(now);
-//                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
-//                    throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�");
-//                }
-                OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 2L, userId);
+                if (!orderPakoutService.update(order, new EntityWrapper<OrderPakout>().eq("order_no", orderNo))) {
+                    throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�");
+                }
                 orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
                 orderDetl.setUpdateBy(userId);
                 orderDetl.setUpdateTime(now);
@@ -1035,10 +1179,9 @@
                 if (!Cools.isEmpty(orderDetl.getBatch())) {
                     wrapper.eq("batch", orderDetl.getBatch());
                 }
-//                if(!orderDetlService.update(orderDetl, wrapper)){
-//                    throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触");
-//                }
-                OrderInAndOutUtil.updateOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl);
+                if (!orderDetlPakoutService.update(orderDetl, wrapper)) {
+                    throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触");
+                }
 
             }
 
@@ -1047,7 +1190,7 @@
 
     @Override
     @Transactional
-    public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
+    public void stockOut(OrderDetlPakout orderDetl, BasDevp staNo, LocDetl locDetl,
                          Double curOutQty, Integer ioType, Long userId, Date now) {
         // 鑾峰彇搴撲綅
         LocMast locMast = locMastService.selectById(locDetl.getLocNo());
@@ -1071,8 +1214,8 @@
         wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
         wrkMast.setIoPri(13D); // 浼樺厛绾э細13
         wrkMast.setCrnNo(locMast.getCrnNo());
-        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
-        wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
+        wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 婧愮珯
+        wrkMast.setStaNo(staDesc.getStnNo() + ""); // 鐩爣绔�
         wrkMast.setSourceLocNo(locDetl.getLocNo()); // 婧愬簱浣�
         wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
         wrkMast.setPicking("N"); // 鎷f枡
@@ -1115,4 +1258,262 @@
             throw new CoolException(locDetl.getLocNo() + "搴撲綅涓嶆槸鍦ㄥ簱鐘舵��");
         }
     }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/22
+     * @description: 鑾峰彇缂撳啿鍖哄簱浣嶄俊鎭�
+     * @version 1.0
+     */
+    @Override
+    public R getCacheLocs() {
+        return R.ok().add(locCacheService.selectList(new EntityWrapper<LocCache>()
+                .eq("frozen", 0)
+                .ne("full_plt", "Y")
+                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type).orderAsc(Arrays.asList("row1"))));
+
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/22
+     * @description: 鍛煎彨AGV鎼繍
+     * @version 1.0
+     */
+    @Override
+    public R callAgvMove(AgvCallParams params, Long userId) {
+        if (Objects.isNull(params.getTarSite())) {
+            throw new CoolException("鐩爣鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getOrgSite())) {
+            throw new CoolException("婧愮珯鐐逛笉鑳戒负绌猴紒锛�");
+        }
+        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>()
+                .eq("frozen", 0)
+                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
+                .eq("loc_no", params.getTarSite())
+                .orderAsc(Arrays.asList("loc_no"))
+                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+        if (Objects.isNull(locCache)) {
+            throw new CoolException("璇锋鏌ョ洰鏍囧簱浣嶆槸鍚﹂棽缃腑锛侊紒");
+        }
+
+        generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId);
+
+        return R.ok();
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/24
+     * @description: 鑾峰彇璁㈠崟鐗╂枡淇℃伅
+     * @version 1.0
+     */
+    @Override
+    public R getMatsByQRcode(PakinMatsByQRParams params) {
+        if (Objects.isNull(params)) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getOrderNo())) {
+            throw new CoolException("鍗曞彿涓嶈兘涓虹┖锛侊紒");
+        }
+        OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no", params.getOrderNo()));
+        if (Objects.isNull(orderPakin)) {
+            throw new CoolException("鏁版嵁閿欒锛氬崟鎹笉瀛樺湪锛侊紒");
+        }
+        List<OrderDetlPakin> detlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>()
+                .eq(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr())
+                .eq("order_id", orderPakin.getId()));
+        if (Objects.isNull(detlPakins) || detlPakins.isEmpty()) {
+            throw new CoolException("鏁版嵁閿欒锛� 鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
+        }
+
+        return R.ok().add(detlPakins);
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/24
+     * @description: AGV鍛煎彨鎼繍
+     * @version 1.0
+     */
+    @Override
+    public R OutCallAgv(AgvCallParams params, Long userId) {
+        LocCache locCaches = locCacheService.selectOne(new EntityWrapper<LocCache>()
+                .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type)
+                .eq("frozen", 0)
+                .orderDesc(Arrays.asList("sort", "first_time"))
+                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+        if (Objects.isNull(locCaches)) {
+            throw new CoolException("鏆傛棤婊¤冻闇�姹傚簱浣嶏紒");
+        }
+        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
+                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
+                .eq("dev_no", params.getTarSite()));
+        if (Objects.isNull(station)) {
+            throw new CoolException("绔欑偣姝e湪鎵ц浠诲姟锛侊紒");
+        }
+
+        generateOutTask(station, locCaches, userId);
+
+        return R.ok();
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/25
+     * @description: 鍛煎彨AGV鐢熸垚鍑哄簱浠诲姟
+     * @version 1.0
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void generateOutTask(BasStation station, LocCache loc, Long userId) {
+        // 鑾峰彇宸ヤ綔鍙�
+        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+        // 淇濆瓨宸ヤ綔妗�
+        Task task = new Task();
+        task.setWrkNo(workNo)
+                .setIoTime(new Date())
+                .setWrkSts(11L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+                .setIoType(101) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+                .setTaskType("agv")
+                .setIoPri(10D)
+                .setFullPlt("Y") // 婊℃澘锛歒
+                .setPicking("N") // 鎷f枡
+                .setExitMk("N")// 閫�鍑�
+                .setStaNo(station.getDevNo())
+                .setSourceLocNo(loc.getLocNo())
+                .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 绌烘澘
+                .setBarcode(loc.getBarcode())// 鎵樼洏鐮�
+                .setLinkMis("N")
+                .setAppeUser(userId)
+                .setAppeTime(new Date())
+                .setModiUser(userId)
+                .setModiTime(new Date());
+        if (!taskService.insert(task)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+        }
+        List<LocDetl> detls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_id", loc.getId()));
+        if (Objects.isNull(detls) || detls.isEmpty()) {
+            throw new CoolException("鏁版嵁閿欒锛氬簱浣嶆槑缁嗕负绌猴紒锛�");
+        }
+        List<TaskDetl> taskDetls = new ArrayList<>();
+        detls.forEach(pakin -> {
+            TaskDetl wrkDetl = new TaskDetl();
+            BeanUtils.copyProperties(pakin, wrkDetl);
+            wrkDetl.setWrkNo(workNo)
+                    .setIoTime(new Date())
+                    .setOrderNo(pakin.getOrderNo())
+                    .setAnfme(pakin.getAnfme())
+                    .setZpallet(pakin.getZpallet())
+                    .setBatch(pakin.getBatch())
+                    .setMatnr(pakin.getMatnr())
+                    .setMaktx(pakin.getMaktx())
+                    .setAppeUser(userId)
+                    .setUnit(pakin.getUnit())
+                    .setModel(pakin.getModel())
+                    .setAppeTime(new Date())
+                    .setModiUser(userId);
+            taskDetls.add(wrkDetl);
+        });
+
+        //淇濆瓨宸ヤ綔妗f槑缁�
+        if (!taskDetlService.insertBatch(taskDetls)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+        }
+
+        loc.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
+        loc.setModiUser(userId);
+        loc.setModiTime(new Date());
+
+        if (!locCacheService.updateById(loc)) {
+            throw new CoolException("鏇存柊搴撲綅鐘舵�佷俊鎭紒锛�");
+        }
+
+        // 淇敼鐩爣绔欑偣淇℃伅
+        if (station.getLocSts().equals("O")) {
+            station.setLocSts("S"); // S.鍏ュ簱棰勭害
+            station.setModiTime(new Date());
+            station.setModiUser(userId);
+            if (!basStationService.updateById(station)) {
+                throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+            }
+        } else {
+            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+        }
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/9/22
+     * @description: 鐢熸垚AGV鎼繍浠诲姟
+     * @version 1.0
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
+        List<WaitPakin> pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
+        if (Objects.isNull(pakins) || pakins.isEmpty()) {
+            throw new CoolException("缁勬墭淇℃伅涓嶅瓨鍦紒锛�");
+        }
+        // 鑾峰彇宸ヤ綔鍙�
+        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+        // 淇濆瓨宸ヤ綔妗�
+        Task task = new Task();
+        task.setWrkNo(workNo)
+                .setIoTime(new Date())
+                .setWrkSts(1L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+                .setIoType(1) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+                .setTaskType("agv")
+                .setIoPri(10D)
+                .setLocNo(loc.getLocNo()) // 鐩爣搴撲綅
+                .setFullPlt("Y") // 婊℃澘锛歒
+                .setPicking("N") // 鎷f枡
+                .setExitMk("N")// 閫�鍑�
+                .setSourceStaNo(orgSite)
+                .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 绌烘澘
+                .setBarcode(barcode)// 鎵樼洏鐮�
+                .setLinkMis("N")
+                .setAppeUser(userId)
+                .setAppeTime(new Date())
+                .setModiUser(userId)
+                .setModiTime(new Date());
+        if (!taskService.insert(task)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+        }
+
+        List<TaskDetl> taskDetls = new ArrayList<>();
+        pakins.forEach(pakin -> {
+            TaskDetl wrkDetl = new TaskDetl();
+            BeanUtils.copyProperties(pakin, wrkDetl);
+            wrkDetl.setWrkNo(workNo)
+                    .setIoTime(new Date())
+                    .setOrderNo(pakin.getOrderNo())
+                    .setAnfme(pakin.getAnfme())
+                    .setZpallet(pakin.getZpallet())
+                    .setBatch(pakin.getBatch())
+                    .setMatnr(pakin.getMatnr())
+                    .setMaktx(pakin.getMaktx())
+                    .setAppeUser(userId)
+                    .setUnit(pakin.getUnit())
+                    .setModel(pakin.getModel())
+                    .setAppeTime(new Date())
+                    .setModiUser(userId);
+            taskDetls.add(wrkDetl);
+        });
+
+        //淇濆瓨宸ヤ綔妗f槑缁�
+        if (!taskDetlService.insertBatch(taskDetls)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+        }
+        // 淇敼鐩爣搴撲綅鐘舵��
+        if (loc.getLocSts().equals("O")) {
+            loc.setLocSts("S"); // S.鍏ュ簱棰勭害
+            loc.setModiTime(new Date());
+            loc.setModiUser(userId);
+            if (!locCacheService.updateById(loc)) {
+                throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+            }
+        } else {
+            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + loc.getLocSts$());
+        }
+    }
 }

--
Gitblit v1.9.1