From fb4e7fd8575a97467a972028a91484f71985656c Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 12 九月 2024 17:03:47 +0800
Subject: [PATCH] #

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java |  325 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 244 insertions(+), 81 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 1c6c199..92c9b51 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
@@ -3,11 +3,12 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.*;
+import com.zy.asrs.wms.asrs.entity.param.FieldParam;
 import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
 import com.zy.asrs.wms.asrs.service.*;
 import com.zy.asrs.wms.utils.LocUtils;
+import com.zy.asrs.wms.utils.OrderUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -45,6 +46,20 @@
     private TaskDetlFieldLogService taskDetlFieldLogService;
     @Autowired
     private LocUtils locUtils;
+    @Autowired
+    private ShelvesRuleService shelvesRuleService;
+    @Autowired
+    private LanewayRuleService lanewayRuleService;
+    @Autowired
+    private CircleRuleService circleRuleService;
+    @Autowired
+    private LocTypeBindService locTypeBindService;
+    @Autowired
+    private LocTypeService locTypeService;
+    @Autowired
+    private MatService matService;
+    @Autowired
+    private OrderUtils orderUtils;
 
     @Override
     public String generateTaskNo(Long taskType) {
@@ -60,31 +75,68 @@
 
     @Override
     public Loc generateEmptyLoc(Long taskType, Integer locTypeHeight) {
-        Loc defaultLoc = null;
-
-        //1.浠庡簱瀛樻垨浠诲姟涓尮閰嶇浉閭诲簱浣�
-        defaultLoc = locUtils.getNeighborEmptyLoc(taskType, locTypeHeight);
-        if (defaultLoc != null) {
-            return defaultLoc;
+        List<ShelvesRule> shelvesRules = shelvesRuleService.list(new LambdaQueryWrapper<ShelvesRule>().eq(ShelvesRule::getStatus, 1).orderByDesc(ShelvesRule::getCreateTime));
+        if(shelvesRules.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒�");
         }
-
-        //2.鑾峰彇鎺ㄨ崘搴撲綅
-        List<Loc> suggestLoc = locUtils.getSuggestEmptyLoc(taskType, locTypeHeight);
-        //鑾峰彇搴撲綅
-        if (!suggestLoc.isEmpty()) {
-            defaultLoc = locUtils.filterLoc(taskType, suggestLoc);
-            if(defaultLoc != null) {
-                return defaultLoc;
+        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$());
             }
         }
 
-        //3.浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
-        List<Loc> globalLoc = locUtils.getGlobalEmptyLoc(taskType, locTypeHeight);
-        //鑾峰彇搴撲綅
-        if (!globalLoc.isEmpty()) {
-            defaultLoc = locUtils.filterAllLoc(globalLoc);
-            if(defaultLoc != null) {
-                return defaultLoc;
+        Integer currentLev = null;
+        if (shelvesRule.getRuleType().equals(ShelvesRuleType.HIGH.id)) {
+            //浼樺厛绔嬩綋灞�
+            currentLev = circleRuleService.getCurrentValueByFlag(CircleRuleType.LEV.flag);
+        }
+
+        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, currentLev);
+                //鑾峰彇搴撲綅
+                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, currentLev);
+                //鑾峰彇搴撲綅
+                if (!globalLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterAllLoc(globalLoc);
+                    if(defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
             }
         }
 
@@ -92,7 +144,7 @@
     }
 
     @Override
-    public Loc generateLoc(Long taskType, String barcode, Integer locTypeHeight) {
+    public synchronized 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("鎵樼洏鏈粍鎵�");
@@ -103,40 +155,88 @@
         if (detl == null) {
             throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
         }
+        String batch = detl.getBatch();
+        List<FieldParam> uniqueFields = detl.getUniqueField();
 
         Mat mat = detl.getMat$();
         if (mat == null) {
             throw new CoolException("鍟嗗搧涓嶅瓨鍦�");
         }
 
+        return generateLoc(taskType, mat.getId(), batch, uniqueFields, locTypeHeight);
+    }
+
+    @Override
+    public synchronized Loc generateLoc(Long taskType, Long matId, String batch, List<FieldParam> uniqueFields, Integer locTypeHeight) {
+        Mat mat = matService.getById(matId);
+        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$());
+            }
+        }
+
+        Integer currentLev = null;
+        if (shelvesRule.getRuleType().equals(ShelvesRuleType.HIGH.id)) {
+            //浼樺厛绔嬩綋灞�
+            currentLev = circleRuleService.getCurrentValueByFlag(CircleRuleType.LEV.flag);
+        }
+
+        List<ShelvesRuleDetl> ruleDetls = shelvesRule.getRuleDetl$();
+        if (ruleDetls.isEmpty()) {
+            throw new CoolException("鏈厤缃笂鏋惰鍒欐槑缁�");
+        }
+
         Loc defaultLoc = null;
 
-        //1.浠庡簱瀛樻垨浠诲姟涓尮閰嶇浉閭诲簱浣�
-        defaultLoc = locUtils.getNeighborLoc(taskType, detl, locTypeHeight);
-        if (defaultLoc != null) {
-            return defaultLoc;
-        }
+        for (ShelvesRuleDetl ruleDetl : ruleDetls) {
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.TASK_OR_LOC.id)) {
+                //浠庡簱瀛樻垨浠诲姟涓尮閰嶇浉閭诲簱浣�
+                defaultLoc = locUtils.getNeighborLoc(taskType, mat.getId(), batch, uniqueFields, locTypeHeight);
+                if (defaultLoc != null) {
+                    return defaultLoc;
+                }
+            }
 
-        //2.鑾峰彇鎺ㄨ崘搴撲綅
-        List<Loc> suggestLoc = locUtils.getSuggestLoc(taskType, mat.getId(), detl.getBatch(), locTypeHeight);
-        //鑾峰彇搴撲綅
-        if (!suggestLoc.isEmpty()) {
-            defaultLoc = locUtils.filterLoc(taskType, suggestLoc);
-            if(defaultLoc != null) {
-                return defaultLoc;
+            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.SUGGEST.id)) {
+                //鑾峰彇鎺ㄨ崘搴撲綅
+                List<Loc> suggestLoc = locUtils.getSuggestLoc(taskType, mat.getId(), batch, locTypeHeight, laneRowList, currentLev);
+                //鑾峰彇搴撲綅
+                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, currentLev);
+                //鑾峰彇搴撲綅
+                if (!globalLoc.isEmpty()) {
+                    defaultLoc = locUtils.filterAllLoc(globalLoc);
+                    if (defaultLoc != null) {
+                        return defaultLoc;
+                    }
+                }
             }
         }
-
-        //3.浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
-        List<Loc> globalLoc = locUtils.getGlobalLoc(taskType, locTypeHeight);
-        //鑾峰彇搴撲綅
-        if (!globalLoc.isEmpty()) {
-            defaultLoc = locUtils.filterAllLoc(globalLoc);
-            if(defaultLoc != null) {
-                return defaultLoc;
-            }
-        }
-
         return defaultLoc;
     }
 
@@ -376,6 +476,20 @@
                 break;
         }
 
+        //鏁版嵁淇濆瓨鑷冲巻鍙叉。
+        TaskLog taskLog = new TaskLog();
+        taskLog.sync(task);
+        taskLog.setId(null);
+        if (!taskLogService.save(taskLog)) {
+            throw new CoolException("浠诲姟妗f杞巻鍙叉。妗堝け璐�");
+        }
+
+        //鍒犻櫎浠诲姟
+        boolean removeTask = taskService.removeById(taskId);
+        if(!removeTask){
+            throw new CoolException("鍥炴粴浠诲姟澶辫触");
+        }
+
         if (task.getTaskType() != 10) {
             List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
             if (taskDetls.isEmpty()) {
@@ -384,17 +498,8 @@
 
             //鍥炴粴璁㈠崟
             for (TaskDetl taskDetl : taskDetls) {
-                OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
-                if(orderDetl == null){
-                    throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�");
-                }
-
-                //鍥炴粴宸ヤ綔鏁伴噺
-                orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());
-                orderDetl.setUpdateTime(new Date());
-                boolean orderDetlUpdate = orderDetlService.updateById(orderDetl);
-                if(!orderDetlUpdate){
-                    throw new CoolException("宸ヤ綔鏁伴噺鍥炴粴澶辫触");
+                if (taskDetl.getDetlId() != null) {
+                    orderUtils.updateWorkQty(taskDetl.getDetlId(), taskDetl.getAnfme(), false);
                 }
 
                 //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
@@ -412,11 +517,28 @@
                     }
                 }
 
+                //鏄庣粏鏁版嵁淇濆瓨鑷冲巻鍙叉。
+                TaskDetlLog taskDetlLog = new TaskDetlLog();
+                taskDetlLog.sync(taskDetl);
+                taskDetlLog.setId(null);
+                taskDetlLog.setTaskId(taskLog.getId());
+                if (!taskDetlLogService.save(taskDetlLog)) {
+                    throw new CoolException("鏄庣粏鏁版嵁杞巻鍙叉。妗堝け璐�");
+                }
+
+                //鍒犻櫎鏄庣粏
+                boolean removeDetl = taskDetlService.removeById(taskDetl.getId());
+                if(!removeDetl){
+                    throw new CoolException("鍥炴粴鏄庣粏澶辫触");
+                }
+
                 List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
                 for (TaskDetlField detlField : detlFields) {
                     //鏄庣粏鎵╁睍瀛楁鏁版嵁淇濆瓨鑷冲巻鍙叉。
                     TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
                     taskDetlFieldLog.sync(detlField);
+                    taskDetlFieldLog.setId(null);
+                    taskDetlFieldLog.setDetlId(taskDetlLog.getId());
                     if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
                         throw new CoolException("鏄庣粏鎵╁睍瀛楁杞巻鍙叉。妗堝け璐�");
                     }
@@ -427,34 +549,75 @@
                         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("鍥炴粴鏄庣粏澶辫触");
-                }
             }
         }
 
-        //鏁版嵁淇濆瓨鑷冲巻鍙叉。
-        TaskLog taskLog = new TaskLog();
-        taskLog.sync(task);
-        if (!taskLogService.save(taskLog)) {
-            throw new CoolException("浠诲姟妗f杞巻鍙叉。妗堝け璐�");
+        return true;
+    }
+
+    @Override
+    public boolean pickTask(Long taskId) {
+        Task task = taskService.getById(taskId);
+        if(task == null){
+            throw new CoolException("浠诲姟涓嶅瓨鍦�");
         }
 
-        //鍒犻櫎浠诲姟
-        boolean removeTask = taskService.removeById(taskId);
-        if(!removeTask){
-            throw new CoolException("鍥炴粴浠诲姟澶辫触");
+        if (task.getTaskType() != 103) {
+            throw new CoolException("浠诲姟绫诲瀷涓嶅彲鎷f枡");
+        }
+
+        if (task.getTaskSts() != 200) {
+            throw new CoolException("褰撳墠鐘舵�佷笉鍙嫞鏂�");
+        }
+
+        //鑾峰彇婧愬簱浣�
+        Loc originLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
+        if(originLoc == null){
+            throw new CoolException("婧愬簱浣嶄笉瀛樺湪");
+        }
+
+        //鑾峰彇婧愬簱浣嶉珮搴�
+        LocTypeBind locTypeBind = locTypeBindService.getOne(new LambdaQueryWrapper<LocTypeBind>().eq(LocTypeBind::getLocId, originLoc.getId()).in(LocTypeBind::getTypeId, LocBindType.HEIGHT.list()));
+        if(locTypeBind == null){
+            throw new CoolException("搴撲綅绫诲瀷涓嶅瓨鍦�");
+        }
+        LocType locType = locTypeService.getById(locTypeBind.getTypeId());
+        if(locType == null){
+            throw new CoolException("搴撲綅绫诲瀷涓嶅瓨鍦�");
+        }
+        LocTypeHeightType locTypeHeightType = LocTypeHeightType.get(locType.getFlag());
+        if(locTypeHeightType == null){
+            throw new CoolException("楂樹綆搴撲綅绫诲瀷涓嶅瓨鍦�");
+        }
+
+        Long taskType = task.getTaskType() - 50;
+
+        List<TaskDetl> taskDetls = taskDetlService.list(new LambdaQueryWrapper<TaskDetl>().eq(TaskDetl::getTaskId, taskId).gt(TaskDetl::getAnfme, 0));
+        if (taskDetls.isEmpty()) {
+            throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
+        }
+        TaskDetl taskDetl = taskDetls.get(0);
+
+        //鐢熸垚搴撲綅
+        Loc loc = this.generateLoc(taskType, taskDetl.getMatId(), taskDetl.getBatch(), taskDetl.getUniqueField(), locTypeHeightType.id);
+        if(loc == null) {
+            throw new CoolException("娌℃湁绌哄簱浣�");
+        }
+
+        task.setTaskSts(1L);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskType(taskType);
+        task.setTargetLoc(loc.getLocNo());
+        task.setUpdateTime(new Date());
+        if (!taskService.updateById(task)) {
+            throw new CoolException("鎷f枡澶辫触");
+        }
+
+        //搴撲綅O => S
+        loc.setLocStsId(LocStsType.S.val());
+        loc.setUpdateTime(new Date());
+        boolean locUpdate = locService.updateById(loc);
+        if(!locUpdate){
+            throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
         }
 
         return true;

--
Gitblit v1.9.1