From b7380ff70bcc962494cd6640fcc3eac21aaab0a1 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期四, 15 一月 2026 08:09:29 +0800
Subject: [PATCH] 1.自动下发出库任务给wcs 2.wcs申请入库

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  267 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 254 insertions(+), 13 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 80f085f..26dc432 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -11,11 +11,15 @@
 import com.zy.asrs.mapper.LocMastMapper;
 import com.zy.asrs.mapper.ManLocDetlMapper;
 import com.zy.asrs.service.*;
+import com.zy.asrs.task.core.ReturnT;
 import com.zy.asrs.utils.MatUtils;
 import com.zy.asrs.utils.OrderInAndOutUtil;
+import com.zy.asrs.utils.Utils;
+import com.zy.common.constant.AgvConstant;
 import com.zy.common.constant.MesConstant;
 import com.zy.common.entity.Parameter;
 import com.zy.common.model.DetlDto;
+import com.zy.common.model.LocDto;
 import com.zy.common.model.MesCombParam;
 import com.zy.common.model.enums.WorkNoType;
 import com.zy.common.service.CommonService;
@@ -24,6 +28,7 @@
 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.util.*;
@@ -544,17 +549,17 @@
         if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
             throw new CoolException(BaseRes.PARAM);
         }
-        if(param.getCombMats().size()>1){
-            throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
-        }
+//        if(param.getCombMats().size()>1){
+//            throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
+//        }
         // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
         if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                 eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
             throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
         }
 
-        if(param.getBarcode().length()!=8){
-            throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode());
+        if(param.getBarcode().length()!=6){
+            throw new CoolException("鏉$爜闀垮害涓嶆槸6浣�===>>" + param.getBarcode());
         }
 //        if (param.getCombMats().size()>1){
 //            throw new CoolException("涓嶅厑璁告贩鏂�===>>" + param.getBarcode());
@@ -568,15 +573,27 @@
         }
 
         Date now = new Date();
-
+        boolean allEmpty = true;
+        if (param.getCombMats() != null) {
+            for (CombParam.CombMat mat : param.getCombMats()) {
+                if (!Cools.isEmpty(mat.getOrderNo())) {
+                    allEmpty = false;
+                    break;
+                }
+            }
+        }
         // 鏃犲崟缁勬墭
-        if (Cools.isEmpty(param.getOrderNo())) {
+        if (allEmpty) {
 
             // 鐢熸垚鍏ュ簱閫氱煡妗�
             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());
+                detlDto.setMemo(elem.getMemo());
+                detlDto.setSupp(elem.getSupp());
+                detlDto.setManu(elem.getManu());
+                detlDto.setSuppCode(elem.getSuppCode());
                 if (DetlDto.has(detlDtos, detlDto)) {
                     DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                     assert one != null;
@@ -603,6 +620,16 @@
                 waitPakin.setAppeTime(now);
                 waitPakin.setModiUser(userId);
                 waitPakin.setModiTime(now);
+                waitPakin.setMemo(detlDto.getMemo());
+                waitPakin.setSupp(detlDto.getSupp());
+                waitPakin.setSuppCode(detlDto.getSuppCode());
+                waitPakin.setManu(detlDto.getManu());
+                waitPakin.setStandby1(detlDto.getStandby1());
+                waitPakin.setStandby2(detlDto.getStandby2());
+                waitPakin.setStandby3(detlDto.getStandby3());
+                waitPakin.setBoxType1(detlDto.getBoxType1());
+                waitPakin.setBoxType2(detlDto.getBoxType2());
+                waitPakin.setBoxType3(detlDto.getBoxType3());
                 if (!waitPakinService.insert(waitPakin)) {
                     throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
                 }
@@ -610,7 +637,7 @@
         // 鍏宠仈缁勬墭
         } else {
 //            Order order = orderService.selectByNo(param.getOrderNo());
-            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo());
+            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getCombMats().get(0).getOrderNo());
             if (Cools.isEmpty(order) || order.getSettle() > 2) {
                 throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
             }
@@ -625,14 +652,14 @@
                 if (elem.getAnfme() > orderDetl.getEnableQty()) {
                     throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
                 }
-                // 淇敼璁㈠崟浣滀笟鏁伴噺
-//                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
-//                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
-//                }
                 OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE,order.getId(), elem.getMatnr(), elem.getBatch(),elem.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(),
                         elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3(), elem.getAnfme());
                 DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(),elem.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(),
                         elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3(),  elem.getAnfme());
+                detlDto.setMemo(elem.getMemo());
+                detlDto.setSupp(elem.getSupp());
+                detlDto.setManu(elem.getManu());
+                detlDto.setSuppCode(elem.getSuppCode());
                 if (DetlDto.has(detlDtos, detlDto)) {
                     DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                     assert one != null;
@@ -658,16 +685,230 @@
                 waitPakin.setAppeTime(now);
                 waitPakin.setModiUser(userId);
                 waitPakin.setModiTime(now);
+                waitPakin.setMemo(detlDto.getMemo());
+                waitPakin.setSupp(detlDto.getSupp());
+                waitPakin.setSuppCode(detlDto.getSuppCode());
+                waitPakin.setManu(detlDto.getManu());
+                waitPakin.setStandby1(detlDto.getStandby1());
+                waitPakin.setStandby2(detlDto.getStandby2());
+                waitPakin.setStandby3(detlDto.getStandby3());
+                waitPakin.setBoxType1(detlDto.getBoxType1());
+                waitPakin.setBoxType2(detlDto.getBoxType2());
+                waitPakin.setBoxType3(detlDto.getBoxType3());
                 if (!waitPakinService.insert(waitPakin)) {
                     throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
                 }
             }
+
 //            orderService.updateSettle(order.getId(), 2L, userId);
             OrderInAndOutUtil.updateOrder(Boolean.TRUE,order.getId(), 2L, userId);
         }
-
     }
 
+
+    @Override
+    @Transactional
+    public R kittingQuery(CombParam combParam, Long userId) {
+        List<Map<String, Object>> result = new ArrayList<>();
+        List<LocDetl> locDetlResultList = new ArrayList<>();
+        List<LocDetl> locDetlResultListHalf = new ArrayList<>();
+        List<CombParam.CombMat> combMats = combParam.getCombMats();
+        for (CombParam.CombMat combMat : combMats){
+            Wrapper<LocDetl> wrapper = new EntityWrapper<LocDetl>()
+                    .eq("matnr", combMat.getMatnr())
+                    .eq("specs", combMat.getSpecs())
+                    .eq("sku", combMat.getSku())
+                    .eq("origin", "涓嶅湪搴�");
+            List<LocDetl> locDetlList = locDetlService.selectList(wrapper);
+            for (LocDetl locDetl : locDetlList){
+                LocDetlFusion locDetlFusion = getLocDetlFusion(combParam, locDetl.getLocNo());
+                if (locDetlFusion.sign != 0 && locDetlFusion.sign != 9999){
+                    if (locDetlFusion.sign == combMats.size()){
+                        locDetlResultList.add(locDetlFusion.locDetl);
+                    } else {
+                        locDetlResultListHalf.add(locDetlFusion.locDetl);
+                    }
+                }
+            }
+        }
+        for (LocDetl locDetl : locDetlResultList){
+            Map<String, Object> map = new HashMap<>();
+            map.put("locNo", locDetl.getLocNo());
+            map.put("matnr", locDetl.getMatnr());
+            map.put("sku", locDetl.getSku());
+            map.put("anfme", locDetl.getAnfme());
+            map.put("memo", locDetl.getMemo());
+            result.add(map);
+        }
+        for (LocDetl locDetl : locDetlResultListHalf){
+            Map<String, Object> map = new HashMap<>();
+            map.put("locNo", locDetl.getLocNo());
+            map.put("matnr", locDetl.getMatnr());
+            map.put("sku", locDetl.getSku());
+            map.put("anfme", locDetl.getAnfme());
+            map.put("memo", locDetl.getMemo());
+            result.add(map);
+        }
+
+        return R.ok().add(result);
+    }
+
+    public class LocDetlFusion{
+        public Integer sign;
+        public LocDetl locDetl;
+
+        public LocDetlFusion(Integer sign, LocDetl locDetl) {
+            this.sign = sign;
+            this.locDetl = locDetl;
+        }
+    }
+
+    public LocDetlFusion getLocDetlFusion(CombParam combParam,String locNo){
+        LocDetl locDetl = new LocDetl();
+        locDetl.setLocNo(locNo);
+        locDetl.setAnfme(0D);
+        Integer sign = 0;
+        Map<Integer, LocDetl> map = new HashMap<>();
+        List<LocDetl> locDetls= new ArrayList<>();
+
+        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo));
+        if (locMast.getLocSts().equals("F")){
+            List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo));
+            for (CombParam.CombMat combMatNow : combParam.getCombMats()){
+                boolean flag = true;
+                while (flag){
+                    flag = false;
+                    for (LocDetl locDetlNow : locDetlList){
+                        if (locDetlNow.getOrigin().equals("涓嶅湪搴�")){
+                            if (combMatNow.getMatnr().equals(locDetlNow.getMatnr())){
+                                if (combMatNow.getAnfme().equals(locDetlNow.getAnfme())){
+                                    LocDetl locDetlAdd = new LocDetl();
+
+                                    locDetlAdd.sync(locDetlNow);
+                                    locDetls.add(locDetlAdd);
+                                    locDetlList.remove(locDetlNow);
+
+                                    sign++;
+                                    combMatNow.setMemo("瀹屽叏鍖归厤");
+                                    break;
+                                } else if (combMatNow.getAnfme()>locDetlNow.getAnfme()){
+                                    double anfme = combMatNow.getAnfme() - locDetlNow.getAnfme();
+                                    combMatNow.setAnfme(anfme);
+
+                                    LocDetl locDetlAdd = new LocDetl();
+                                    locDetlAdd.sync(locDetlNow);
+                                    locDetls.add(locDetlAdd);
+
+                                    locDetlList.remove(locDetlNow);
+                                    flag = true;
+                                    break;
+                                } else if (combMatNow.getAnfme()<locDetlNow.getAnfme()){
+                                    double anfme = locDetlNow.getAnfme() - combMatNow.getAnfme();
+                                    locDetlNow.setAnfme(combMatNow.getAnfme());
+
+                                    LocDetl locDetlAdd = new LocDetl();
+                                    locDetlAdd.sync(locDetlNow);
+                                    locDetls.add(locDetlAdd);
+
+                                    locDetlNow.setAnfme(anfme);
+                                    sign++;
+                                    combMatNow.setMemo("瀹屽叏鍖归厤");
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (sign == combParam.getCombMats().size()){
+                if (locDetlList.size() == 0 ){
+                    locDetl.setMemo("瀹屽叏鍖归厤");
+                } else {
+                    locDetl.setMemo("婧㈠嚭鍖归厤");
+                }
+            } else if (locDetls.size() != 0 ){
+                locDetl.setMemo("鏈畬鍏ㄥ尮閰�");
+                sign = 99999999;
+            }
+        }
+        for (LocDetl locDetlNow : locDetls){
+            if (Cools.isEmpty(locDetl.getMatnr())){
+                locDetl.setMatnr(locDetlNow.getMatnr());
+            } else {
+                locDetl.setMatnr(locDetl.getMatnr() + "," + locDetlNow.getMatnr());
+            }
+            if (Cools.isEmpty(locDetl.getSku())){
+                locDetl.setSku(locDetlNow.getSku());
+            } else {
+                locDetl.setSku(locDetl.getSku() + "," + locDetlNow.getSku());
+            }
+            locDetl.setAnfme(locDetlNow.getAnfme() + locDetl.getAnfme());
+        }
+        return new LocDetlFusion(sign,locDetl);
+    }
+
+    @Override
+    @Transactional
+    public void kittingCall(String locNo, Long userId) {
+        try{
+            List<StockOutParam.LocDetl> locDetls = new ArrayList<>();
+
+            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo));
+            if (locMast.getLocSts().equals("F")){
+                List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo));
+                for (LocDetl locDetl:locDetlList){
+                    StockOutParam.LocDetl locDto = new StockOutParam.LocDetl();
+                    locDto.setLocNo(locDetl.getLocNo());
+                    locDto.setMatnr(locDetl.getMatnr());
+                    locDto.setBatch(locDetl.getBatch());
+                    locDto.setBrand(locDetl.getBrand());
+                    locDto.setCount(locDetl.getAnfme());
+                    locDto.setStandby1(locDetl.getStandby1());
+                    locDto.setStandby2(locDetl.getStandby2());
+                    locDto.setStandby3(locDetl.getStandby3());
+                    locDto.setBoxType1(locDetl.getBoxType1());
+                    locDto.setBoxType2(locDetl.getBoxType2());
+                    locDto.setBoxType3(locDetl.getBoxType3());
+                    locDetls.add(locDto);
+                }
+            }
+            StockOutParam param = new StockOutParam();
+            param.setOutSite(101);
+            param.setLocDetls(locDetls);
+            WorkService workService = SpringUtils.getBean(WorkService.class);
+            workService.locCheckOut(param,userId);
+        } catch (Exception e){
+            throw new CoolException("鐩樼偣鍚姩澶辫触锛侊紒锛�");
+        }
+    }
+
+    @Override
+    @Transactional
+    public R locOriginInOut(LocDetl locDetl, Long userId) {
+        try{
+            Wrapper<LocDetl> wrapper = new EntityWrapper<LocDetl>()
+                    .eq("loc_no", locDetl.getLocNo())
+                    .eq("zpallet", locDetl.getZpallet())
+                    .eq("matnr", locDetl.getMatnr())
+                    .eq("specs", locDetl.getSpecs())
+                    .eq("batch", locDetl.getBatch())
+                    .eq("origin", locDetl.getOrigin());
+            LocDetl locDetl1 = locDetlService.selectOne(wrapper);
+            if (Cools.isEmpty(locDetl1)){
+                return R.error();
+            } else if (locDetl1.getOrigin().equals("涓嶅湪搴�")){
+                locDetl1.setOrigin("鍦ㄥ簱");
+            }else{
+                locDetl1.setOrigin("涓嶅湪搴�");
+            }
+            if (locDetlService.update(locDetl1,wrapper)){
+                return R.ok();
+            }
+        } catch (Exception e){
+
+        }
+        return R.error();
+    }
     // 鍟嗗搧涓婃灦
     @Override
     public void onSale(CombParam param) {

--
Gitblit v1.9.1