From 3cb931b3799846e1b8ef708da6c447bb9a9e0a0e Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期一, 15 十二月 2025 11:17:41 +0800
Subject: [PATCH] 并板出库功能优化

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  105 +++++++++++++++++++++++++---------------------------
 1 files changed, 50 insertions(+), 55 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 1eca080..d309d42 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -6,8 +6,6 @@
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.*;
 import com.core.exception.CoolException;
-import com.zy.api.enums.MatLocType;
-import com.zy.api.enums.MatType;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.*;
 import com.zy.asrs.entity.result.FindLocNoAttributeVo;
@@ -29,7 +27,6 @@
 import com.zy.common.model.LocTypeDto;
 import com.zy.common.model.MesCombParam;
 import com.zy.common.model.StartupDto;
-import com.zy.common.model.enums.IoWorkType;
 import com.zy.common.model.enums.WorkNoType;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.HttpHandler;
@@ -656,6 +653,7 @@
                 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());
@@ -760,6 +758,7 @@
                 waitPakin.setZpallet(param.getBarcode()); // 鎵樼洏鐮�
                 waitPakin.setThreeCode(detlDto.getThreeCode());
                 waitPakin.setSuppCode(detlDto.getStandby1());
+                waitPakin.setStandby1(detlDto.getStandby1());
                 waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
                 waitPakin.setAnfme(detlDto.getAnfme()); // 鏁伴噺
                 waitPakin.setStatus("Y"); // 鐘舵��
@@ -1331,23 +1330,15 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R OutCallAgv(AgvCallParams params, Long userId) {
-
-        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
-                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
-                .eq("dev_no", params.getTarSite()));
-        if (Objects.isNull(station)) {
-            throw new CoolException("璇锋鏌ョ珯鐐逛俊鎭紒");
+        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("搴撳尯涓嶅瓨鍦紒锛�");
         }
-
-        /** 鑾峰彇鍏ュ簱鏈�鏃╃殑涓�鏉℃暟鎹� **/
+        /**鑾峰彇鍏ュ簱鏈�鏃╃殑涓�鏉℃暟鎹�**/
         List<LocCache> locCaches = locCacheService.selectList(new EntityWrapper<LocCache>()
                 .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type)
+                .eq("area_id", basAreas.getId())
                 .eq("frozen", 0)
-                .in("loc_no", new EntityWrapper<LocDetl>()
-                        .setSqlSelect("DISTINCT loc_no")
-                        .in("matnr", new EntityWrapper<Mat>()
-                                .setSqlSelect("matnr")
-                                .eq("tag_id", station.getCtnType())))
                 .orderDesc(Arrays.asList("sort", "first_time")));
 
         if (locCaches.isEmpty()) {
@@ -1355,13 +1346,8 @@
         }
 
         for (LocCache locCache : locCaches) {
-            // 鑾峰彇缂撳瓨鍖轰俊鎭�
-            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("搴撳尯涓嶅瓨鍦紒锛�");
-            }
-
+            //鑾峰彇缂撳瓨鍖轰俊鎭�
+//            BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
             List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                     .eq("area_id", basAreas.getId())
                     .eq("loc_no", locCache.getLocNo()));
@@ -1381,19 +1367,18 @@
 
             Mat mat = matList.stream().findFirst().get();
 
-//            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
-//                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
-//                    .eq("ctn_type", mat.getTagId())
-//                    .eq("dev_no", params.getTarSite()));
-
-            if (mat.getTagId() != station.getCtnType().longValue()){
+            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
+                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
+                    .eq("ctn_type", mat.getTagId())
+                    .eq("dev_no", params.getTarSite()));
+            if (Objects.isNull(station)) {
                 continue;
             }
 
-            /** 鐢熸垚缂撳瓨鍖哄嚭搴撲换鍔� */
+            /**鐢熸垚缂撳瓨鍖哄嚭搴撲换鍔�*/
             generateCacheOutTask(station, locCache, userId);
 
-            /** 鐢熸垚绔嬪簱鍑哄簱浠诲姟 */
+            /**鐢熸垚绔嬪簱鍑哄簱浠诲姟*/
             generateCRNOutTask(station, locCache, userId);
 
             return R.ok();
@@ -1667,7 +1652,7 @@
             throw new CoolException("缁勬墭鐗╂枡绫诲瀷涓嶄竴鑷达紝鍙湁鐩稿悓鐨勭墿鏂欏垎绫绘墠鍙互缁勬墭锛侊紒");
         }
         // 杩樺彲浠ユ斁鍏ュ灏戠鐗╂枡
-        Integer suplus = container.getMixMax();
+        Double suplus = container.getMixMax();
         Date now = new Date();
         for (DetlDto detlDto : detlDtos) {
             Mat mat = matService.selectByMatnr(detlDto.getMatnr());
@@ -1694,7 +1679,7 @@
                 throw new CoolException("鏄庣粏鍐呭涓嶅瓨鍦紒锛�");
             }
 
-            Double v = stationDetl.getAnfme() - stationDetl.getWorkQty();
+            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);
             }
@@ -1725,19 +1710,31 @@
                 throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
             }
 
-            Double v1 = stationDetl.getWorkQty() + detlDto.getAnfme();
+            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.getWorkQty()) >= 0) {
+            if (v1.compareTo(stationDetl.getAnfme()) >= 0) {
                 if (!basStationDetlService.deleteById(stationDetl)) {
                     throw new CoolException("鍘熷鏁版嵁绉婚櫎澶辫触锛�");
                 }
             }
 
+            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);
+                if (!basStationService.updateById(station)) {
+                    throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+                }
+            }
         }
     }
 
@@ -1838,11 +1835,13 @@
                 Mat mat = matService.selectByMatnr(combMat.getMatnr());
                 BeanUtils.copyProperties(mat, basStationDetl);
                 basStationDetl
+                        .setId(null)
                         .setOrderNo(orderPakin.getOrderNo())
                         .setDevNo(basStation.getDevNo())
                         .setBarcode(params.getTarBarcode())
                         .setZpallet(params.getTarBarcode())
                         .setBatch(combMat.getBatch())
+                        .setSuppCode(combMat.getStandby1())
                         .setStandby1(combMat.getStandby1())
                         .setAnfme(combMat.getWorkQty().doubleValue());
                 if (!basStationDetlService.insert(basStationDetl)) {
@@ -1855,7 +1854,6 @@
                 if (!basStationDetlService.updateById(basStationDetl)) {
                     throw new CoolException("鏇存柊鏄庣粏鏁版嵁澶辫触");
                 }
-
             }
         }
         if (basStation.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)
@@ -1954,7 +1952,7 @@
         wrkMast.setSourceStaNo(dto.getSourceStaNo() + "");
         wrkMast.setStaNo(dto.getStaNo() + "");
         wrkMast.setLocNo(dto.getLocNo());
-        wrkMast.setBarcode(pakin.getBarcode()); // 鎵樼洏鐮�
+        wrkMast.setBarcode(pakin.getZpallet()); // 鎵樼洏鐮�
         wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
@@ -2077,13 +2075,14 @@
         BasDevp basDevp = devps.stream().findFirst().get();
         List<LocMast> locMasts = new ArrayList<>();
         Map<String, List<LocDetl>> listMap = locDetls.stream().collect(Collectors.groupingBy(LocDetl::getMatnr));
-        AtomicReference<Double> totalOut = new AtomicReference<>(
-                locDetls.stream().mapToDouble(LocDetl::getAnfme).sum());
+        //鑾峰彇鏌ュ簱瀛樻�绘暟閲�
+        AtomicReference<Double> totalOut = new AtomicReference<>(0.0);
         listMap.forEach((matnr, detls) -> {
-            // 鏍规嵁supId(渚涘簲鍟�)鍒嗙被锛屽緱鍒板嚭搴撴�绘暟
             Map<String, List<LocDetl>> supIds = detls.stream().collect(Collectors.groupingBy(LocDetl::getStandby1));
             supIds.forEach((supId, sups) -> {
+                // 鏍规嵁supId(渚涘簲鍟�)鍒嗙被锛屽緱鍒伴渶瑕佸瓨鏀剧殑鎬荤┖搴撳瓨鏁伴噺
                 Double sum = sups.stream().mapToDouble(LocDetl::getAnfme).sum();
+                AtomicReference<Double> itemed = new AtomicReference<>(0.0);
                 // 鑾峰彇褰撳墠渚涘簲鍟�+ 鐗╂枡鍦ㄥ簱
                 List<LocDetl> detlList = locDetlService.selectList(new EntityWrapper<LocDetl>()
                         .eq("matnr", matnr)
@@ -2106,17 +2105,20 @@
                         Set<String> sets = adetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
                         // 鍒ゆ柇瀹瑰櫒鏄惁杩樺彲娣锋斁,鍙婂綋鍓嶇墿鏂欏彲鏀惧灏�
                         if (container.getMixMax() > sets.size()) {
-                            int suplus = 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 = mats.getUpQty() * suplus;
-                            // 灏忎簬闆�
-                            if (sum.compareTo(v) <= 0) {
+                            //浣欎笅鏈�澶у彲鏀炬暟閲�
+                            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);
                                 // 鍙斁涓�
                                 locMasts.add(locMast);
-                                totalOut.set(Math.round((totalOut.get() - sum) * 10000) / 10000.0);
+                                totalOut.set(Math.round((totalOut.get() + itemed.get()) * 10000) / 10000.0);
                             }
                         }
                     });
@@ -2126,10 +2128,9 @@
 
         // 鍒ゆ柇鏍规嵁鍒嗘嫞鍑哄簱鍚�,杩橀渶瑕佸嚭澶氬皯鎵樼洏鎴栨枡绠�;濡傛灉浣欐枡澶т簬0, 鍑烘柊鎵樼洏鎴栨枡绠�
         if (totalOut.get().compareTo(0.0) > 0) {
-            // Set<String> matnrs =
-            // locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
-            // List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr",
-            // matnrs));
+            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId);
+            //TODO 缁嗗寲鍖哄垎锛屽綋鍓嶅嚭搴撴墭鐩樻槸婊炴弧瓒虫嫞璐ф暟閲�
+        } else {
             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                     // todo 鏍规嵁鐗╂枡绉嶇被,鍖哄垎搴撳尯绫诲瀷
                     .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
@@ -2138,12 +2139,6 @@
             locMasts.add(locMast);
             // 绌烘澘鍑哄簱
             generateTask(locMasts, TaskIOType.EMPTY_OUT.type, basDevp, userId);
-        } else {
-            // 鐢熸垚鍫嗗灈鏈哄嚭搴撲换鍔�
-            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId);
-            // if (!locMasts.isEmpty()) {
-            //
-            // }
         }
     }
 

--
Gitblit v1.9.1