From 6e24a8fe9a57687842413933ce891bebb5693649 Mon Sep 17 00:00:00 2001
From: zyx <zyx123456>
Date: 星期五, 17 十一月 2023 16:52:52 +0800
Subject: [PATCH] Merge branch 'tzskasrs' of http://47.97.1.152:5880/r/zy-asrs into tzskasrs

---
 src/main/java/com/zy/asrs/task/handler/AutoReplenishmentHandler.java |   82 ++++++++++++++++++++++++-----------------
 1 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/src/main/java/com/zy/asrs/task/handler/AutoReplenishmentHandler.java b/src/main/java/com/zy/asrs/task/handler/AutoReplenishmentHandler.java
index 3b95b94..cd21bd0 100644
--- a/src/main/java/com/zy/asrs/task/handler/AutoReplenishmentHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/AutoReplenishmentHandler.java
@@ -1,11 +1,13 @@
 package com.zy.asrs.task.handler;
 
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.service.*;
 import com.zy.asrs.task.AbstractHandler;
 import com.zy.asrs.task.core.ReturnT;
+import com.zy.asrs.utils.Utils;
 import com.zy.common.model.enums.WorkNoType;
 import com.zy.common.service.CommonService;
 import org.springframework.beans.BeanUtils;
@@ -13,10 +15,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 @Service
 public class AutoReplenishmentHandler extends AbstractHandler<String> {
@@ -75,11 +74,19 @@
             }
 
             String matnr = orderDetl.getMatnr();
+            String batch = orderDetl.getBatch();
+            String csocode = orderDetl.getThreeCode();
+            String isocode = orderDetl.getDeadTime();
+
             Double orderAnfme = orderDetl.getAnfme();
 
-            List<String> locNosSearch = locDetlService.selectLocNo(matnr);
+            //List<String> locNosSearch = locDetlService.selectLocNo(matnr);
+            Set<String> locNosSearch = locDetlService.selectLocNo(matnr, batch, csocode, isocode);
 
-            for(String locNo : locNosSearch){
+            //閲嶆柊鎺掑簭 骞朵笖妫�娴嬭搴撲綅鏄惁鍚病鏈夋枡绠辩爜鐨勭墿鏂欙紝濡傛湁鏈夊垯涓嶅厑璁稿嚭搴�
+            Set<String> resort = resort(locNosSearch);
+
+            for(String locNo : resort){
                 List<LocDetl> locDetls = locDetlService.selectByLocNo(locNo);
                 locNos.add(locNo);
                 for (LocDetl locDetl :locDetls){
@@ -95,37 +102,44 @@
             }
         }
 
-//        orderDetlList.forEach(orderDetl -> {
-//
-//            if(orderDetl.getAnfme() - orderDetl.getQty() <= 0){
-//                cont
-//            }
-//
-//            String matnr = orderDetl.getMatnr();
-//            Double orderAnfme = orderDetl.getAnfme();
-//
-//            List<String> locNosSearch = locDetlService.selectLocNo(matnr);
-//
-//            for(String locNo : locNosSearch){
-//                List<LocDetl> locDetls = locDetlService.selectByLocNo(locNo);
-//                locNos.add(locNo);
-//                for (LocDetl locDetl :locDetls){
-//                    if(matnr.equals(locDetl.getMatnr())){
-//                        orderAnfme -= locDetl.getAnfme();
-//                    }
-//                }
-//                if(orderAnfme <= 0){
-//                    orderDetl.setQty(orderDetl.getAnfme() - orderAnfme);
-//                    orderDetlService.updateById(orderDetl);
-//                    break;
-//                }
-//            }
-//
-//        });
-
         return locNos;
     }
 
+    //鏍规嵁娣辨祬搴撲綅杩涜閲嶆柊鎺掑簭
+    private Set<String> resort(Set<String> locNos){
+        Set<String> locNosResort = new LinkedHashSet<>();
+
+        for(String locNoSearch : locNos){
+            LocMast locMast = locMastService.selectById(locNoSearch);
+            if(!"F".equals(locMast.getLocSts())){
+                continue;
+            }
+
+            List<String> groupOuterLoc = Utils.getGroupOuterLoc(locNoSearch);
+
+            if(Cools.isEmpty(groupOuterLoc)){
+                locNosResort.add(locNoSearch);
+            }else {
+                groupOuterLoc.add(locNoSearch);
+                //濡傛灉鏄繁搴撲綅锛屽垯鍏堟壘澶栦晶鐨勫簱浣�
+                for (String locNoOut : groupOuterLoc){
+                    LocMast locMastOuter = locMastService.selectById(locNoOut);
+                    //澶栦晶濡傛灉鏄嫞鏂欙紝鍒欏唴娴嬩笉鍏佽鍑�
+                    if("P".equals(locMastOuter.getLocSts()) || "Q".equals(locMastOuter.getLocSts()) || "S".equals(locMastOuter.getLocSts())){
+                        break;
+                    }
+
+                    if(!"F".equals(locMastOuter.getLocSts())){
+                        continue;
+                    }
+                    locNosResort.add(locNoOut);
+
+                }
+            }
+        }
+        return locNosResort;
+    }
+
     private WrkMast createWrkMast(String locNo,String barCode,Date now){
         int ioType = 101;
         int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));

--
Gitblit v1.9.1