From 45b95bf88ab48e4b4db7ff9205e9afa2b83e8737 Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期五, 03 四月 2026 19:29:09 +0800
Subject: [PATCH] no message

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java | 1632 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 1,235 insertions(+), 397 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 c3db773..78c07c3 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.*;
 import com.core.exception.CoolException;
+import com.zy.api.enums.MatLocType;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.*;
 import com.zy.asrs.entity.result.*;
@@ -17,27 +18,31 @@
 import com.zy.asrs.service.*;
 import com.zy.asrs.utils.MatUtils;
 import com.zy.asrs.utils.OrderInAndOutUtil;
+import com.zy.asrs.utils.Utils;
 import com.zy.common.constant.HIKApiConstant;
 import com.zy.common.constant.MesConstant;
 import com.zy.common.entity.Parameter;
-import com.zy.common.model.DetlDto;
-import com.zy.common.model.LocTypeDto;
-import com.zy.common.model.MesCombParam;
-import com.zy.common.model.StartupDto;
+import com.zy.common.model.*;
 import com.zy.common.model.enums.WorkNoType;
+import com.zy.common.properties.SlaveProperties;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.HttpHandler;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -88,6 +93,9 @@
     private ManLocDetlMapper manLocDetlMapper;
 
     @Autowired
+    private SlaveProperties slaveProperties;
+
+    @Autowired
     private AdjDetlService adjDetlService;
 
     @Resource
@@ -126,6 +134,10 @@
     private StationRelaService stationRelaService;
     @Autowired
     private BasStationDetlService basStationDetlService;
+    @Autowired
+    private WorkService workService;
+    @Autowired
+    private ConfigService configService;
 
     @Override
     @Transactional
@@ -166,7 +178,9 @@
         wrkMastService.insert(wrkMast);
 
         for (OrderDetl orderDetl : param.getCombMats()) {
-            Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", orderDetl.getMatnr()));
+            Mat mat = matService.selectOne(new EntityWrapper<Mat>()
+                    .eq("supp_code", orderDetl.getStandby1())
+                    .eq("matnr", orderDetl.getMatnr()));
             if (mat == null) {
                 throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鐗╂枡淇℃伅涓嶅瓨鍦細" + orderDetl.getMatnr());
             }
@@ -365,6 +379,7 @@
         for (CombParam.CombMat combMat : combParam.getCombMats()) {
             List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>()
                     .eq("loc_no", combParam.getLocNo())
+                    .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1())
                     .eq("matnr", combMat.getMatnr()));
             if (locDetlList.isEmpty()) {
                 return R.error("鏈煡璇㈠埌搴撳瓨鏁版嵁");
@@ -439,7 +454,9 @@
                 wrkMast.setModiUser(userId);
                 wrkMastService.insert(wrkMast);
 
-                Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", combMat.getMatnr()));
+                Mat mat = matService.selectOne(new EntityWrapper<Mat>()
+                        .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1())
+                        .eq("matnr", combMat.getMatnr()));
                 if (mat == null) {
                     throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鐗╂枡淇℃伅涓嶅瓨鍦細" + combMat.getMatnr());
                 }
@@ -584,12 +601,10 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void comb(CombParam param, Long userId) {
-        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
+        if (Objects.isNull(param.getBarcode())) {
             throw new CoolException(BaseRes.PARAM);
         }
-        if (param.getCombMats().size() < 1) {
-            throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
-        }
+
         // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
         if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())
                 .eq("io_status", "N")) > 0) {
@@ -605,9 +620,6 @@
         if (Objects.isNull(container)) {
             throw new CoolException("鏁版嵁閿欒锛氬鍣ㄧ爜涓嶅瓨鍦紒锛�");
         }
-        // if (param.getBarcode().length() != 8) {
-        // throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode());
-        // }
 
         if (Objects.isNull(param.getType())) {
             param.setType("0");
@@ -624,51 +636,69 @@
         Date now = new Date();
         // 鏃犲崟缁勬墭
         if (Cools.isEmpty(param.getOrderNo())) {
-            // 鐢熸垚鍏ュ簱閫氱煡妗�
-            List<DetlDto> detlDtos = new ArrayList<>();
-            param.getCombMats().forEach(elem -> {
-                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
-                        elem.getStandby2(), elem.getStandby3(),
-                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
-                        elem.getThreeCode());
-                if (DetlDto.has(detlDtos, detlDto)) {
-                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
-                    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涓嶅瓨鍦�");
-                }
-                if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
-                    throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟鏈�澶х粍鎵樹笂闄愪负锛�" + mat.getUpQty());
-                }
+            //绌烘澘缁勬墭
+            if (!Cools.isEmpty(param.getPakinType()) && param.getPakinType().equals("3")) {
                 WaitPakin waitPakin = new WaitPakin();
-                BeanUtils.copyProperties(mat, waitPakin);
-                waitPakin.setBatch(detlDto.getBatch());
                 waitPakin.setZpallet(param.getBarcode());
                 waitPakin.setIoStatus("N");
-                waitPakin.setAnfme(detlDto.getAnfme());
-                waitPakin.setThreeCode(detlDto.getThreeCode());
                 waitPakin.setStatus("Y");
-                waitPakin.setSuppCode(detlDto.getStandby1());
-                waitPakin.setStandby1(detlDto.getStandby1());
-                waitPakin.setStandby2(detlDto.getStandby2());
-                waitPakin.setStandby3(detlDto.getStandby3());
-                waitPakin.setBoxType1(detlDto.getBoxType1());
-                waitPakin.setBoxType2(detlDto.getBoxType2());
-                waitPakin.setBoxType3(detlDto.getBoxType3());
                 waitPakin.setAppeUser(userId);
                 waitPakin.setAppeTime(now);
                 waitPakin.setModiUser(userId);
                 waitPakin.setModiTime(now);
                 if (!waitPakinService.insert(waitPakin)) {
                     throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+                }
+            } else {
+                if (param.getCombMats().size() < 1) {
+                    throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
+                }
+                // 鐢熸垚鍏ュ簱閫氱煡妗�
+                List<DetlDto> detlDtos = new ArrayList<>();
+                param.getCombMats().forEach(elem -> {
+                    DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
+                            elem.getStandby2(), elem.getStandby3(),
+                            elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
+                            elem.getThreeCode());
+                    if (DetlDto.has(detlDtos, detlDto)) {
+                        DetlDto one = DetlDto.findDto(detlDtos, detlDto);
+                        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涓嶅瓨鍦�");
+                    }
+                    if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
+                        throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟鏈�澶х粍鎵樹笂闄愪负锛�" + mat.getUpQty());
+                    }
+                    WaitPakin waitPakin = new WaitPakin();
+                    BeanUtils.copyProperties(mat, waitPakin);
+                    waitPakin.setBatch(detlDto.getBatch());
+                    waitPakin.setZpallet(param.getBarcode());
+                    waitPakin.setIoStatus("N");
+                    waitPakin.setAnfme(detlDto.getAnfme());
+                    waitPakin.setThreeCode(detlDto.getThreeCode());
+                    waitPakin.setStatus("Y");
+                    waitPakin.setSuppCode(detlDto.getStandby1());
+                    waitPakin.setStandby1(detlDto.getStandby1());
+                    waitPakin.setStandby2(detlDto.getStandby2());
+                    waitPakin.setStandby3(detlDto.getStandby3());
+                    waitPakin.setBoxType1(detlDto.getBoxType1());
+                    waitPakin.setBoxType2(detlDto.getBoxType2());
+                    waitPakin.setBoxType3(detlDto.getBoxType3());
+                    waitPakin.setAppeUser(userId);
+                    waitPakin.setAppeTime(now);
+                    waitPakin.setModiUser(userId);
+                    waitPakin.setModiTime(now);
+                    if (!waitPakinService.insert(waitPakin)) {
+                        throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+                    }
                 }
             }
             // 鍏宠仈缁勬墭
@@ -688,8 +718,12 @@
                 // elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
                 OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
                         .eq("order_id", order.getId())
+                        .eq("supp_code", elem.getStandby1())
                         .eq("matnr", elem.getMatnr()));
-
+                if (Objects.isNull(elem.getBoxType1())) {
+                    throw new CoolException("鏍煎眰缂栫爜涓嶈兘涓虹┖锛侊紒");
+                }
+                detls.setBoxType1(elem.getBoxType1());
                 if (Objects.isNull(detls)) {
                     throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗕笉瀛樺湪锛侊紒");
                 }
@@ -699,14 +733,14 @@
                 }
                 OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, 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(),
+                        "1", elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
+                DetlDto detlDto = new DetlDto(order.getOrderNo(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                         elem.getStandby2(), elem.getStandby3(),
                         elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
                         elem.getThreeCode());
                 detlDto.setOrderId(order.getId());
                 detlDto.setOrderNo(order.getOrderNo());
-                if (DetlDto.has(detlDtos, detlDto)) {
+                if (DetlDto.hasOrder(detlDtos, detlDto)) {
                     DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                     assert one != null;
                     one.setAnfme(one.getAnfme() + detlDto.getAnfme());
@@ -715,9 +749,16 @@
                 }
             });
 
-            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());
+            List<Mat> tempMats = new ArrayList<>();
+            for (DetlDto detlDto : detlDtos) {
+                Mat mat = matService.selectOne(new EntityWrapper<Mat>()
+                        .eq("matnr", detlDto.getMatnr())
+                        .eq("supp_code", detlDto.getStandby1()));
+                tempMats.add(mat);
+            }
+
+//            Set<String> matnrs = tempMats.stream().map(Mat::getMatnr).collect(Collectors.toSet());
+            Set<Long> tagIds = tempMats.stream().map(Mat::getTagId).collect(Collectors.toSet());
             if (tagIds.size() > 1) {
                 throw new CoolException("缁勬墭鐗╂枡绫诲瀷涓嶄竴鑷达紝鍙湁鐩稿悓鐨勭墿鏂欏垎绫绘墠鍙互缁勬墭锛侊紒");
             }
@@ -762,6 +803,7 @@
                 waitPakin.setThreeCode(detlDto.getThreeCode());
                 waitPakin.setSuppCode(detlDto.getStandby1());
                 waitPakin.setStandby1(detlDto.getStandby1());
+                waitPakin.setBoxType1(detlDto.getBoxType1());
                 waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
                 waitPakin.setAnfme(detlDto.getAnfme()); // 鏁伴噺
                 waitPakin.setStatus("Y"); // 鐘舵��
@@ -874,9 +916,9 @@
                         // todo 鐩樼偣璁板綍銆佷繚瀛樿皟鏁磋褰�
                         // 淇敼鏄庣粏
                         if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(),
-                                wrkDetl.getBatch())) {
+                                wrkDetl.getSuppCode())) {
                             throw new CoolException(wrkMast.getWrkNo() + "鐩樼偣浠诲姟锛�" + wrkDetl.getMatnr() + "鍟嗗搧锛�"
-                                    + wrkDetl.getBatch() + "鎵瑰彿淇敼鏁伴噺澶辫触");
+                                    + wrkDetl.getSuppCode() + "鎵瑰彿淇敼鏁伴噺澶辫触");
                         }
                     }
                     iterator.remove();
@@ -888,7 +930,7 @@
         // 鍒犻櫎鏄庣粏
         for (WrkDetl wrkDetl : wrkDetls) {
             // todo 鐩樼偣璁板綍銆佷繚瀛樿皟鏁磋褰�
-            if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) {
+            if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getSuppCode())) {
                 throw new CoolException("鍒犻櫎" + wrkMast.getWrkNo() + "鐩樼偣浠诲姟锛�" + wrkDetl.getMatnr() + "鍟嗗搧锛�"
                         + wrkDetl.getBatch() + "鎵瑰彿浠诲姟鏄庣粏澶辫触");
             }
@@ -991,7 +1033,7 @@
                 try {
                     response = new HttpHandler.Builder()
                             .setUri(MesConstant.URL)
-                            .setPath(MesConstant.PACK_DOWN_URL)
+                            .setPath(MesConstant.IN_DISPATCH_RESULT)
                             .setJson(JSON.toJSONString(mesCombParam))
                             .build()
                             .doPost();
@@ -999,11 +1041,11 @@
                     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,
+                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                 JSON.toJSONString(mesCombParam), response);
                         throw new CoolException(jsonObject.getString("msg"));
                     } else {
-                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.PACK_DOWN_URL,
+                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                 JSON.toJSONString(mesCombParam), response);
                         throw new CoolException("涓婃姤mes绯荤粺澶辫触");
                     }
@@ -1015,7 +1057,7 @@
                         // 淇濆瓨鎺ュ彛鏃ュ織
                         apiLogService.save(
                                 "鎵撳寘涓嬬嚎甯墭涓婃姤",
-                                MesConstant.URL + MesConstant.PACK_DOWN_URL,
+                                MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                 null,
                                 "127.0.0.1",
                                 JSON.toJSONString(mesCombParam),
@@ -1066,7 +1108,7 @@
                 // }
                 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());
+                        "1", detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme());
                 // 淇濆瓨鍏ュ簱閫氱煡妗�
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
@@ -1162,6 +1204,7 @@
                 orderDetl.setUpdateBy(userId);
                 orderDetl.setUpdateTime(now);
                 Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
+                        .eq(!Cools.isEmpty(orderDetl.getStandby1()), "supp_code", orderDetl.getStandby1())
                         .eq("matnr", orderDetl.getMatnr());
                 if (!Cools.isEmpty(orderDetl.getBatch())) {
                     wrapper.eq("batch", orderDetl.getBatch());
@@ -1179,19 +1222,19 @@
     @Override
     @Transactional
     public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
-            Double curOutQty, Integer ioType, Long userId, Date now) {
+                         Double curOutQty, Integer ioType, Long userId, Date now) {
         // 鑾峰彇搴撲綅
         LocMast locMast = locMastService.selectById(locDetl.getLocNo());
         // 鑾峰彇璺緞
-        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
-                .eq("type_no", ioType)
-                .eq("stn_no", staNo.getDevNo())
-                .eq("crn_no", locMast.getCrnNo());
-
-        StaDesc staDesc = staDescService.selectOne(wrapper);
-        if (Cools.isEmpty(staDesc)) {
-            throw new CoolException("鍑哄簱璺緞涓嶅瓨鍦�");
-        }
+//        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+//                .eq("type_no", ioType)
+//                .eq("stn_no", staNo.getDevNo())
+//                .eq("crn_no", locMast.getCrnNo());
+//
+//        StaDesc staDesc = staDescService.selectOne(wrapper);
+//        if (Cools.isEmpty(staDesc)) {
+//            throw new CoolException("鍑哄簱璺緞涓嶅瓨鍦�");
+//        }
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(2);
         // 鐢熸垚宸ヤ綔妗�
@@ -1202,8 +1245,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枡
@@ -1273,26 +1316,66 @@
         if (Objects.isNull(params.getOrgSite())) {
             throw new CoolException("婧愮珯鐐逛笉鑳戒负绌猴紒锛�");
         }
-        BasAreas basAreas = basAreasService
-                .selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
-        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>()
-                .eq("area_id", basAreas.getId())
-                .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("璇锋鏌ョ洰鏍囧簱浣嶆槸鍚﹂棽缃腑锛侊紒");
-        }
+        if (!Objects.isNull(params.getTaskType()) && params.getTaskType().equals("XM1")) {
+            String taskType = params.getTaskType();
+            generateXAgvTask(params.getOrgSite(), params.getTarSite(), userId, taskType);
+        } else {
+            String taskType = "M2";
+            if (!params.getIsNewIn().isEmpty()) {
+                taskType = "M1";
+                int cacheCount = locCacheService.selectCount(new EntityWrapper<LocCache>().eq("barcode", params.getBarcode()));
+                if (cacheCount > 0) {
+                    throw new CoolException("鍙拌溅宸插叆搴擄紝涓嶈兘鍕鹃�夋柊鍙拌溅锛侊紒");
+                }
+            }
 
-        try {
-            generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId);
-        } catch (Exception e) {
-            throw new CoolException(e.getMessage());
-        }
+            BasAreas basAreas = basAreasService
+                    .selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
+            LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>()
+                    .eq("area_id", basAreas.getId())
+                    .eq("frozen", 0)
+                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
+                    .orderAsc(Arrays.asList("loc_no"))
+                    .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+            if (Objects.isNull(locCache)) {
+                throw new CoolException("璇锋鏌ョ洰鏍囧簱浣嶆槸鍚﹂棽缃腑锛侊紒");
+            }
 
+            try {
+                generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId, taskType);
+            } catch (Exception e) {
+                throw new CoolException(e.getMessage());
+            }
+        }
         return R.ok();
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public void generateXAgvTask(String orgSite, String tarSite, Long userId, String taskType) {
+        // 鑾峰彇宸ヤ綔鍙�
+        int workNo = commonService.getWorkNo(4);
+        // 淇濆瓨宸ヤ綔妗�
+        Task task = new Task();
+        task.setWrkNo(workNo)
+                .setIoTime(new Date())
+                .setWrkSts(201L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+                .setIoType(1) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+                .setTaskType("agv")
+                .setIoPri(10D)
+                .setIsNewIn(taskType)
+                .setFullPlt("Y") // 婊℃澘锛歒
+                .setPicking("N") // 鎷f枡
+                .setExitMk("N")// 閫�鍑�
+                .setSourceStaNo(orgSite)
+                .setStaNo(tarSite)
+                .setLinkMis("N")
+                .setAppeUser(userId)
+                .setAppeTime(new Date())
+                .setModiUser(userId)
+                .setModiTime(new Date());
+        if (!taskService.insert(task)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+        }
     }
 
     /**
@@ -1306,17 +1389,12 @@
         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()));
+                        .eq(!Cools.isEmpty(params.getThreeCode()), "three_code", params.getThreeCode())
+//                .eq(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr())
+//                .eq(!Cools.isEmpty(params.getOrderNo()), "order_no", params.getOrderNo())
+        );
         if (Objects.isNull(detlPakins) || detlPakins.isEmpty()) {
             throw new CoolException("鏁版嵁閿欒锛� 鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
         }
@@ -1355,7 +1433,8 @@
                     .eq("area_id", basAreas.getId())
                     .eq("loc_no", locCache.getLocNo()));
             if (Objects.isNull(locDetls) || locDetls.isEmpty()) {
-                throw new CoolException("搴撳瓨鏄庣粏涓嶅瓨鍦紒锛�");
+                continue;
+//                throw new CoolException("搴撳瓨鏄庣粏涓嶅瓨鍦紒锛�");
             }
 
             Set<String> set = locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
@@ -1390,9 +1469,19 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R callEmptyCar(AgvCallParams params, Long userId) {
-
         BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("name", params.getOrgSite()));
+
+        BasStation station1 = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", params.getTarSite()));
+        if (Objects.isNull(station1) || Objects.isNull(basAreas)) {
+            return R.error("鐩爣绔欑偣鎴栧簱鍖轰笉瀛樺湪锛岃鑱旂郴绠$悊锛侊紒");
+        }
+
+        List<String> list = Arrays.asList("SSX01", "SSX02", "SSX03", "SSX04", "SSX05", "SSX06", "SSX07", "SSX08", "SSX09", "SSX10");
+        if (Long.parseLong(station1.getAreaId()) != basAreas.getId() && !list.contains(params.getTarSite())) {
+            return R.error("璧峰鍖哄拰鐩爣绔欑偣涓嶅湪鍚屼竴涓簱鍖猴紝璇烽噸鏂版搷浣滐紒锛�");
+        }
 
         List<LocCache> locCaches = locCacheService.selectList(new EntityWrapper<LocCache>()
                 .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
@@ -1409,20 +1498,6 @@
         }
         generateCacheOutTask(station, locCaches.get(0), userId);
 
-        // HIKApiDTO hikApiDTO =new HIKApiDTO()
-        // .setOrg(locCaches.get(0).getLocNo())
-        // .setOrgType("05")
-        // .setTar(params.getTarSite())
-        // .setTarType("05")
-        // .setTaskType("GT5")
-        // .setPriority("1")
-        // .setCtnrType("2")
-        // ;
-        // HIKResultDTO hikResultDTO = sendAgvTask(hikApiDTO,
-        // HIKApiConstant.AGV_CALL_IN_PATH);
-        // if (!hikResultDTO.isSuccess()){
-        // return R.error(hikResultDTO.getMessage());
-        // }
 
         return R.ok();
     }
@@ -1435,6 +1510,9 @@
         }
 
         BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("name", params.getTarSite()));
+        if (Objects.isNull(basAreas)) {
+            return R.error("绔欑偣涓嶅瓨鍦紝璇锋鏌ョ珯鐐规槸鍚﹁緭鍏ユ纭紒锛�");
+        }
 
         List<LocCache> locCaches = locCacheService.selectList(new EntityWrapper<LocCache>()
                 .in("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
@@ -1456,23 +1534,17 @@
 
     @Transactional(rollbackFor = Exception.class)
     public void generateSOEOInTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
-        List<BasStationDetl> basStationDetls = basStationDetlService
-                .selectList(new EntityWrapper<BasStationDetl>().eq("dev_no", orgSite));
-        if (Objects.isNull(basStationDetls) || basStationDetls.isEmpty()) {
-            throw new CoolException("绔欑偣淇℃伅涓嶅瓨鍦紒锛�");
-        }
-
         List<Task> tasks = taskService.selectList(new EntityWrapper<Task>().eq("barcode", barcode));
         if (!tasks.isEmpty()) {
             throw new CoolException("鎵樼洏宸插湪浠诲姟鎵ц涓�..");
         }
         // 鑾峰彇宸ヤ綔鍙�
-        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+        int workNo = commonService.getWorkNo(4);
         // 淇濆瓨宸ヤ綔妗�
         Task task = new Task();
         task.setWrkNo(workNo)
                 .setIoTime(new Date())
-                .setWrkSts(1L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+                .setWrkSts(201L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍏ュ簱搴揑D
                 .setIoType(1) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
                 .setTaskType("agv")
                 .setIoPri(10D)
@@ -1492,7 +1564,9 @@
             throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
         }
 
-        for (BasStationDetl basStationDetl : basStationDetls) {
+        List<BasStationDetl> basStationDetls = basStationDetlService
+                .selectList(new EntityWrapper<BasStationDetl>().eq("dev_no", orgSite));
+        basStationDetls.forEach(basStationDetl -> {
             TaskDetl wrkDetl = new TaskDetl();
             BeanUtils.copyProperties(basStationDetl, wrkDetl);
             wrkDetl.setWrkNo(workNo)
@@ -1514,36 +1588,32 @@
             if (!taskDetlService.insert(wrkDetl)) {
                 throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
             }
-        }
+        });
 
         // 淇敼鐩爣搴撲綅鐘舵��
         if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
             loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.鍏ュ簱棰勭害
             loc.setModiTime(new Date());
             loc.setModiUser(userId);
-            if (!locCacheService.updateById(loc)) {
+            if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
                 throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
             }
         } else {
             throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + loc.getLocSts$());
         }
 
-        // 淇敼鐩爣绔欑偣淇℃伅
+        // 淇敼鍘熺珯鐐逛俊鎭�
         BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
         if (Objects.isNull(station)) {
             throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
         }
 
-        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_F.type)) {
-            station.setLocSts("R"); // S.鍏ュ簱棰勭害
-            station.setBarcode(barcode);
-            station.setModiTime(new Date());
-            station.setModiUser(userId);
-            if (!basStationService.updateById(station)) {
-                throw new CoolException("鏇存柊鐩爣绔欑偣鐘舵�佸け璐�");
-            }
-        } else {
-            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+        station.setLocSts("R"); // S.鍏ュ簱棰勭害
+        station.setBarcode(barcode);
+        station.setModiTime(new Date());
+        station.setModiUser(userId);
+        if (!basStationService.updateById(station)) {
+            throw new CoolException("鏇存柊鐩爣绔欑偣鐘舵�佸け璐�");
         }
     }
 
@@ -1597,7 +1667,7 @@
     }
 
     /**
-     * 缂撳瓨鍖轰笂鏋剁粍鎵�
+     * 缂撳瓨鍖哄苟鏉夸笂鏋剁粍鎵�
      *
      * @param param
      * @param userId
@@ -1610,140 +1680,98 @@
         if (Objects.isNull(param.getBarcode())) {
             throw new CoolException("鎵樼洏鐮佷笉鑳戒负绌猴紒锛�");
         }
-
         if (Objects.isNull(param.getCombMats()) || param.getCombMats().isEmpty()) {
             throw new CoolException("缁勬墭鏄庣粏涓嶈兘涓虹┖锛侊紒");
         }
-        // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
-        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())
-                .eq("io_status", "N")) > 0) {
-            throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
+
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
+                .eq("wrk_sts", 14)
+                .eq("io_type", 104)
+                .eq("barcode", param.getBarcode()));
+        if (Objects.isNull(wrkMast)) {
+            throw new CoolException("浠诲姟妗d俊鎭笉瀛樺湪,璇锋鏌ユ墭鐩橈細" + param.getBarcode() + "浠诲姟妗f槸鍚﹀凡瀹屾垚鍑哄簱 锛侊紒");
         }
 
-        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()));
-        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()));
-        if (countWrk > 0 || countLoc > 0) {
-            WrkMast wrkDetl = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode()));
-            if (!wrkDetl.getIoType().equals(TaskIOType.MERGE_OUT.type)) {
-                throw new CoolException("缁勬墭妗�/宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
-            }
-        }
-        int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
-        if (countwait > 0) {
-            throw new CoolException("缁勬墭妗�/宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
-        }
-
-        // 鐢熸垚鍏ュ簱閫氱煡妗�
-        List<DetlDto> detlDtos = new ArrayList<>();
-        param.getCombMats().forEach(elem -> {
-            DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
-                    elem.getStandby2(), elem.getStandby3(),
-                    elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode());
-            if (DetlDto.has(detlDtos, detlDto)) {
-                DetlDto one = DetlDto.findDto(detlDtos, detlDto);
-                assert one != null;
-                one.setAnfme(one.getAnfme() + detlDto.getAnfme());
-            } else {
-                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("缁勬墭鐗╂枡绫诲瀷涓嶄竴鑷达紝鍙湁鐩稿悓鐨勭墿鏂欏垎绫绘墠鍙互缁勬墭锛侊紒");
-        }
-        // 杩樺彲浠ユ斁鍏ュ灏戠鐗╂枡
-        Double suplus = container.getMixMax();
-        Date now = new Date();
-        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() + ", 瓒呭嚭褰撳墠鎵樼洏瑁呰浇涓婇檺锛侊紒");
-            }
-
+        for (CombParam.CombMat combMat : param.getCombMats()) {
             BasStationDetl stationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
                     .eq("zpallet", param.getCarBarcode())
-                    .eq("three_code", detlDto.getThreeCode()));
+                    .eq(!Objects.isNull(combMat.getMatnr()), "matnr", combMat.getMatnr())
+                    .eq(!Objects.isNull(combMat.getThreeCode()), "three_code", combMat.getThreeCode()));
             if (Objects.isNull(stationDetl)) {
                 throw new CoolException("鏄庣粏鍐呭涓嶅瓨鍦紒锛�");
             }
+            WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>()
+                    .eq("matnr", stationDetl.getMatnr())
+                    .eq("wrk_no", wrkMast.getWrkNo())
+                    .eq("supp_code", stationDetl.getSuppCode()));
 
-            Double v = Math.round((stationDetl.getAnfme() - stationDetl.getWorkQty()) * 10000) / 10000.0;
-            if (detlDto.getAnfme().compareTo(v) > 0) {
-                throw new CoolException("缁勬墭涓婇檺涓猴細" + stationDetl.getAnfme() + ", 宸茬粍鎵橈細" + stationDetl.getWorkQty() + ", 杩樺彲缁勬墭锛�" + v);
-            }
+            if (Objects.isNull(wrkDetl)) {
+                //TODO 鏂版彃鍏�
+                Mat mat = matService.selectOne(new EntityWrapper<Mat>()
+                        .eq("matnr", stationDetl.getMatnr())
+                        .eq("supp_code", combMat.getSuppCode()));
+                if (Objects.isNull(mat)) {
+                    throw new CoolException("鐗╂枡鍩虹淇℃伅宸蹭笉瀛樺湪锛侊紒");
+                }
+                WrkDetl detl = new WrkDetl();
+                BeanUtils.copyProperties(stationDetl, detl);
+                detl.setAnfme(combMat.getAnfme());
+                detl.setBarcode(wrkMast.getBarcode());
+                detl.setZpallet(param.getBarcode());
+                detl.setBoxType1(param.getBoxType1());
+                detl.setStandby1(combMat.getSuppCode());
+                detl.setThreeCode(combMat.getThreeCode());
+                detl.setAdjustQty(combMat.getAdjustQty());
+                detl.setSplusQty(combMat.getSplusQty());
+                detl.setWrkNo(wrkMast.getWrkNo());
 
-            WaitPakin waitPakin = new WaitPakin();
-            BeanUtils.copyProperties(mat, waitPakin);
-            waitPakin.setBatch(detlDto.getBatch());
-            waitPakin.setType(param.getType());
-            waitPakin.setZpallet(param.getBarcode());
-            // 璁剧疆缁勬墭绫诲瀷
-            waitPakin.setType(param.getType());
-            waitPakin.setIoStatus("N");
-            waitPakin.setAnfme(detlDto.getAnfme());
-            waitPakin.setThreeCode(detlDto.getThreeCode());
-            waitPakin.setStatus("Y");
-            waitPakin.setSuppCode(detlDto.getStandby1());
-            waitPakin.setStandby1(detlDto.getStandby1());
-            waitPakin.setStandby2(detlDto.getStandby2());
-            waitPakin.setStandby3(detlDto.getStandby3());
-            waitPakin.setBoxType1(detlDto.getBoxType1());
-            waitPakin.setBoxType2(detlDto.getBoxType2());
-            waitPakin.setBoxType3(detlDto.getBoxType3());
-            waitPakin.setAppeUser(userId);
-            waitPakin.setAppeTime(now);
-            waitPakin.setModiUser(userId);
-            waitPakin.setModiTime(now);
-            if (!waitPakinService.insert(waitPakin)) {
-                throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
-            }
-
-            Double v1 = Math.round((stationDetl.getWorkQty() + detlDto.getAnfme()) * 10000) / 10000.0;
-            stationDetl.setWorkQty(v1);
-
-            if (!basStationDetlService.updateById(stationDetl)) {
-                throw new CoolException("绔欑偣鏄庣粏淇敼澶辫触");
-            }
-
-            if (v1.compareTo(stationDetl.getAnfme()) >= 0) {
-                if (!basStationDetlService.deleteById(stationDetl)) {
-                    throw new CoolException("鍘熷鏁版嵁绉婚櫎澶辫触锛�");
+                if (!wrkDetlService.insert(detl)) {
+                    throw new CoolException("浠诲姟鏄庣粏淇濆瓨澶辫触锛侊紒");
+                }
+            } else {
+                if (Objects.isNull(combMat.getAnfme())) {
+                    throw new CoolException("鏁伴噺涓嶈兘涓虹┖锛侊紒");
+                }
+                double val = Math.round((combMat.getAnfme() + wrkDetl.getAnfme()) * 10000) / 10000.0;
+                WrkDetl detl = new WrkDetl();
+                detl.setOrderNo(stationDetl.getOrderNo());
+                detl.setBoxType1(param.getBoxType1());
+                detl.setZpallet(param.getBarcode());
+                detl.setBarcode(param.getBarcode());
+                detl.setThreeCode(combMat.getThreeCode());
+                detl.setStandby1(combMat.getSuppCode());
+                detl.setAdjustQty(combMat.getAdjustQty());
+                detl.setSplusQty(combMat.getSplusQty());
+                detl.setAnfme(val);
+                detl.setModiTime(new Date());
+                if (!wrkDetlService.update(detl, new EntityWrapper<WrkDetl>()
+                        .eq("wrk_no", wrkMast.getWrkNo())
+                        .eq("supp_code", stationDetl.getSuppCode())
+                        .eq("matnr", stationDetl.getMatnr()))) {
+                    throw new CoolException(wrkMast.getWrkNo() + "鐩樼偣浠诲姟锛�" + wrkDetl.getMatnr() + "鍟嗗搧锛�"
+                            + wrkDetl.getBatch() + "鎵瑰彿淇敼鏁伴噺澶辫触");
                 }
             }
 
-            List<BasStationDetl> stas = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>()
-                    .eq("dev_no", stationDetl.getDevNo()));
-            if (Objects.isNull(stas) || stas.isEmpty()) {
-                BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", stationDetl.getDevNo()));
-                if (Objects.isNull(station)) {
-                    throw new CoolException("鏁版嵁閿欒锛岀珯鐐逛笉瀛樺湪锛侊紒");
-                }
-                station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
-                station.setBarcode("");
-                if (!basStationService.updateById(station)) {
-                    throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+            BasStationDetl stationDetl1 = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
+                    .eq("zpallet", param.getCarBarcode())
+                    .eq("three_code", combMat.getThreeCode()));
+
+            if (!Objects.isNull(stationDetl1)) {
+                Double v = Math.round((stationDetl1.getAnfme() - combMat.getAnfme()) * 10000) / 10000.0;
+                if (v.compareTo(0.0) == 0) {
+                    if (!basStationDetlService.delete(new EntityWrapper<BasStationDetl>()
+                            .eq("zpallet", param.getCarBarcode())
+                            .eq("three_code", combMat.getThreeCode()))) {
+                        throw new CoolException("绔欑偣淇℃伅鏇存柊澶辫触锛侊紒");
+                    }
+                } else {
+                    stationDetl1.setAnfme(v);
+                    if (!basStationDetlService.update(stationDetl1, new EntityWrapper<BasStationDetl>()
+                            .eq("zpallet", param.getCarBarcode())
+                            .eq("three_code", combMat.getThreeCode()))) {
+                        throw new CoolException("绔欑偣淇℃伅鏇存柊澶辫触锛侊紒");
+                    }
                 }
             }
         }
@@ -1759,61 +1787,84 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void combInPub(CompleteParam param, Long userId) {
+    public R combInPub(CompleteParam param, Long userId) {
         if (Objects.isNull(param.getBarcode())) {
             throw new CoolException("鎵樼洏鐮佷笉鑳戒负绌猴紒锛�");
         }
-        if (Objects.isNull(param.getStation())) {
+        if (Objects.isNull(param.getSourceStaNo())) {
             throw new CoolException("绔欑偣涓嶈兘涓虹┖!!");
         }
-//        // TODO 淇敼缂撳瓨绔欑偣鐘舵�佸強鏁版嵁
-//        Task task = taskService.selectOne(new EntityWrapper<Task>()
-//                .eq("wrk_sts", 14L)
-//                .eq("barcode", param.getCarBarcode()));
-//        if (Objects.isNull(task)) {
-//            throw new CoolException("鏁版嵁閿欒,浠诲姟涓嶅瓨鍦�!!");
-//        }
-//        List<TaskDetl> taskDetls = taskDetlService
-//                .selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo()));
-//        if (Objects.isNull(taskDetls) || taskDetls.isEmpty()) {
-//            throw new CoolException("鏁版嵁閿欒,浠诲姟鏄庣粏涓嶅瓨鍦�!!");
-//        }
-
-        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
-                .eq("dev_no", param.getStation()));
-        if (Objects.isNull(station)) {
-            throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
+        if (Objects.isNull(param.getLocType1())) {
+            param.setLocType1((short) 1);
         }
 
-        station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
-        station.setBarcode("");
-        if (!basStationService.updateById(station)) {
-            throw new CoolException("绔欑偣鐘舵�佷慨鏀瑰け璐�!");
-        }
-        basStationDetlService.delete(new EntityWrapper<BasStationDetl>().eq("dev_no", station.getDevNo()));
-
-//        // 浠诲姟瀹屾垚
-//        task.setWrkSts(15L);
-//
-//        if (!taskService.updateById(task)) {
-//            throw new CoolException("AGV浠诲姟瀹屾垚澶辫触!!");
-//        }
-
-        List<WaitPakin> waitPakins = waitPakinService
-                .selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
-        if (Objects.isNull(waitPakins) || waitPakins.isEmpty()) {
-            throw new CoolException("鏁版嵁閿欒,缁勬嫋妗e凡涓嶅瓨鍦�!!");
+        BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
+        if (Objects.isNull(container)) {
+            throw new CoolException("瀹瑰櫒缂栫爜鏈淮鎶わ紝璇风淮鎶ゅ悗鍐嶆搷浣滐紒锛�");
         }
 
-        generateCrnInTask(waitPakins, station, param.getLocType1(), userId);
+        Integer whsType = 1;
+        Short lcoType = 1;
+        //鐢ㄤ簬鍒ゆ柇鏂欑鎵樼洏锛屾枡绠憋紝绗兼
+        if (!container.getType().equals(ContainerType.CONTAINER_TYPE_BOX.type)) {
+            whsType = 2;
+            if (container.getType().equals(ContainerType.CONTAINER_TYPE_SALVER.type)) {
+                lcoType = 2;
+            }
+        }
+
+        WrkMast barcode = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode()));
+        if (!Objects.isNull(barcode) && (barcode.getIoType() == 104 || barcode.getIoType() == 103 || barcode.getIoType() == 107) && barcode.getWrkSts() == 14L) {
+            //
+            workService.pickWrkMast(barcode.getWrkNo() + "", userId);
+
+            Map<String, Object> response = new HashMap<>();
+            response.put("taskNo", barcode.getWrkNo());
+            response.put("locNo", barcode.getLocNo());
+            response.put("taskPri", barcode.getIoPri());
+
+            return R.ok("浠诲姟鐢熸垚鎴愬姛").add(response);
+        } else {
+            log.info("WCS浠诲姟鐢熸垚璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(param));
+
+            BasDevp station = basDevpService.selectOne(new EntityWrapper<BasDevp>()
+                    .eq("dev_no", param.getSourceStaNo()));
+            if (Objects.isNull(station)) {
+                throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
+            }
+            Map<String, Object> response = new HashMap<>();
+
+            if (Objects.isNull(barcode)) {
+                List<WaitPakin> waitPakins = waitPakinService
+                        .selectList(new EntityWrapper<WaitPakin>()
+                                .eq("io_status", "N")
+                                .eq("zpallet", param.getBarcode()));
+                if (Objects.isNull(waitPakins) || waitPakins.isEmpty()) {
+                    throw new CoolException("鏁版嵁閿欒,缁勬嫋妗e凡涓嶅瓨鍦�!!");
+                }
+
+                WrkMast wrkMast = generateCrnInTask(waitPakins, whsType, station, lcoType, userId);
+
+                response.put("taskNo", wrkMast.getWrkNo());
+                response.put("locNo", wrkMast.getLocNo());
+                response.put("taskPri", wrkMast.getIoPri());
+            } else {
+                response.put("taskNo", barcode.getWrkNo());
+                response.put("locNo", barcode.getLocNo());
+                response.put("taskPri", barcode.getIoPri());
+            }
+
+            return R.ok("浠诲姟鐢熸垚鎴愬姛").add(response);
+        }
     }
 
     /**
      * SO/EO 鍖虹粍鎵�
-     * @author Ryan
-     * @date 2025/12/18 15:19
+     *
      * @param params
      * @return com.core.common.R
+     * @author Ryan
+     * @date 2025/12/18 15:19
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -1832,6 +1883,12 @@
         if (Cools.isEmpty(basStation)) {
             throw new CoolException("璇疯緭鍏ユ纭殑绔欑偣鍙�");
         }
+
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", params.getOrgBarcode()));
+        if (Objects.isNull(wrkMast)) {
+            throw new CoolException("鍑哄簱浠诲姟妗d俊鎭笉瀛樺湪锛侊紒");
+        }
+
         for (CollectionPakinParams.CombMat combMat : params.getCombMats()) {
             if (combMat.getWorkQty().compareTo(BigDecimal.ZERO) == 0) {
                 continue;
@@ -1847,8 +1904,23 @@
             BasStationDetl basStationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
                     .eq("dev_no", basStation.getDevNo())
                     .eq("matnr", combMat.getMatnr())
-                    .eq("batch", combMat.getBatch())
-                    .eq("standby1", combMat.getStandby1()));
+                    .eq("order_no", combMat.getOrderNo())
+                    .eq(!Cools.isEmpty(combMat.getBatch()), "batch", combMat.getBatch())
+                    .eq(!Cools.isEmpty(combMat.getStandby1()), "standby1", combMat.getStandby1()));
+
+
+            Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>()
+                    .eq("wrk_no", wrkMast.getWrkNo())
+                    .eq("matnr", combMat.getMatnr())
+                    .eq("supp_coode", combMat.getStandby1());
+////                    .eq(!Objects.isNull(params.getBoxType1()), "boxType1", params.getBoxType1())
+//
+//            if (!Objects.isNull(params.getBoxType1())) {
+//                wrapper.eq("box_type1", params.getBoxType1());
+//            }
+
+//            WrkDetl wrkDetl = wrkDetlService.selectOne(wrapper);
+
             if (Cools.isEmpty(basStationDetl)) {
                 basStationDetl = new BasStationDetl();
                 Mat mat = matService.selectByMatnr(combMat.getMatnr());
@@ -1860,9 +1932,14 @@
                         .setBarcode(params.getTarBarcode())
                         .setZpallet(params.getTarBarcode())
                         .setBatch(combMat.getBatch())
+                        .setBoxType1(params.getBoxType1())
                         .setSuppCode(combMat.getStandby1())
                         .setStandby1(combMat.getStandby1())
                         .setAnfme(combMat.getWorkQty().doubleValue());
+
+//                if (!Objects.isNull(wrkDetl) && !wrkDetl.getMatnr().equals(combMat.getMatnr())) {
+//                    throw new CoolException("璇锋鏌ラ殧灞傛槸鍚︾粦瀹氭纭紒锛�");
+//                }
                 if (!basStationDetlService.insert(basStationDetl)) {
                     throw new CoolException("鎻掑叆鏄庣粏澶辫触");
                 }
@@ -1890,8 +1967,8 @@
         OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
                 .eq("order_id", orderPakin.getId())
                 .eq("matnr", combMat.getMatnr())
-                .eq("batch", combMat.getBatch())
-                .eq("standby1", combMat.getStandby1()));
+                .eq(!Cools.isEmpty(combMat.getBatch()), "batch", combMat.getBatch())
+                .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1()));
         if (Cools.isEmpty(orderDetlPakin)) {
             throw new CoolException("妫�绱㈠崟鎹槑缁嗘暟鎹け璐�");
         }
@@ -1914,7 +1991,6 @@
 
     @Override
     public R collectionPakinView(CollectionPakinParams params) {
-
         WrkMast wrkMast = wrkMastService.selectByBarcode(params.getOrgBarcode());
         if (Cools.isEmpty(wrkMast)) {
             throw new CoolException("鏈壘鍒颁换鍔�");
@@ -1922,10 +1998,15 @@
 
         if (wrkMast.getIoType().equals(TaskIOType.ALL_OUT.type)
                 && wrkMast.getIoType().equals(TaskIOType.PICK_OUT.type)) {
-            throw new CoolException("浜虹墿绫诲瀷閿欒");
+            throw new CoolException("浠诲姟绫诲瀷閿欒");
         }
 
-        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
+        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>()
+                .like(!Objects.isNull(params.getMatnr()), "matnr", params.getMatnr())
+                .eq(!Objects.isNull(params.getBoxType1()), "box_type1", params.getBoxType1())
+                .eq("wrk_no", wrkMast.getWrkNo()));
+
+//        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
         if (Cools.isEmpty(wrkDetls)) {
             throw new CoolException("鏈壘鍒颁换鍔℃槑缁�");
         }
@@ -1936,23 +2017,24 @@
     /**
      * 鐢熸垚鍫嗗灈鏈哄叆搴撲换鍔�
      *
+     * @param whsType
      * @param station
      * @author Ryan
      * @date 2025/12/9 13:54
      */
     @Transactional(rollbackFor = Exception.class)
-    public void generateCrnInTask(List<WaitPakin> waitPakins, BasStation station, Short locType, Long userId) {
+    public WrkMast generateCrnInTask(List<WaitPakin> waitPakins, Integer whsType, BasDevp station, Short locType, Long userId) {
         Date now = new Date();
-        StationRela rela = stationRelaService.selectOne(new EntityWrapper<StationRela>()
-                .eq("agv_sta", station.getDevNo())
-                .orderAsc(Arrays.asList("crn_sta"))
-                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+//        StationRela rela = stationRelaService.selectOne(new EntityWrapper<StationRela>()
+//                .eq("agv_sta", station.getDevNo())
+//                .orderAsc(Arrays.asList("crn_sta"))
+//                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+//
+//        if (Objects.isNull(rela)) {
+//            throw new CoolException("鏈粦瀹氫綔涓氱珯鐐�!!");
+//        }
 
-        if (Objects.isNull(rela)) {
-            throw new CoolException("鏈粦瀹氫綔涓氱珯鐐�!!");
-        }
-
-        BasDevp sourceStaNo = basDevpService.checkSiteStatus(Integer.parseInt(rela.getCrnSta()), true);
+        BasDevp sourceStaNo = basDevpService.checkSiteStatus(station.getDevNo(), true);
         sourceStaNo.setLocType1(locType);
         LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
         WaitPakin pakin = waitPakins.stream().findFirst().get();
@@ -1960,9 +2042,24 @@
 
         WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", pakin.getZpallet()));
         WrkMast wrkMast = new WrkMast();
+        String locNo;
         if (!Objects.isNull(mast)) {
             if (mast.getIoType().equals(TaskIOType.MERGE_OUT.type) || mast.getIoType().equals(TaskIOType.PICK_OUT.type) || mast.getIoType().equals(TaskIOType.CHECK_OUT.type)) {
                 int ioType = mast.getIoType() - 50;
+
+                List<WrkDetl> wrkDetls103 = wrkDetlService
+                        .selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
+                if (wrkDetls103.isEmpty()) {
+                    ioType = 10;
+                }
+                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()));
+                if (!Objects.isNull(locDetls) && !locDetls.isEmpty()) {
+                    Double sum = wrkDetls103.stream().mapToDouble(WrkDetl::getAnfme).sum();
+                    Double summed = locDetls.stream().mapToDouble(LocDetl::getAnfme).sum();
+                    if (summed.compareTo(sum) <= 0) {
+                        ioType = 10;
+                    }
+                }
                 mast.setIoType(ioType);
                 mast.setWrkSts(2L);
                 mast.setSourceStaNo(mast.getSourceStaNo());
@@ -1973,6 +2070,7 @@
                 if (!res) {
                     throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
                 }
+                locNo = mast.getLocNo();
                 // 鏇存柊婧愮珯鐐逛俊鎭�
                 sourceStaNo.setWrkNo(mast.getWrkNo());
                 sourceStaNo.setModiTime(now);
@@ -1993,8 +2091,10 @@
             } else {
                 throw new CoolException("鎵樼洏宸插瓨鍦ㄤ换鍔℃。锛侊紒");
             }
+
         } else {
-            StartupDto dto = commonService.getLocNo(1, sourceStaNo.getDevNo(), findLocNoAttributeVo, locTypeDto);
+            StartupDto dto = commonService.getLocNo(1, sourceStaNo.getDevNo(), whsType, findLocNoAttributeVo, locTypeDto);
+
             int workNo = dto.getWorkNo();
             // 鐢熸垚宸ヤ綔妗�
             wrkMast.setWrkNo(workNo);
@@ -2003,7 +2103,7 @@
             wrkMast.setIoType(1); // 鍏ュ嚭搴撶姸鎬侊細1.鍏ュ簱
             wrkMast.setCrnNo(dto.getCrnNo());
             wrkMast.setSourceStaNo(dto.getSourceStaNo() + "");
-            wrkMast.setStaNo(dto.getStaNo() + "");
+            wrkMast.setStaNo(!Objects.isNull(dto.getStaNo()) ? dto.getStaNo() + "" : null);
             wrkMast.setLocNo(dto.getLocNo());
             wrkMast.setIoPri(13D); // 浼樺厛绾�
             wrkMast.setBarcode(pakin.getZpallet()); // 鎵樼洏鐮�
@@ -2022,6 +2122,7 @@
             if (!res) {
                 throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
             }
+            locNo = dto.getLocNo();
             // 鏇存柊婧愮珯鐐逛俊鎭�
             sourceStaNo.setWrkNo(workNo);
             sourceStaNo.setModiTime(now);
@@ -2043,29 +2144,36 @@
 
         // 鐢熸垚宸ヤ綔妗f槑缁�
         waitPakins.forEach(waitPakin -> {
-            WrkDetl wrkDetl = new WrkDetl();
-            wrkDetl.sync(waitPakin);
-            wrkDetl.setWrkNo(wrkMast.getWrkNo());
-            wrkDetl.setIoTime(wrkMast.getIoTime());
-            wrkDetl.setAppeTime(now);
-            wrkDetl.setModiTime(now);
-            if (!wrkDetlService.insert(wrkDetl)) {
-                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触");
+            if (!Objects.isNull(waitPakin.getMatnr())) {
+                WrkDetl wrkDetl = new WrkDetl();
+                wrkDetl.sync(waitPakin);
+                wrkDetl.setWrkNo(wrkMast.getWrkNo());
+                wrkDetl.setIoTime(wrkMast.getIoTime());
+                wrkDetl.setAppeTime(now);
+                wrkDetl.setModiTime(now);
+                if (!wrkDetlService.insert(wrkDetl)) {
+                    throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触");
+                }
+            } else {
+                wrkMast.setWrkSts(2L);
+                wrkMast.setIoType(10);
+                wrkMastService.updateById(wrkMast);
             }
         });
 
+        // 鏇存柊鍏ュ簱閫氱煡妗� ioStatus ===>> Y
+        Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
+                .eq("zpallet", pakin.getZpallet());
 
+        WaitPakin setParam = new WaitPakin();
+        setParam.setLocNo(locNo);
+        setParam.setIoStatus("Y");
+        setParam.setModiTime(now);
+        if (!waitPakinService.update(setParam, wrapper)) {
+            throw new CoolException("鏇存柊閫氱煡妗eけ璐�");
+        }
 
-//        // 鏇存柊鍏ュ簱閫氱煡妗� ioStatus ===>> Y
-//        Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
-//                .eq("zpallet", pakin.getZpallet());
-//        WaitPakin setParam = new WaitPakin();
-//        setParam.setLocNo(dto.getLocNo());
-//        setParam.setIoStatus("Y");
-//        setParam.setModiTime(now);
-//        if (!waitPakinService.update(setParam, wrapper)) {
-//            throw new CoolException("鏇存柊閫氱煡妗eけ璐�");
-//        }
+        return wrkMast;
     }
 
     /**
@@ -2137,7 +2245,16 @@
         AtomicReference<Double> totalOut = new AtomicReference<>(0.0);
         listMap.forEach((matnr, detls) -> {
             Map<String, List<LocDetl>> supIds = detls.stream().collect(Collectors.groupingBy(LocDetl::getStandby1));
-            supIds.forEach((supId, sups) -> {
+            for (String supId : supIds.keySet()) {
+                List<LocDetl> sups = supIds.get(supId);
+//            }
+//            supIds.forEach((supId, sups) -> {
+                Mat mats = matService.selectOne(new EntityWrapper<Mat>()
+                        .eq("supp_code", supId)
+                        .eq("matnr", matnr));
+                if (Objects.isNull(mats)) {
+                    throw new CoolException("鐗╂枡涓嶅瓨鍦紒锛�");
+                }
                 // 鏍规嵁supId(渚涘簲鍟�)鍒嗙被锛屽緱鍒伴渶瑕佸瓨鏀剧殑鎬荤┖搴撳瓨鏁伴噺
                 Double sum = sups.stream().mapToDouble(LocDetl::getAnfme).sum();
                 AtomicReference<Double> itemed = new AtomicReference<>(0.0);
@@ -2165,10 +2282,6 @@
                         if (container.getMixMax() > sets.size()) {
                             //浣欎笅鍙贩鏀剧绫�
                             long suplus = Math.round((container.getMixMax() - sets.size()) * 10000) / 10000;
-                            Mat mats = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", matnr));
-                            if (Objects.isNull(mats)) {
-                                throw new CoolException("鐗╂枡涓嶅瓨鍦紒锛�");
-                            }
                             //浣欎笅鏈�澶у彲鏀炬暟閲�
                             Double v = Math.round((mats.getUpQty() * suplus) * 10000) / 10000.0;
                             // 鍏ュ簱鏁伴噺灏忎簬闆朵笖鍏ュ簱鏁伴噺鍑忓幓宸茶鍒掑嚭鏁伴噺澶т簬闆讹紙锛�
@@ -2181,24 +2294,85 @@
                             }
                         }
                     });
+                } else {
+                    // 鑾峰彇褰撳墠渚涘簲鍟�+ 鐗╂枡鍦ㄥ簱
+                    LocMast notFullList = locMastService.selectNotFull(mats.getLocType(), one.getId());
+                    if (Objects.isNull(notFullList)) {
+                        continue;
+                    }
+                    BasContainer container = basContainerService
+                            .selectOne(new EntityWrapper<BasContainer>().eq("barcode", notFullList.getBarcode()));
+                    if (Objects.isNull(container)) {
+                        throw new CoolException("鏁版嵁閿欒锛屽鍣ㄤ笉瀛樺湪锛侊紒");
+                    }
+                    List<LocDetl> adetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", notFullList.getLocNo()));
+                    Set<String> sets = adetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
+                    List<LocDetl> locDtls = new ArrayList<>();
+                    // 鍒ゆ柇瀹瑰櫒鏄惁杩樺彲娣锋斁,鍙婂綋鍓嶇墿鏂欏彲鏀惧灏�
+                    if (container.getMixMax() > sets.size()) {
+                        //浣欎笅鍙贩鏀剧绫�
+                        long suplus = Math.round((container.getMixMax() - sets.size()) * 10000) / 10000;
+                        //浣欎笅鏈�澶у彲鏀炬暟閲�
+                        Double v = Math.round((mats.getUpQty() * suplus) * 10000) / 10000.0;
+                        // 鍏ュ簱鏁伴噺灏忎簬闆朵笖鍏ュ簱鏁伴噺鍑忓幓宸茶鍒掑嚭鏁伴噺澶т簬闆讹紙锛�
+                        if (sum.compareTo(v) <= 0 && sum.compareTo(itemed.get()) > 0) {
+                            itemed.set(Math.round((itemed.get() + v) * 10000) / 10000.0);
+                            // 鍙斁涓�
+                            LocDetl locDetl = new LocDetl();
+                            BeanUtils.copyProperties(mats, locDetl);
+                            locDetl.setLocNo(notFullList.getLocNo());
+                            locDetl.setAnfme(0.0);
+                            locDetl.setMatnr(mats.getMatnr());
+                            locDetl.setZpallet(notFullList.getBarcode());
+                            locDetl.setSuppCode(mats.getSuppCode());
+                            locDetl.setMaktx(mats.getMaktx());
+                            locDtls.add(locDetl);
+                            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(notFullList.getLocNo()).setLocDetlList(locDtls);
+                            locMasts.add(crnTaskDetlDTO);
+                            totalOut.set(Math.round((totalOut.get() + itemed.get()) * 10000) / 10000.0);
+                        }
+                    }
                 }
-            });
+            }
         });
 
-        // 鍒ゆ柇鏍规嵁鍒嗘嫞鍑哄簱鍚�,杩橀渶瑕佸嚭澶氬皯鎵樼洏鎴栨枡绠�;濡傛灉浣欐枡澶т簬0, 鍑烘柊鎵樼洏鎴栨枡绠�
-        if (totalOut.get().compareTo(0.0) > 0) {
-            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
-            //TODO 缁嗗寲鍖哄垎锛屽綋鍓嶅嚭搴撴墭鐩樻槸婊¤冻鎷h揣鏁伴噺
-        } else {
+        /**鏄惁浼樺厛绌烘澘鍑哄簱*/
+        Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "OutStockOrderByEmpty"));
+        if (!Objects.isNull(config) && Boolean.parseBoolean(config.getValue())) {
             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                     // todo 鏍规嵁鐗╂枡绉嶇被,鍖哄垎搴撳尯绫诲瀷
                     .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
                     .orderAsc(Arrays.asList("row1", "bay1", "lev1"))
                     .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
-            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(locDetls);
+
+            if (Objects.isNull(locMast)) {
+                throw new CoolException("鏈煡璇㈠埌鍙敤鐨勭┖鏉夸俊鎭紒锛�");
+            }
+            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(new ArrayList<>());
             locMasts.add(crnTaskDetlDTO);
             // 绌烘澘鍑哄簱
             generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
+        } else {
+            // 鍒ゆ柇鏍规嵁鍒嗘嫞鍑哄簱鍚�,杩橀渶瑕佸嚭澶氬皯鎵樼洏鎴栨枡绠�;濡傛灉浣欐枡澶т簬0, 鍑烘柊鎵樼洏鎴栨枡绠�
+            if (totalOut.get().compareTo(0.0) > 0) {
+                generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
+                //TODO 缁嗗寲鍖哄垎锛屽綋鍓嶅嚭搴撴墭鐩樻槸婊¤冻鎷h揣鏁伴噺
+            } else {
+                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                        // todo 鏍规嵁鐗╂枡绉嶇被,鍖哄垎搴撳尯绫诲瀷
+                        .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
+                        .orderAsc(Arrays.asList("row1", "bay1", "lev1"))
+                        .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+
+                if (Objects.isNull(locMast)) {
+                    throw new CoolException("鏈煡璇㈠埌鍙敤鐨勭┖鏉夸俊鎭紒锛�");
+                }
+                CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(new ArrayList<>());
+                locMasts.add(crnTaskDetlDTO);
+
+                // 绌烘澘鍑哄簱
+                generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
+            }
         }
     }
 
@@ -2222,7 +2396,7 @@
             WrkMast wrkMast1 = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_loc_no", locMast.getLocNo()));
             // 鐢熸垚宸ヤ綔鍙�
             int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
-            if (Cools.isEmpty(wrkMast1)){
+            if (Cools.isEmpty(wrkMast1)) {
                 Integer outSta = devp.getDevNo();
                 // 鑾峰彇璺緞
                 StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta);
@@ -2235,7 +2409,7 @@
                 wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶被鍨�
                 wrkMast.setIoPri(13D); // 浼樺厛绾э細13
                 wrkMast.setCrnNo(locMast.getCrnNo());
-                wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 婧愮珯
+//                wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 婧愮珯
                 wrkMast.setStaNo(staDesc.getStnNo() + ""); // 鐩爣绔�
                 wrkMast.setSourceLocNo(locMast.getLocNo()); // 婧愬簱浣�
                 //灏忔澗椤圭洰锛岀紦瀛樺嚭搴揂GV绔欑偣锛岀敤浜庢竻绌虹紦瀛樺尯搴撳瓨
@@ -2254,14 +2428,13 @@
                 if (!wrkMastService.insert(wrkMast)) {
                     throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鍑哄簱搴撲綅鍙凤細" + locMast.getLocNo());
                 }
-            }else {
+            } else {
                 workNo = wrkMast1.getWrkNo();
             }
             // 鐢熸垚宸ヤ綔妗f槑缁�
             for (LocDetl detlDto : crnTaskDetlDTO.getLocDetlList()) {
                 WrkDetl wrkDetl = new WrkDetl();
                 BeanUtils.copyProperties(detlDto, wrkDetl);
-                wrkDetl.setOrderNo(""); // 鎵嬪姩鍑哄簱涓嶉渶瑕佸甫鍑哄簱瀛樹腑鐨勫崟鎹紪鍙�
                 wrkDetl.setWrkNo(workNo);
                 wrkDetl.setIoTime(now);
                 wrkDetl.setZpallet(null);
@@ -2299,7 +2472,7 @@
     @Transactional(rollbackFor = Exception.class)
     public void generateCacheOutTask(BasStation station, LocCache loc, Long userId) {
         // 鑾峰彇宸ヤ綔鍙�
-        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+        int workNo = commonService.getWorkNo(4);
         // 淇濆瓨宸ヤ綔妗�
         Task task = new Task();
         task.setWrkNo(workNo)
@@ -2356,9 +2529,10 @@
         loc.setModiUser(userId);
         loc.setModiTime(new Date());
 
-        if (!locCacheService.updateById(loc)) {
-            throw new CoolException("鏇存柊搴撲綅鐘舵�佷俊鎭紒锛�");
-        }
+//        if (!) {
+//            throw new CoolException("鏇存柊搴撲綅鐘舵�佷俊鎭紒锛�");
+//        }
+        locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()));
 
         // 淇敼鐩爣绔欑偣淇℃伅
         if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
@@ -2369,7 +2543,8 @@
                 throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
             }
         } else {
-            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+            log.error("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+//            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
         }
     }
 
@@ -2380,21 +2555,22 @@
      * @version 1.0
      */
     @Transactional(rollbackFor = Exception.class)
-    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
+    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId, String isNewIn) {
         List<Task> tasks = taskService.selectList(new EntityWrapper<Task>().eq("barcode", barcode));
         if (!tasks.isEmpty()) {
             throw new CoolException("鎵樼洏宸插湪浠诲姟鎵ц涓�..");
         }
         // 鑾峰彇宸ヤ綔鍙�
-        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+        int workNo = commonService.getWorkNo(4);
         // 淇濆瓨宸ヤ綔妗�
         Task task = new Task();
         task.setWrkNo(workNo)
                 .setIoTime(new Date())
                 .setWrkSts(201L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
                 .setIoType(1) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
-                .setTaskType("agv")
+                .setTaskType(type)
                 .setIoPri(10D)
+                .setIsNewIn(isNewIn)
                 .setLocNo(loc.getLocNo()) // 鐩爣搴撲綅
                 .setFullPlt("Y") // 婊℃澘锛歒
                 .setPicking("N") // 鎷f枡
@@ -2436,7 +2612,6 @@
                 if (!taskDetlService.insert(wrkDetl)) {
                     throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
                 }
-
             }
 
             for (WaitPakin pakin : pakins) {
@@ -2445,28 +2620,27 @@
                     throw new CoolException("鏇存柊缁勬墭淇℃伅澶辫触");
                 }
             }
-        }
 
-        // 淇敼鐩爣搴撲綅鐘舵��
-        if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
-            loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.鍏ュ簱棰勭害
-            loc.setModiTime(new Date());
-            loc.setModiUser(userId);
-            if (!locCacheService.updateById(loc)) {
-                throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+            // 淇敼鐩爣搴撲綅鐘舵��
+            if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+                loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.鍏ュ簱棰勭害
+                loc.setModiTime(new Date());
+                loc.setModiUser(userId);
+
+                if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
+                    throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+                }
+            } else {
+                throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + loc.getLocSts$());
             }
-        } else {
-            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + loc.getLocSts$());
-        }
 
-        // 淇敼鐩爣绔欑偣淇℃伅
-        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
-        if (Objects.isNull(station)) {
-            throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
-        }
+            // 淇敼鐩爣绔欑偣淇℃伅
+            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
+            if (Objects.isNull(station)) {
+                throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
+            }
 
-        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type) || station.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)) {
-            station.setLocSts("R"); // S.鍏ュ簱棰勭害
+            station.setLocSts("R"); // R.鍏ュ簱棰勭害
             station.setBarcode(barcode);
             station.setModiTime(new Date());
             station.setModiUser(userId);
@@ -2474,7 +2648,27 @@
                 throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
             }
         } else {
-            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+            // 淇敼鐩爣搴撲綅鐘舵��
+            loc.setLocSts(LocStsType.LOC_STS_TYPE_D.type); // S.鍏ュ簱棰勭害
+            loc.setModiTime(new Date());
+            loc.setModiUser(userId);
+            if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
+                throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+            }
+
+            // 淇敼鐩爣绔欑偣淇℃伅
+            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
+            if (Objects.isNull(station)) {
+                throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
+            }
+            station.setLocSts("O");
+            station.setBarcode(barcode);
+            station.setModiTime(new Date());
+            station.setModiUser(userId);
+            if (!basStationService.updateById(station)) {
+                throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+            }
+            basStationDetlService.delete(new EntityWrapper<BasStationDetl>().eq("dev_no", station.getDevNo()));
         }
     }
 
@@ -2534,10 +2728,11 @@
 
     /**
      * 鍛煎彨AGV绌哄彴杞﹁繑鍥�
-     * @author Ryan
-     * @date 2025/9/24
+     *
      * @param callAgvBackParam
      * @return com.core.common.R
+     * @author Ryan
+     * @date 2025/9/24
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -2548,7 +2743,7 @@
 
         // 鎸夊綋鍓嶆煡鎵惧簱浣嶉『搴忥紝鏌ュ埌涓�涓悗锛屼笉鍐嶅線涓嬫煡璇�
         LocCache locCache = findPriorityLocCache();
-        
+
         if (Objects.isNull(locCache)) {
             return R.error("鏈煡璇㈠埌鍙敤搴撲綅");
         }
@@ -2558,16 +2753,661 @@
         if (Objects.isNull(station)) {
             throw new CoolException("绔欑偣涓嶅瓨鍦�!!");
         }
-
         try {
             //绌哄彴杞﹀洖搴�
-            generateAgvTask("agv_back", locCache, callAgvBackParam.getOrgSite(), station.getBarcode(), userId);
+            generateAgvTask("agv_back", locCache, callAgvBackParam.getOrgSite(), station.getBarcode(), userId, "M2");
         } catch (Exception e) {
-            e.printStackTrace();
-            return R.error(e.getMessage());
+            log.error(e.getMessage());
+            throw new CoolException(e.getMessage());
         }
 
         return R.ok(locCache);
+    }
+
+    /**
+     * 绉诲簱浠诲姟鐢宠
+     *
+     * @param combParam
+     * @param userId
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R taskMove(CompleteParam combParam, long userId) {
+        if (Objects.isNull(combParam.getTaskNo())) {
+            return R.error("浠诲姟鍙蜂笉鑳戒负绌�");
+        }
+        if (Objects.isNull(combParam.getSourceLocNo())) {
+            return R.error("婧愬簱浣嶄笉鑳戒负绌猴紒锛�");
+        }
+        if (Objects.isNull(combParam.getLocNo())) {
+            return R.error("鐩爣搴撲綅涓嶈兘涓虹┖锛�");
+        }
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", combParam.getTaskNo()));
+        if (Objects.isNull(wrkMast)) {
+            return R.error("浠诲姟妗d笉瀛樺湪锛侊紒");
+        }
+
+
+        String body = JSON.toJSONString(combParam);
+        boolean success = false;
+        String response = "";
+        try {
+            response = new HttpHandler.Builder()
+                    .setUri(MesConstant.WCS_URL)
+                    .setPath(MesConstant.MOVE_LOC_TASK)
+                    .setJson(body)
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+            if (jsonObject.getInteger("code").equals(200)) {
+                wrkMast.setWrkSts(2L);
+                if (!wrkMastService.updateById(wrkMast)) {
+                    throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐ワ紒锛�");
+                }
+                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getSourceLocNo()));
+                if (!Objects.isNull(locMast)) {
+                    locMast.setMoveStatus(1);
+                    locMastService.updateById(locMast);
+                }
+                success = true;
+            } else {
+                log.error("鍙戦�乤gv浠诲姟澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.WCS_URL + MesConstant.MOVE_LOC_TASK, body, response);
+            }
+        } catch (Exception e) {
+            log.error("鍙戦�乤gv浠诲姟寮傚父", e);
+        } finally {
+            try {
+                // 淇濆瓨鎺ュ彛鏃ュ織
+                apiLogService.save(
+                        "鍙戦�乤gv浠诲姟",
+                        MesConstant.WCS_URL + MesConstant.MOVE_LOC_TASK,
+                        null,
+                        "127.0.0.1",
+                        body,
+                        response,
+                        success);
+            } catch (Exception e) {
+                log.error("", e);
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 6.15WCS鐢宠鍦ㄥ簱搴撲綅鏇存崲搴撲綅
+     *
+     * @param combParam
+     * @param l
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R changeLoc(CompleteParam combParam, long l) {
+        if (Objects.isNull(combParam)) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖锛�");
+        }
+        if (Objects.isNull(combParam.getLocNo())) {
+            return R.error("搴撲綅鍙蜂笉鑳戒负绌�!!");
+        }
+        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", combParam.getLocNo()));
+        if (Objects.isNull(locMast)) {
+            return R.error("搴撲綅淇℃伅涓嶅瓨鍦ㄦ垨搴撲綅鐘舵�侀潪 F.鍦ㄥ簱 鐘舵��");
+        }
+
+        List<Integer> doubleLocs = slaveProperties.getDoubleLocs();
+        List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                .in("row1", doubleLocs)
+                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type));
+        Map<String, Object> result = new HashMap<>();
+        LocMast selected = new LocMast();
+        for (LocMast loc : locMasts) {
+            LocMast temLoc = locMastService.selectById(loc.getLocNo());
+            if (Objects.isNull(temLoc)) {
+                throw new CoolException("鏁版嵁閿欒锛� 鍘熷簱浣嶄俊鎭笉瀛樺湪锛侊紒");
+            }
+            String shallowLoc = Utils.getShallowLoc(slaveProperties, temLoc.getLocNo());
+
+            LocMast locMast1 = locMastService.selectById(shallowLoc);
+            if (Objects.isNull(locMast1)) {
+                throw new CoolException("鏁版嵁閿欒锛� 鏂板簱浣嶄俊鎭笉瀛樺湪锛侊紒");
+            }
+            if (!locMast1.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+                continue;
+            }
+            selected = loc;
+
+            break;
+        }
+
+        WrkMast moveTask = generateMoveTask(selected, locMast);
+        result.put("locNo", selected.getLocNo());
+        result.put("taskNo", moveTask.getWrkNo());
+
+        return R.ok().add(result);
+
+    }
+
+    /**
+     * 鑾峰彇缂撳瓨绔欑偣淇℃伅
+     *
+     * @param type
+     * @return
+     */
+    @Override
+    public R getCacheSites(String type) {
+        BasAreas areas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", type));
+        if (Objects.isNull(areas)) {
+            return R.error("搴撳尯涓嶅瓨鍦紒");
+        }
+        List<BasStation> stations = basStationService.selectList(new EntityWrapper<BasStation>().eq("area_id", areas.getId()));
+        if (Objects.isNull(stations) || stations.isEmpty()) {
+            return R.error("绔欑偣涓嶅瓨鍦紒");
+        }
+        return R.ok("鏌ヨ鎴愬姛").add(stations);
+    }
+
+    /**
+     * 鑾峰彇鎹嗗寘鏄庣粏淇℃伅
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    public R getAllBindInfo(AgvCallParams params) {
+        if (Objects.isNull(params.getCarBarcode())) {
+            return R.error("鍙拌溅缂栫爜涓嶈兘涓虹┖锛�");
+        }
+        List<TaskDetl> taskDetls = taskDetlService.selectList(new EntityWrapper<TaskDetl>()
+                .eq("zpallet", params.getCarBarcode()));
+
+        taskDetls.forEach(taskDetl -> {
+            OrderPakout orderDetlPakout = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>()
+                    .eq("order_no", taskDetl.getOrderNo()));
+            taskDetl.setMemo(orderDetlPakout.getShipCode());
+        });
+
+        return R.ok("鏌ヨ鎴愬姛").add(taskDetls);
+    }
+
+    /**
+     * 鎸夊彴杞﹀嚭搴�
+     *
+     * @param params
+     * @return com.core.common.R
+     * @author Ryan
+     * @date 2026/3/28 8:41
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R outStockByTc(AgvCallParams params) {
+        if (Objects.isNull(params.getCarBarcode())) {
+            return R.error("鍙拌溅鐮佷笉鑳戒负绌猴紒锛�");
+        }
+        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("barcode", params.getCarBarcode()));
+        if (Objects.isNull(locCache)) {
+            return R.error("褰撳墠鍙拌溅涓嶅湪缂撳啿搴撳尯锛侊紒");
+        }
+        if (Objects.isNull(params.getTarSite())) {
+            return R.error("鐩爣绔欑偣涓嶈兘涓虹┖锛侊紒");
+        }
+        BasStation devNo = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", params.getTarSite()));
+        if (Objects.isNull(devNo) || !devNo.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+            return R.error("鐩爣绔欑偣蹇欑涓紒锛�");
+        }
+
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locCache.getLocNo()));
+        if (Objects.isNull(locDetls) || locDetls.isEmpty()) {
+            return R.error("鍙拌溅涓婃病鏈夊搴旀槑缁嗕俊鎭紒锛�");
+        }
+        List<LocDto> locDtos = new ArrayList<>();
+        locDetls.forEach(locDetl -> {
+            List<OrderPakout> orderPakouts = orderPakoutService.selectList(new EntityWrapper<OrderPakout>()
+                    .eq("doc_type", 5)
+                    .eq("number", locDetl.getOrderNo()));
+            if (Objects.isNull(orderPakouts) || orderPakouts.isEmpty()) {
+                throw new CoolException("鍗曟嵁淇℃伅涓嶅瓨鍦ㄦ垨宸蹭笂鎶ュ畬鎴愶紒锛�");
+            }
+            for (OrderPakout orderPakout : orderPakouts) {
+                OrderDetlPakout orderDetl = orderDetlPakoutService.selectOne(new EntityWrapper<OrderDetlPakout>()
+                        .eq("matnr", locDetl.getMatnr())
+                        .eq("supp_code", locDetl.getSuppCode())
+                        .eq("order_no", orderPakout.getOrderNo()));
+                if (Objects.isNull(orderDetl)) {
+                    continue;
+                }
+                locDetl.setMemo(orderPakout.getShipCode());
+                locDetl.setOrderNo(orderPakout.getOrderNo());
+
+                LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), locDetl.getAnfme());
+                locDto.setFrozen(locDetl.getFrozen());
+                locDto.setFrozenLoc(locCache.getFrozen());
+                locDto.setAgvStaNo(params.getTarSite());
+                locDto.setBrand(orderDetl.getBrand());
+                locDto.setSuppCode(orderDetl.getSuppCode());
+                locDto.setStandby1(orderDetl.getStandby1());
+                locDto.setStandby2(orderDetl.getStandby2());
+                locDto.setStandby3(orderDetl.getStandby3());
+                locDto.setBoxType1(orderDetl.getBoxType1());
+                locDto.setBoxType2(orderDetl.getBoxType2());
+                locDto.setBoxType3(orderDetl.getBoxType3());
+                locDtos.add(locDto);
+
+            }
+//            exist.add(locDetl.getLocNo());
+        });
+
+        generateAgvTaskByTc(locDtos);
+
+        return R.ok();
+    }
+
+    /**
+     * 鑾峰彇绔欑偣鏄庣粏淇℃伅
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    public R getStationInfos(AgvCallParams params) {
+        if (Objects.isNull(params.getOrgSite())) {
+            return R.error("绔欑偣涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getCarBarcode())) {
+            return R.error("绔欑偣鍙拌溅涓嶈兘涓虹┖锛侊紒");
+        }
+//        if (!Cools.isEmpty(params.getMatnr())) {
+//            return R.error("鐗╂枡淇℃伅涓嶈兘涓虹┖锛侊紒");
+//        }
+        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
+                .eq("dev_no", params.getOrgSite())
+                .eq("barcode", params.getCarBarcode()));
+        if (Objects.isNull(station)) {
+            throw new CoolException("鍙拌溅涓庣珯鐐圭粦瀹氬叧绯讳笉瀛樺湪锛岃鑱旂郴绠$悊鍛橈紒");
+        }
+        List<BasStationDetl> stationDetls = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>()
+                .like(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr())
+                .eq("dev_no", station.getDevNo()));
+        if (!stationDetls.isEmpty()) {
+            return R.ok().add(stationDetls);
+        }
+        return R.ok();
+    }
+
+    /**
+     * 绔欑偣鐗╂枡瑙g粦
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R unbindMatnr(CombParam params) {
+        if (Objects.isNull(params.getCombMats()) || params.getCombMats().isEmpty()) {
+            return R.error("鏄庣粏涓嶈兘涓虹┖锛侊紒");
+        }
+        for (CombParam.CombMat combMat : params.getCombMats()) {
+            if (Objects.isNull(combMat)) {
+                continue;
+            }
+            OrderPakin order = orderPakinService.selectOne(new EntityWrapper<OrderPakin>()
+                    .lt("settle", 4)
+                    .eq("order_no", combMat.getOrderNo()));
+            if (Objects.isNull(order)) {
+                return R.error("鏈煡璇㈠埌璁㈠崟锛岃纭鏄惁涓哄簱鍙g粍鎵樹俊鎭紒锛�");
+            }
+            //鍏ュ簱
+            OrderDetlPakin detlPakin = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
+                    .eq("order_no", combMat.getOrderNo())
+                    .eq("matnr", combMat.getMatnr())
+                    .eq("supp_code", combMat.getStandby1())
+                    .last("AND anfme != qty"));
+
+            if (!Objects.isNull(detlPakin)) {
+                Double v = Math.round((detlPakin.getWorkQty() - combMat.getAnfme()) * 10000) / 10000.0;
+                detlPakin.setWorkQty(v);
+                if (!orderDetlPakinService.update(detlPakin, new EntityWrapper<OrderDetlPakin>()
+                        .eq("order_no", combMat.getOrderNo())
+                        .eq("matnr", combMat.getMatnr())
+                        .eq("supp_code", combMat.getStandby1()))) {
+                    throw new CoolException("璁㈠崟鏄庣粏鏇存柊澶辫触锛侊紒");
+                }
+
+                BasStationDetl stationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
+                        .eq("order_no", combMat.getOrderNo())
+                        .eq("matnr", combMat.getMatnr())
+                        .eq("supp_code", combMat.getStandby1()));
+                if (!Objects.isNull(stationDetl)) {
+                    if (!basStationDetlService.delete(new EntityWrapper<BasStationDetl>()
+                            .eq("order_no", combMat.getOrderNo())
+                            .eq("matnr", combMat.getMatnr())
+                            .eq("supp_code", combMat.getStandby1()))) {
+                        throw new CoolException("瑙g粦澶辫触锛岀珯鐐瑰簱瀛樺垹闄ゅけ璐ワ紒");
+                    }
+                }
+
+                BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
+                if (Objects.isNull(basAreas)) {
+                    throw new CoolException("绔欑偣鏌ヨ澶辫触锛岃鑱旂郴绠$悊鍛橈紒锛�");
+                }
+
+                LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>()
+                        .eq("area_id", basAreas.getId())
+                        .eq("order_no", combMat.getOrderNo())
+                        .eq("matnr", combMat.getMatnr())
+                        .eq("supp_code", combMat.getStandby1()));
+                if (!Objects.isNull(locDetl)) {
+                    if (!locDetlService.delete(new EntityWrapper<LocDetl>()
+                            .eq("area_id", basAreas.getId())
+                            .eq("order_no", combMat.getOrderNo())
+                            .eq("matnr", combMat.getMatnr())
+                            .eq("supp_code", combMat.getStandby1()))) {
+                        throw new CoolException("瑙g粦澶辫触锛岀紦鍐插簱鍖哄簱瀛樺垹闄ゅけ璐ワ紒");
+                    }
+                }
+
+                WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>()
+                        .eq("order_no", combMat.getOrderNo())
+                        .eq("matnr", combMat.getMatnr())
+                        .eq("supp_code", combMat.getStandby1()));
+                if (!Objects.isNull(waitPakin)) {
+                    if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("order_no", combMat.getOrderNo())
+                            .eq("matnr", combMat.getMatnr())
+                            .eq("supp_code", combMat.getStandby1()))) {
+                        throw new CoolException("鍘熺粍鎵樻。鍒犻櫎澶辫触锛侊紒");
+                    }
+                }
+            } else {
+                throw new CoolException("璁㈠崟鏄庣粏缁戝畾鍏崇郴涓嶅瓨鍦ㄦ垨宸插畬鎴愬叆搴擄紒锛�");
+            }
+        }
+        return R.ok();
+    }
+
+
+    @Transactional(rollbackFor = Exception.class)
+    public void generateAgvTaskByTc(List<LocDto> locDtos) {
+        List<LocDto> locDtoArrayList = new ArrayList<>();
+        for (LocDto locDto : locDtos) {
+            if (locDto.getFrozen() != 1 && locDto.getFrozenLoc() != 1) {
+                locDtoArrayList.add(locDto);
+            }
+        }
+        locDtos = locDtoArrayList;
+        if (Cools.isEmpty(locDtos)) {
+            throw new CoolException("搴撳瓨/搴撲綅琚喕缁擄紝璇峰鐞嗗悗鍑哄簱锛侊紒锛�");
+        }
+        boolean lack = true;
+        for (LocDto locDto : locDtos) {
+            if (!locDto.isLack()) {
+                lack = false;
+                break;
+            }
+        }
+        if (lack) {
+            throw new CoolException("搴撳瓨涓嶈冻");
+        }
+
+        try {
+            Thread.sleep(300L);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+
+        List<TaskDto> taskDtos = new ArrayList<>();
+        // 鏍规嵁 锛堝簱浣� & 鍑哄簱绔欙級 鍒嗙粍锛� 鐞嗘兂鐘舵�侊細涓�缁勪负涓�娆″嚭搴撲换鍔�
+        for (LocDto locDto : locDtos) {
+            if (locDto.isLack()) {
+                continue;
+            }
+            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getAgvStaNo(), locDto);
+            if (TaskDto.hasAgv(taskDtos, taskDto)) {
+                TaskDto dto = TaskDto.findAgv(taskDtos, taskDto);
+                assert dto != null;
+                dto.getLocDtos().addAll(taskDto.getLocDtos());
+            } else {
+                taskDtos.add(taskDto);
+            }
+        }
+        // -----------------------------------------------------------------------------------------------
+        Map<String, List<TaskDto>> listMap = taskDtos.stream().collect(Collectors.groupingBy(TaskDto::getLocNo));
+        listMap.keySet().forEach(locNo -> {
+            listMap.get(locNo).forEach(taskDto -> {
+                BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
+                        .in("loc_sts", Arrays.asList(LocStsType.LOC_STS_TYPE_O.type, LocStsType.LOC_STS_TYPE_O.type))
+                        .eq("dev_no", taskDto.getAgvStaNo()));
+                if (Objects.isNull(station)) {
+                    throw new CoolException("鏁版嵁閿欒锛岀珯鐐逛笉瀛樺湪鎴栧凡浣跨敤锛侊紒");
+                }
+                workService.agvStockOut(station, taskDto, 9527L);
+            });
+        });
+    }
+
+    /**
+     * 纭鎹嗗寘鍑哄簱
+     *
+     * @param combParam
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R confirmOutstock(CombParam combParam) {
+        if (Objects.isNull(combParam.getCombMats()) || combParam.getCombMats().isEmpty()) {
+            return R.error("鎹嗗寘淇℃伅涓嶈兘涓虹┖锛侊紒");
+        }
+        Task task = taskService.selectOne(new EntityWrapper<Task>()
+                .eq("wrk_sts", 304)
+                .eq("barcode", combParam.getBarcode()));
+        if (Objects.isNull(task)) {
+            throw new CoolException("浠诲姟淇℃伅涓嶅瓨鍦紒锛�");
+        }
+        if (task.getIoType().equals(103)) {
+            List<TaskDetl> taskDetls = taskDetlService.selectList(new EntityWrapper<TaskDetl>()
+                    .eq("wrk_no", task.getWrkNo()));
+
+            int workNo = commonService.getWorkNo(4);
+            Task task1 = new Task();
+            BeanUtils.copyProperties(task, task1);
+            task1.setIoType(53);
+            task1.setLocNo(task.getSourceLocNo());
+            task1.setSourceStaNo(task.getStaNo());
+            task1.setWrkNo(workNo);
+            task1.setWrkSts(TaskStatusType.AGV_IN_START.type);
+
+            if (!taskService.insert(task1)) {
+                throw new CoolException("鍏ュ簱浠诲姟鐢熸垚澶辫触锛侊紒");
+            }
+            if (!Objects.isNull(taskDetls) && !taskDetls.isEmpty()) {
+                for (CombParam.CombMat combMat : combParam.getCombMats()) {
+                    taskDetls.forEach(taskDetl -> {
+                        if (taskDetl.getMatnr().equals(combMat.getMatnr()) && taskDetl.getSuppCode().equals(combMat.getSuppCode())) {
+                            //TODO
+                            if (!taskDetl.getAnfme().equals(combMat.getAnfme())) {
+                                throw new CoolException("鐗╂枡--->" + combMat.getMatnr() + "鏈嫞鏂欏畬鎴愶紝璇风‘璁ゅ畬鎴愬悗鍐嶅皾璇曪紒锛�");
+                            }
+                            List<TaskDetl> taskDetls1 = taskDetlService.selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo()));
+                            if (!Objects.isNull(taskDetls1) && !taskDetls1.isEmpty()) {
+                                taskDetls1.forEach(detl -> {
+                                    detl.setWrkNo(workNo);
+                                    detl.setBoxType1(combMat.getBoxType1());
+                                    detl.setSupp(combMat.getSuppCode());
+                                    if (!taskDetlService.update(detl, new EntityWrapper<TaskDetl>()
+                                            .eq("matnr", detl.getMatnr())
+                                            .eq("order_no", detl.getOrderNo())
+                                            .eq("supp_code", detl.getSuppCode())
+                                            .eq("wrk_no", task.getWrkNo()))) {
+                                        throw new CoolException("浠诲姟鍙蜂俊鎭洿鏂板け璐ワ紒锛�");
+                                    }
+                                });
+                            }
+                        }
+                    });
+                }
+            }
+            task.setWrkSts(TaskStatusType.AGV_INVENTORY_UPDATED_OUT.type);
+            if (!taskService.update(task, new EntityWrapper<Task>().eq("wrk_no", task.getWrkNo()))) {
+                throw new CoolException("浠诲姟淇℃伅鏇存柊澶辫触锛侊紒");
+            }
+        }
+        return R.ok("鍛煎彨鎴愬姛锛侊紒");
+    }
+
+
+    /**
+     * 绌烘澘鍑哄簱浠诲姟
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R getEmptyOutStock(AgvCallParams params) {
+        if (Objects.isNull(params.getOrgSite())) {
+            return R.error("鎵樼洏绫诲瀷涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getTarSite())) {
+            return R.error("鐩爣绔欑偣涓嶈兘涓虹┖锛侊紒");
+        }
+        Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>().eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type);
+        if (params.getOrgSite().equals(MatLocType.AUTOMATED.type)) {
+            wrapper.like("barcode", "LX80");
+        } else if (params.getOrgSite().equals(MatLocType.SO_HOLDING.type)) {
+            wrapper.like("barcode", "TP80");
+        } else {
+            wrapper.like("barcode", "TP88");
+        }
+        wrapper.orderAsc(Arrays.asList("row1", "lev1"));
+        LocMast locMast = locMastService.selectOne(wrapper);
+        if (Objects.isNull(locMast)) {
+            return R.error("娌℃湁鍙敤绌烘澘锛侊紒");
+        }
+
+        locMast.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
+
+        if (!locMastService.update(locMast, new EntityWrapper<LocMast>().eq("loc_no", locMast.getLocNo()))) {
+            throw new CoolException(locMast.getLocNo() + "鍑哄簱棰勭害澶辫触锛侊紒");
+        }
+
+        WrkMast wrkMast1 = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_loc_no", locMast.getLocNo()));
+        if (!Objects.isNull(wrkMast1)) {
+            throw new CoolException("浠诲姟妗e凡鐢熸垚锛岃涓嶈閲嶅鎿嶄綔锛侊紒");
+        }
+        int workNo = commonService.getWorkNo(0);
+        //TODO 鐢熸垚骞舵澘鍑哄簱浠诲姟
+        WrkMast wrkMast = new WrkMast();
+        wrkMast.setIoType(104);
+        wrkMast.setWrkSts(11L);
+        wrkMast.setStaNo(params.getTarSite());
+        wrkMast.setSourceLocNo(locMast.getLocNo());
+        wrkMast.setBarcode(locMast.getBarcode());
+        wrkMast.setIoPri(14.0);
+        wrkMast.setAppeTime(new Date());
+        wrkMast.setModiTime(new Date());
+        wrkMast.setCrnNo(locMast.getCrnNo());
+        wrkMast.setIoTime(new Date());
+        wrkMast.setWrkDate(new Date());
+        wrkMast.setWrkNo(workNo);
+        wrkMast.setTaskType("crn");
+
+        if (!wrkMastService.insert(wrkMast)) {
+            throw new CoolException("鏂板缓浠诲姟澶辫触锛侊紒");
+        }
+
+        return R.ok().add(wrkMast);
+    }
+
+    /**
+     * 鑾峰彇鍑哄簱鍙拌溅鎵�鏈変俊鎭�
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R getTcAllInfos(AgvCallParams params) {
+        if (Objects.isNull(params.getCarBarcode())) {
+            return R.error("鍙拌溅鐮佷笉鑳戒负绌猴紒锛�");
+        }
+//        Task task = taskService.selectOne(new EntityWrapper<Task>().eq("barcode", params.getCarBarcode()));
+//        if (Objects.isNull(task)) {
+//            throw new CoolException("浠诲姟妗d笉瀛樺湪锛侊紒");
+//        }
+//        if (Objects.isNull(task.getSourceLocNo())) {
+//            throw new CoolException("璇锋鏌ヤ换鍔$被鍨嬫槸鍚﹀睘浜庡嚭搴撴崋缁戯紒锛�");
+//        }
+        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("barcode", params.getCarBarcode()));
+        if (Objects.isNull(locCache)) {
+            return R.error("褰撳墠鍙拌溅涓嶅湪缂撳啿搴撳尯锛侊紒");
+        }
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locCache.getLocNo()));
+        if (!Objects.isNull(locDetls) && !locDetls.isEmpty()) {
+            locDetls.forEach(locDetl -> {
+                OrderPakout orderPakout = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>()
+                        .eq("number", locDetl.getOrderNo()));
+                if (!Objects.isNull(orderPakout)) {
+                    locDetl.setMemo(orderPakout.getShipCode());
+                }
+            });
+        }
+
+        try {
+            Map<String, List<LocDetl>> listMap = locDetls.stream().collect(Collectors.groupingBy(LocDetl::getMemo));
+            if (!Cools.isEmpty(params.getShipCode())) {
+                List<LocDetl> detlList = listMap.get(params.getShipCode());
+                return R.ok().add(detlList);
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+
+        return R.ok().add(locDetls);
+//        Map<String, List<LocDetl>> listMap = locDetls.stream().collect(Collectors.groupingBy(LocDetl::getMemo));
+//        if (!Objects.isNull(params.getShipCode())) {
+//            List<LocDetl> detlList = listMap.get(params.getShipCode());
+//            return R.ok().add(detlList);
+//        } else {
+//            return R.ok().add(locDetls);
+//        }
+    }
+
+    /**
+     * 鐢熸垚绉诲簱浠诲姟
+     *
+     * @param result
+     * @param sourceLoc
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public WrkMast generateMoveTask(LocMast result, LocMast sourceLoc) {
+        WrkMast wrkMast = new WrkMast();
+        int workNo = commonService.getWorkNo(0);
+
+        wrkMast.setWrkNo(workNo);
+        wrkMast.setLocNo(result.getLocNo());
+        wrkMast.setSourceLocNo(sourceLoc.getLocNo());
+        wrkMast.setWrkSts(11L);
+        wrkMast.setIoType(11);
+        wrkMast.setCrnNo(sourceLoc.getCrnNo());
+        wrkMast.setAppeTime(new Date());
+        wrkMast.setModiTime(new Date());
+        wrkMast.setIoPri(13D);
+        wrkMast.setWrkDate(new Date());
+
+        if (!wrkMastService.insert(wrkMast)) {
+            throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
+        }
+
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLoc.getLocNo()));
+        locDetls.forEach(detl -> {
+            detl.setLocNo(result.getLocNo());
+            if (!locDetlService.updateById(detl)) {
+                throw new CoolException("鏄庣粏鏇存柊澶辫触锛侊紒");
+            }
+        });
+
+        return wrkMast;
     }
 
     /**
@@ -2579,12 +3419,12 @@
         LocCache loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_IN_CACHE);
         if (loc != null) return loc;
 
-        // 2. Try SO Area
-        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_SO);
-        if (loc != null) return loc;
-
-        // 3. Try EO Area
-        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_EO);
+//        // 2. Try SO Area
+//        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_SO);
+//        if (loc != null) return loc;
+//
+//        // 3. Try EO Area
+//        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_EO);
         return loc;
     }
 
@@ -2598,9 +3438,7 @@
         }
         return locCacheService.selectOne(new EntityWrapper<LocCache>()
                 .eq("area_id", area.getId())
-                .eq("frozen", 0)
                 .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
-                .orderAsc(Arrays.asList("loc_no"))
-                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+                .orderAsc(Arrays.asList("loc_no")));
     }
 }

--
Gitblit v1.9.1