From a5ba6fbce1527c514392c01a914e15365d32dfab Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期四, 19 六月 2025 14:14:20 +0800
Subject: [PATCH] #批量出库同一托盘不同箱号界面显示bug修复

---
 src/main/java/com/zy/asrs/controller/OutController.java |  213 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 146 insertions(+), 67 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/OutController.java b/src/main/java/com/zy/asrs/controller/OutController.java
index eed2f39..51211a5 100644
--- a/src/main/java/com/zy/asrs/controller/OutController.java
+++ b/src/main/java/com/zy/asrs/controller/OutController.java
@@ -5,9 +5,11 @@
 import com.core.common.*;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
+import com.zy.asrs.entity.param.StockOutParam;
 import com.zy.asrs.service.*;
+import com.zy.common.model.LocDetlDto;
 import com.zy.common.model.LocDto;
-import com.zy.common.model.TaskDto;
+import com.zy.common.model.enums.IoWorkType;
 import com.zy.common.web.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -60,69 +62,75 @@
         if (Cools.isEmpty(ids)) {
             return R.parse(BaseRes.PARAM);
         }
+
         List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids);
+        if (orderDetls.isEmpty()) {
+            return R.parse("璇烽�夋嫨鏁版嵁");
+        }
+
+        Order order = orderService.selectOne(
+                new EntityWrapper<Order>().eq("order_no", orderDetls.get(0).getOrderNo())
+        );
+        if (order == null) {
+            return R.parse("璁㈠崟鏁版嵁涓虹┖");
+        }
+
+        // 鎸夊寘瑁呯粍鍙峰垎缁勫鐞�
+        Map<String, List<OrderDetl>> brandGroup = orderDetls.stream()
+                .collect(Collectors.groupingBy(OrderDetl::getBrand));
+
         List<LocDto> locDtos = new ArrayList<>();
 
-//        for (OrderDetl orderDetl : orderDetls) {
-//            if (orderDetl.getAnfme()-orderDetl.getWorkQty()-orderDetl.getQty()==0.0){
-//                continue;
-//            }
-//            LocDto locDto = new LocDto(orderDetl.getManu(), orderDetl.getMatnr(), orderDetl.getMaktx(),orderDetl.getModel(),orderDetl.getSpecs(),
-//                    orderDetl.getBatch(),orderDetl.getBrand(),orderDetl.getBarcode(), orderDetl.getOrderNo(),orderDetl.getAnfme());
-//            locDto.setOrderDetlId(orderDetl.getId());
-//            locDto.setTkType(orderDetl.getTkType());
-//            locDtos.add(locDto);
-//        }
+        // 姣忎釜鍖呰缁勬煡涓�娆″簱瀛�
+        for (Map.Entry<String, List<OrderDetl>> entry : brandGroup.entrySet()) {
+            String brand = entry.getKey();
+            List<OrderDetl> brandOrderDetls = entry.getValue();
 
+            // 鏌ヨ繖涓寘瑁呯粍瀵瑰簲鐨勬墍鏈夊簱瀛�
+            List<LocDetl> locDetls = locDetlService.selectList(
+                    new EntityWrapper<LocDetl>().eq("brand", brand)
+            );
+            if (locDetls.isEmpty()) continue;
 
-
-
-        Set<String> exist = new HashSet<>();
-
-        for (OrderDetl orderDetl : orderDetls) {
-            double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D);
-            if (issued <= 0.0D) { continue; }
-//            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist);
-            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("batch",orderDetl.getBatch()).eq("model",orderDetl.getModel()));
-            for (LocDetl locDetl : locDetls) {
-                if (issued > 0) {
-                    LocDto locDto = new LocDto(orderDetl.getManu(), orderDetl.getMatnr(), orderDetl.getMaktx(),orderDetl.getModel(),orderDetl.getSpecs(),
-                    orderDetl.getBatch(),orderDetl.getBrand(),orderDetl.getBarcode(), orderDetl.getOrderNo(),orderDetl.getAnfme());
-//                    LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(),
-//                            issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued);
-//                    List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103);
-                    List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103);
-
-                    locDto.setLocNo(locDetl.getLocNo());
-//                    wrkDetl.setMatnr(roll.getSpecs()); // 瑙勬牸
-//                    wrkDetl.setMaktx(roll.getSpecs()); //瑙勬牸
-                    locDto.setBatch(locDetl.getBatch()); // 绠卞彿
-                    locDto.setModel(locDetl.getModel()); // 鍗峰彿
-                    locDto.setBrand(""); // 鏈ㄧ绫诲瀷
-                    locDto.setOrigin(locDetl.getOrigin()); // 鏈ㄧ鍦ㄦ墭鐩樹綅缃�
-                    locDto.setWeight(locDetl.getWeight()); // 鍑�閲�
-                    locDto.setVolume(locDetl.getVolume()); // 姣涢噸
-                    locDto.setPrice(locDetl.getPrice());
-                    locDto.setSpecs(locDetl.getSpecs());
-                    locDto.setZpallet(locDetl.getZpallet());
-                    locDto.setStaNos(staNos);
-                    locDto.setOrderDetlId(orderDetl.getId());
-                    locDtos.add(locDto);
-                    exist.add(locDetl.getLocNo());
-                    // 鍓╀綑寰呭嚭鏁伴噺閫掑噺
-                    issued = issued - locDetl.getAnfme();
-                } else {
-                    break;
-                }
+            // 鑾峰彇鍑哄簱鍙�
+            List<Integer> staNos = new ArrayList<>();
+            if (order.getDocType() == 21) {
+                staNos.add(3077); staNos.add(3106);
+            } else if (order.getDocType() == 22) {
+                staNos.add(2041);
+            } else if (order.getDocType() == 23) {
+                staNos.add(3092); staNos.add(3102); staNos.add(3095);
             }
-            if (issued > 0) {
-                LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued);
-                locDto.setLack(Boolean.TRUE);
+
+            // 鍘婚噸 key锛岄伩鍏嶇浉鍚� loc+unit+model 閲嶅鏄剧ず
+            Set<String> seen = new HashSet<>();
+
+            for (LocDetl locDetl : locDetls) {
+                String key = locDetl.getLocNo() + "|" + locDetl.getUnit() + "|" + locDetl.getModel();
+                if (seen.contains(key)) continue;
+                seen.add(key);
+
+                // 瀵瑰簲澶氫釜鏄庣粏鏃讹紝鍒嗛厤鍒扮涓�涓槑缁嗭紙鎴栦綘鍙互鎷嗗垎澶氫釜锛�
+                OrderDetl firstDetl = brandOrderDetls.get(0);
+
+                LocDto locDto = new LocDto();
+                locDto.setLocNo(locDetl.getLocNo());
+                locDto.setUnit(locDetl.getUnit());
+                locDto.setModel(locDetl.getModel());
+                locDto.setThreeCode(locDetl.getThreeCode());
+                locDto.setBrand(brand);
+                locDto.setOrderNo(firstDetl.getOrderNo());
+                locDto.setStaNos(staNos);
+                locDto.setOrderDetlId(firstDetl.getId());
+
                 locDtos.add(locDto);
             }
         }
+
         return R.ok().add(locDtos);
     }
+
+
 
     @PostMapping("/out/refund/loc/preview/auth")
     @ManagerAuth
@@ -201,24 +209,95 @@
 
         Thread.sleep(1000L);
 
-        List<TaskDto> taskDtos = new ArrayList<>();
-        // 鏍规嵁 锛堝簱浣� & 鍑哄簱绔欙級 鍒嗙粍锛� 鐞嗘兂鐘舵�侊細涓�缁勪负涓�娆″嚭搴撲换鍔�
+        List<StockOutParam> stockOutParams = new ArrayList<>();
         for (LocDto locDto : locDtos) {
-            if (locDto.isLack()) { continue; }
-            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto);
-            if (TaskDto.has(taskDtos, taskDto)) {
-                TaskDto dto = TaskDto.find(taskDtos, taskDto);
-                assert dto != null;
-                dto.getLocDtos().addAll(taskDto.getLocDtos());
-            } else {
-                taskDtos.add(taskDto);
+            boolean flag1 = true;
+            for(StockOutParam stockOutParam: stockOutParams) {
+                if(stockOutParam.getOutSite().equals(locDto.getStaNo())) { // 鏈変竴鏍风殑鍑哄簱鍙�
+                    List<StockOutParam.LocDetl> locDetls = new ArrayList<>();
+                    List<LocDetl> locDetls1 = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("brand", locDto.getBrand()));
+                    for(LocDetl locDetl:locDetls1) {
+                        StockOutParam.LocDetl  locDetl1 = new StockOutParam.LocDetl();
+                        locDetl1.setLocNo(locDetl.getLocNo());
+                        locDetl1.setBrand(locDetl.getBrand());
+                        locDetl1.setModel(locDetl.getModel());
+                        locDetl1.setCount(locDetl.getAnfme());
+                        locDetls.add(locDetl1);
+                    }
+                    stockOutParam.getLocDetls().addAll(locDetls);
+                    flag1 = false;
+                    break;
+                }
+            }
+            if(flag1) { // 娌℃湁涓�鏍风殑鍑哄簱鍙�
+                StockOutParam stockOutParam = new StockOutParam();
+                stockOutParam.setOutSite(locDto.getStaNo());
+                stockOutParam.setOrderNo(locDto.getOrderNo());
+                List<StockOutParam.LocDetl> locDetls = new ArrayList<>();
+                List<LocDetl> locDetls1 = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("brand", locDto.getBrand()));
+                for(LocDetl locDetl:locDetls1) {
+                    StockOutParam.LocDetl  locDetl1 = new StockOutParam.LocDetl();
+                    locDetl1.setLocNo(locDetl.getLocNo());
+                    locDetl1.setBrand(locDetl.getBrand());
+                    locDetl1.setModel(locDetl.getModel());
+                    locDetl1.setCount(locDetl.getAnfme());
+                    locDetls.add(locDetl1);
+                }
+                stockOutParam.setLocDetls(locDetls);
+                stockOutParams.add(stockOutParam);
             }
         }
-        // -----------------------------------------------------------------------------------------------
-        for (TaskDto taskDto : taskDtos) {
-            BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo());
-            workService.stockOut(staNo, taskDto, getUserId());
+
+        for(StockOutParam stockOutParam :stockOutParams) {
+            BasDevp staNo = basDevpService.checkSiteStatus(stockOutParam.getOutSite());
+            // 鑾峰彇搴撲綅鏄庣粏
+            List<LocDetlDto> locDetlDtos = new ArrayList<>();
+            for (StockOutParam.LocDetl paramLocDetl : stockOutParam.getLocDetls()) {
+                LocDetl one = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no",paramLocDetl.getLocNo())
+                        .eq("brand",paramLocDetl.getBrand()).eq("model",paramLocDetl.getModel()));
+                if (null != one) {
+                    if(!"鍚堟牸".equals(one.getThreeCode())) {
+                        throw new CoolException(one.getModel() + "鍗蜂笉鍚堟牸:" + one.getThreeCode() );
+                    }
+                    locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount(), stockOutParam.getOrderNo()));
+                }
+            }
+            if (!locDetlDtos.isEmpty()) {
+                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo()));
+                if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ){
+                    // 鏍规嵁璁㈠崟绫诲瀷鍒ゆ柇鍑哄簱绫诲瀷
+                    Order order = orderService.selectByNo(stockOutParam.getOrderNo());
+
+                    // 鍚姩鍑哄簱寮�濮�
+                    workService.stockOut(staNo, locDetlDtos, order.getDocType() ==  23 ? IoWorkType.CHECK_OUT : null, getUserId());
+                }else {
+                    throw new CoolException("鎵�閫夊簱浣嶅瓨鍦ㄧ姸鎬佷笉涓篎銆丏鐨勫簱浣嶏紝搴撲綅鍙凤細"+locMast.getLocNo()+" 銆佸綋鍓嶇姸鎬侊細"+locMast.getLocSts()+"-"+locMast.getLocSts$());
+                }
+            } else {
+                throw new CoolException("搴撳瓨涓嶅瓨鍦�");
+            }
         }
+
+//        List<TaskDto> taskDtos = new ArrayList<>();
+//        // 鏍规嵁 锛堝簱浣� & 鍑哄簱绔欙級 鍒嗙粍锛� 鐞嗘兂鐘舵�侊細涓�缁勪负涓�娆″嚭搴撲换鍔�
+//        for (LocDto locDto : locDtos) {
+//            if (locDto.isLack()) { continue; }
+//            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto);
+//            if (TaskDto.has(taskDtos, taskDto)) {
+//                TaskDto dto = TaskDto.find(taskDtos, taskDto);
+//                assert dto != null;
+//                dto.getLocDtos().addAll(taskDto.getLocDtos());
+//            } else {
+//                taskDtos.add(taskDto);
+//            }
+//        }
+        // -----------------------------------------------------------------------------------------------
+//        for (TaskDto taskDto : taskDtos) {
+//            BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo());
+//            workService.stockOut(staNo, taskDto, getUserId());
+//        }
+//
+//        stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
         return R.ok();
     }
 

--
Gitblit v1.9.1