From b591d3396c94e0ca3496d2bac280d106438c75e9 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期六, 17 八月 2024 09:37:35 +0800
Subject: [PATCH] #

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java |  343 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 276 insertions(+), 67 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
index 6c7c7ce..e015d14 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
@@ -4,15 +4,16 @@
 import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wms.asrs.entity.*;
 import com.zy.asrs.wms.asrs.entity.enums.LocStsType;
+import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType;
+import com.zy.asrs.wms.asrs.entity.enums.ShelvesRuleDetlType;
 import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
 import com.zy.asrs.wms.asrs.service.*;
+import com.zy.asrs.wms.utils.LocUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
 
 @Service("workService")
 public class WorkServiceImpl implements WorkService {
@@ -30,6 +31,8 @@
     @Autowired
     private TaskDetlFieldService taskDetlFieldService;
     @Autowired
+    private OrderService orderService;
+    @Autowired
     private OrderDetlService orderDetlService;
     @Autowired
     private LocService locService;
@@ -41,6 +44,12 @@
     private TaskDetlLogService taskDetlLogService;
     @Autowired
     private TaskDetlFieldLogService taskDetlFieldLogService;
+    @Autowired
+    private LocUtils locUtils;
+    @Autowired
+    private ShelvesRuleService shelvesRuleService;
+    @Autowired
+    private LanewayRuleService lanewayRuleService;
 
     @Override
     public String generateTaskNo(Long taskType) {
@@ -55,20 +64,153 @@
     }
 
     @Override
-    public Loc generateLoc(Long taskType) {
-        LocSts locSts = locStsService.getOne(new LambdaQueryWrapper<LocSts>().eq(LocSts::getLocSts, String.valueOf(LocStsType.O)));
-        List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getLocStsId, locSts.getId()));
-        if (list.isEmpty()) {
-            throw new CoolException("娌℃湁绌哄簱浣�");
+    public Loc generateEmptyLoc(Long taskType, Integer locTypeHeight) {
+        List<ShelvesRule> shelvesRules = shelvesRuleService.list(new LambdaQueryWrapper<ShelvesRule>().eq(ShelvesRule::getStatus, 1).orderByDesc(ShelvesRule::getCreateTime));
+        if(shelvesRules.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒�");
         }
-        return list.get(0);
+        ShelvesRule shelvesRule = shelvesRules.get(0);
+        //鍙敤宸烽亾
+        List<Long> laneList = shelvesRule.getLaneList();
+        //鍙敤宸烽亾Row
+        List<Integer> laneRowList = new ArrayList<>();
+        if (laneList != null) {
+            //鑾峰彇宸烽亾
+            List<LanewayRule> lanewayRules = lanewayRuleService.listByIds(laneList);
+            for (LanewayRule lanewayRule : lanewayRules) {
+                laneRowList.addAll(lanewayRule.getLaneX$());
+                laneRowList.addAll(lanewayRule.getLaneY$());
+            }
+        }
+
+        List<ShelvesRuleDetl> ruleDetls = shelvesRule.getRuleDetl$();
+        if(ruleDetls.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒欐槑缁�");
+        }
+
+        Loc defaultLoc = null;
+
+        for (ShelvesRuleDetl ruleDetl : ruleDetls) {
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.TASK_OR_LOC.id)) {
+                //浠庡簱瀛樻垨浠诲姟涓尮閰嶇浉閭诲簱浣�
+                defaultLoc = locUtils.getNeighborEmptyLoc(taskType, locTypeHeight);
+                if (defaultLoc != null) {
+                    return defaultLoc;
+                }
+            }
+
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.SUGGEST.id)) {
+                //鑾峰彇鎺ㄨ崘搴撲綅
+                List<Loc> suggestLoc = locUtils.getSuggestEmptyLoc(taskType, locTypeHeight, laneRowList);
+                //鑾峰彇搴撲綅
+                if (!suggestLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterLoc(taskType, suggestLoc);
+                    if(defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
+            }
+
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.COMPLETE.id)) {
+                //浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
+                List<Loc> globalLoc = locUtils.getGlobalEmptyLoc(taskType, locTypeHeight, laneRowList);
+                //鑾峰彇搴撲綅
+                if (!globalLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterAllLoc(globalLoc);
+                    if(defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
+            }
+        }
+
+        return defaultLoc;
+    }
+
+    @Override
+    public Loc generateLoc(Long taskType, String barcode, Integer locTypeHeight) {
+        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, barcode));
+        if (taskType != 10 && waitPakins.isEmpty()) {
+            throw new CoolException("鎵樼洏鏈粍鎵�");
+        }
+
+        WaitPakin waitPakin = waitPakins.get(0);
+        OrderDetl detl = waitPakin.getDetl$();
+        if (detl == null) {
+            throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
+        }
+
+        Mat mat = detl.getMat$();
+        if (mat == null) {
+            throw new CoolException("鍟嗗搧涓嶅瓨鍦�");
+        }
+
+        List<ShelvesRule> shelvesRules = shelvesRuleService.list(new LambdaQueryWrapper<ShelvesRule>().eq(ShelvesRule::getStatus, 1).orderByDesc(ShelvesRule::getCreateTime));
+        if(shelvesRules.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒�");
+        }
+        ShelvesRule shelvesRule = shelvesRules.get(0);
+        //鍙敤宸烽亾
+        List<Long> laneList = shelvesRule.getLaneList();
+        //鍙敤宸烽亾Row
+        List<Integer> laneRowList = new ArrayList<>();
+        if (laneList != null) {
+            //鑾峰彇宸烽亾
+            List<LanewayRule> lanewayRules = lanewayRuleService.listByIds(laneList);
+            for (LanewayRule lanewayRule : lanewayRules) {
+                laneRowList.addAll(lanewayRule.getLaneX$());
+                laneRowList.addAll(lanewayRule.getLaneY$());
+            }
+        }
+
+        List<ShelvesRuleDetl> ruleDetls = shelvesRule.getRuleDetl$();
+        if(ruleDetls.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒欐槑缁�");
+        }
+
+        Loc defaultLoc = null;
+
+        for (ShelvesRuleDetl ruleDetl : ruleDetls) {
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.TASK_OR_LOC.id)) {
+                //浠庡簱瀛樻垨浠诲姟涓尮閰嶇浉閭诲簱浣�
+                defaultLoc = locUtils.getNeighborLoc(taskType, detl, locTypeHeight);
+                if (defaultLoc != null) {
+                    return defaultLoc;
+                }
+            }
+
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.SUGGEST.id)) {
+                //鑾峰彇鎺ㄨ崘搴撲綅
+                List<Loc> suggestLoc = locUtils.getSuggestLoc(taskType, mat.getId(), detl.getBatch(), locTypeHeight, laneRowList);
+                //鑾峰彇搴撲綅
+                if (!suggestLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterLoc(taskType, suggestLoc);
+                    if(defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
+            }
+
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.COMPLETE.id)) {
+                //浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
+                List<Loc> globalLoc = locUtils.getGlobalLoc(taskType, locTypeHeight, laneRowList);
+                //鑾峰彇搴撲綅
+                if (!globalLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterAllLoc(globalLoc);
+                    if(defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
+            }
+        }
+        return defaultLoc;
     }
 
     @Override
     @Transactional
     public boolean generatePakIn(GeneratePakInParam param) {
         List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, param.getBarcode()));
-        if (waitPakins.isEmpty()) {
+        if (param.getTaskType() != 10 && waitPakins.isEmpty()) {
             throw new CoolException("鎵樼洏鏈粍鎵�");
         }
 
@@ -77,8 +219,16 @@
             throw new CoolException("浠诲姟绫诲瀷涓嶅瓨鍦�");
         }
 
+        Task one = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, param.getBarcode()));
+        if (one != null) {
+            throw new CoolException("浠诲姟宸茬粡鍒涘缓锛岃鍕块噸澶嶈姹�");
+        }
+
         //鐢熸垚搴撲綅
-        Loc loc = this.generateLoc(param.getTaskType());
+        Loc loc = this.generateLoc(param.getTaskType(), param.getBarcode(), param.getLocTypeHeight());
+        if(loc == null) {
+            throw new CoolException("娌℃湁绌哄簱浣�");
+        }
 
         Task task = new Task();
         task.setTaskNo(this.generateTaskNo(taskType.getId()));//浠诲姟鍙�
@@ -108,6 +258,7 @@
             taskDetl.setOrderNo(waitPakin.getOrderNo());
             taskDetl.setDetlId(waitPakin.getDetlId());
             taskDetl.setMatId(waitPakin.getDetl$().getMatId());
+            taskDetl.setMatnr(waitPakin.getDetl$().getMat$().getMatnr());
             boolean taskDetlSave = taskDetlService.save(taskDetl);
             if(!taskDetlSave){
                 throw new CoolException("浠诲姟鏄庣粏鐢熸垚澶辫触");
@@ -135,18 +286,72 @@
                 throw new CoolException("缁勬墭閫氱煡妗f洿鏂板け璐�");
             }
 
-            //鏇存柊璁㈠崟鏁版嵁
+            //鏇存柊璁㈠崟鏄庣粏鏁版嵁
             OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
             if(orderDetl == null){
-                throw new CoolException("璁㈠崟鏁版嵁寮傚父");
+                throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
             }
 
             orderDetl.setWorkQty(orderDetl.getWorkQty() + taskDetl.getAnfme());
             orderDetl.setUpdateTime(new Date());
             boolean orderDetlUpdate = orderDetlService.updateById(orderDetl);
             if(!orderDetlUpdate){
-                throw new CoolException("璁㈠崟鏇存柊澶辫触");
+                throw new CoolException("璁㈠崟鏄庣粏鏇存柊澶辫触");
             }
+
+            //鑾峰彇璁㈠崟
+            Order order = orderService.getById(taskDetl.getOrderId());
+            if(order == null){
+                throw new CoolException("璁㈠崟涓嶅瓨鍦�");
+            }
+
+            //鏇存柊璁㈠崟鐘舵��
+            if (order.getOrderSettle().equals(OrderSettleType.WAIT.val())) {
+                order.setOrderSettle(OrderSettleType.WORKING.val());
+                order.setUpdateTime(new Date());
+                if (!orderService.updateById(order)) {
+                    throw new CoolException("璁㈠崟鏁版嵁鏇存柊澶辫触");
+                }
+            }
+        }
+
+        //搴撲綅O => S
+        loc.setLocStsId(LocStsType.S.val());
+        loc.setUpdateTime(new Date());
+        boolean locUpdate = locService.updateById(loc);
+        if(!locUpdate){
+            throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean generateEmptyPakIn(GeneratePakInParam param) {
+        TaskType taskType = taskTypeService.getById(param.getTaskType());
+        if (taskType == null) {
+            throw new CoolException("浠诲姟绫诲瀷涓嶅瓨鍦�");
+        }
+
+        //鐢熸垚搴撲綅
+        Loc loc = this.generateEmptyLoc(param.getTaskType(), param.getLocTypeHeight());
+        if(loc == null) {
+            throw new CoolException("娌℃湁绌哄簱浣�");
+        }
+
+        Task task = new Task();
+        task.setTaskNo(this.generateTaskNo(taskType.getId()));//浠诲姟鍙�
+        task.setTaskSts(1L);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskType(taskType.getId());//浠诲姟绫诲瀷
+        task.setIoPri(this.generateIoPri(taskType.getId()));//浼樺厛绾�
+        task.setOriginLoc(null);
+        task.setTargetLoc(loc.getLocNo());
+        task.setOriginSite(param.getOriginSite());
+        task.setTargetSite(null);
+        task.setBarcode(null);//鎵樼洏鐮�
+        boolean taskSave = taskService.save(task);
+        if (!taskSave) {
+            throw new CoolException("浠诲姟鐢熸垚澶辫触");
         }
 
         //搴撲綅O => S
@@ -196,15 +401,11 @@
             throw new CoolException("浠诲姟涓嶅瓨鍦�");
         }
 
-        List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
-        if (taskDetls.isEmpty()) {
-            throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
-        }
-
         //鏇存柊搴撲綅鐘舵��
         Loc loc = null;
         switch (task.getTaskType().intValue()) {
             case 1://鍏ュ簱
+            case 10://绌烘澘
             case 53://鎷f枡
             case 54://骞舵澘
             case 57://鐩樼偣
@@ -225,6 +426,7 @@
             case 103://鎷f枡
             case 104://骞舵澘
             case 107://鐩樼偣
+            case 110://绌烘澘
                 loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
                 if(loc == null){
                     throw new CoolException("搴撲綅涓嶅瓨鍦�");
@@ -240,64 +442,71 @@
                 break;
         }
 
-        //鍥炴粴璁㈠崟
-        for (TaskDetl taskDetl : taskDetls) {
-            OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
-            if(orderDetl == null){
-                throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
+        if (task.getTaskType() != 10) {
+            List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
+            if (taskDetls.isEmpty()) {
+                throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
             }
 
-            //鍥炴粴宸ヤ綔鏁伴噺
-            orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());
-            orderDetl.setUpdateTime(new Date());
-            boolean orderDetlUpdate = orderDetlService.updateById(orderDetl);
-            if(!orderDetlUpdate){
-                throw new CoolException("宸ヤ綔鏁伴噺鍥炴粴澶辫触");
-            }
-
-            //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
-            if (task.getTaskType() == 1) {
-                WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getDetlId, taskDetl.getDetlId()).eq(WaitPakin::getBarcode, task.getBarcode()));
-                if(waitPakin == null){
-                    throw new CoolException("缁勬墭閫氱煡妗d笉瀛樺湪");
+            //鍥炴粴璁㈠崟
+            for (TaskDetl taskDetl : taskDetls) {
+                OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
+                if(orderDetl == null){
+                    throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
                 }
 
-                waitPakin.setIoStatus(0);
-                waitPakin.setUpdateTime(new Date());
-                boolean updateWaitPakin = waitPakinService.updateById(waitPakin);
-                if(!updateWaitPakin){
-                    throw new CoolException("缁勬墭閫氱煡妗e洖婊氬け璐�");
-                }
-            }
-
-            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
-            for (TaskDetlField detlField : detlFields) {
-                //鏄庣粏鎵╁睍瀛楁鏁版嵁淇濆瓨鑷冲巻鍙叉。
-                TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
-                taskDetlFieldLog.sync(detlField);
-                if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
-                    throw new CoolException("鏄庣粏鎵╁睍瀛楁杞巻鍙叉。妗堝け璐�");
+                //鍥炴粴宸ヤ綔鏁伴噺
+                orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());
+                orderDetl.setUpdateTime(new Date());
+                boolean orderDetlUpdate = orderDetlService.updateById(orderDetl);
+                if(!orderDetlUpdate){
+                    throw new CoolException("宸ヤ綔鏁伴噺鍥炴粴澶辫触");
                 }
 
-                //鍒犻櫎鏄庣粏鎵╁睍
-                boolean removeField = taskDetlFieldService.removeById(detlField.getId());
-                if(!removeField){
-                    throw new CoolException("鍥炴粴鎵╁睍鏄庣粏澶辫触");
+                //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
+                if (task.getTaskType() == 1) {
+                    WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getDetlId, taskDetl.getDetlId()).eq(WaitPakin::getBarcode, task.getBarcode()));
+                    if(waitPakin == null){
+                        throw new CoolException("缁勬墭閫氱煡妗d笉瀛樺湪");
+                    }
+
+                    waitPakin.setIoStatus(0);
+                    waitPakin.setUpdateTime(new Date());
+                    boolean updateWaitPakin = waitPakinService.updateById(waitPakin);
+                    if(!updateWaitPakin){
+                        throw new CoolException("缁勬墭閫氱煡妗e洖婊氬け璐�");
+                    }
                 }
-            }
+
+                List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
+                for (TaskDetlField detlField : detlFields) {
+                    //鏄庣粏鎵╁睍瀛楁鏁版嵁淇濆瓨鑷冲巻鍙叉。
+                    TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
+                    taskDetlFieldLog.sync(detlField);
+                    if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
+                        throw new CoolException("鏄庣粏鎵╁睍瀛楁杞巻鍙叉。妗堝け璐�");
+                    }
+
+                    //鍒犻櫎鏄庣粏鎵╁睍
+                    boolean removeField = taskDetlFieldService.removeById(detlField.getId());
+                    if(!removeField){
+                        throw new CoolException("鍥炴粴鎵╁睍鏄庣粏澶辫触");
+                    }
+                }
 
 
-            //鏄庣粏鏁版嵁淇濆瓨鑷冲巻鍙叉。
-            TaskDetlLog taskDetlLog = new TaskDetlLog();
-            taskDetlLog.sync(taskDetl);
-            if (!taskDetlLogService.save(taskDetlLog)) {
-                throw new CoolException("鏄庣粏鏁版嵁杞巻鍙叉。妗堝け璐�");
-            }
+                //鏄庣粏鏁版嵁淇濆瓨鑷冲巻鍙叉。
+                TaskDetlLog taskDetlLog = new TaskDetlLog();
+                taskDetlLog.sync(taskDetl);
+                if (!taskDetlLogService.save(taskDetlLog)) {
+                    throw new CoolException("鏄庣粏鏁版嵁杞巻鍙叉。妗堝け璐�");
+                }
 
-            //鍒犻櫎鏄庣粏
-            boolean removeDetl = taskDetlService.removeById(taskDetl.getId());
-            if(!removeDetl){
-                throw new CoolException("鍥炴粴鏄庣粏澶辫触");
+                //鍒犻櫎鏄庣粏
+                boolean removeDetl = taskDetlService.removeById(taskDetl.getId());
+                if(!removeDetl){
+                    throw new CoolException("鍥炴粴鏄庣粏澶辫触");
+                }
             }
         }
 

--
Gitblit v1.9.1