From ac4341ea6b66ae02427d39d35f41d42d78b2eb2e Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 14 二月 2025 10:08:32 +0800
Subject: [PATCH] #

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java |  267 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 248 insertions(+), 19 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 141bcf3..c259f0a 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
@@ -1,13 +1,20 @@
 package com.zy.asrs.wms.asrs.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.R;
 import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wms.asrs.entity.*;
 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.entity.param.LocAdjustParam;
+import com.zy.asrs.wms.asrs.entity.param.LocTransferParam;
 import com.zy.asrs.wms.asrs.service.*;
 import com.zy.asrs.wms.utils.LocUtils;
+import com.zy.asrs.wms.utils.OrderUtils;
+import com.zy.asrs.wms.utils.Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -36,6 +43,10 @@
     @Autowired
     private LocService locService;
     @Autowired
+    private LocDetlService locDetlService;
+    @Autowired
+    private LocDetlFieldService locDetlFieldService;
+    @Autowired
     private LocStsService locStsService;
     @Autowired
     private TaskLogService taskLogService;
@@ -57,6 +68,12 @@
     private LocTypeService locTypeService;
     @Autowired
     private MatService matService;
+    @Autowired
+    private OrderUtils orderUtils;
+    @Autowired
+    private WaveDetlService waveDetlService;
+    @Autowired
+    private MatFieldService matFieldService;
 
     @Override
     public String generateTaskNo(Long taskType) {
@@ -263,7 +280,7 @@
 
         Task task = new Task();
         task.setTaskNo(this.generateTaskNo(taskType.getId()));//浠诲姟鍙�
-        task.setTaskSts(1L);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.鐢熸垚鍏ュ簱浠诲姟
         task.setTaskType(taskType.getId());//浠诲姟绫诲瀷
         task.setIoPri(this.generateIoPri(taskType.getId()));//浼樺厛绾�
         task.setOriginLoc(null);
@@ -372,7 +389,7 @@
 
         Task task = new Task();
         task.setTaskNo(this.generateTaskNo(taskType.getId()));//浠诲姟鍙�
-        task.setTaskSts(1L);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.鐢熸垚鍏ュ簱浠诲姟
         task.setTaskType(taskType.getId());//浠诲姟绫诲瀷
         task.setIoPri(this.generateIoPri(taskType.getId()));//浼樺厛绾�
         task.setOriginLoc(null);
@@ -410,10 +427,15 @@
 
         if (task.getTaskType() < 100) {
             //鍏ュ簱
-            task.setTaskSts(99L);//99.鍏ュ簱瀹屾垚
+            task.setTaskSts(TaskStsType.COMPLETE_IN.id);//99.鍏ュ簱瀹屾垚
         }else {
             //鍑哄簱
-            task.setTaskSts(199L);//199.鍑哄簱瀹屾垚
+            TaskDetl taskDetl = taskDetls.get(0);
+            if (taskDetl.getWaveId() == null) {
+                task.setTaskSts(TaskStsType.COMPLETE_OUT.id);//199.鍑哄簱瀹屾垚
+            }else {
+                task.setTaskSts(TaskStsType.WAVE_SEED.id);//198.鎾涓�
+            }
         }
 
         task.setUpdateTime(new Date());
@@ -470,6 +492,53 @@
                 if(!locService.updateById(loc)){
                     throw new CoolException("搴撲綅鐘舵�佸彉鏇村け璐�");
                 }
+
+                List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
+                for (TaskDetl taskDetl : taskDetls) {
+                    if (taskDetl.getWaveId() == null) {
+                        continue;
+                    }
+
+                    String matUniqueKey = Utils.getMatUniqueKey(taskDetl.getMatnr(), taskDetl.getBatch(), taskDetl.getUniqueField());
+                    WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, taskDetl.getWaveId()));
+                    if(waveDetl == null){
+                        continue;
+                    }
+                    waveDetl.setWorkQty(waveDetl.getWorkQty() - taskDetl.getAnfme());
+                    waveDetl.setUpdateTime(new Date());
+                    if (!waveDetlService.updateById(waveDetl)) {
+                        throw new CoolException("娉㈡鏄庣粏鏇存柊澶辫触");
+                    }
+                }
+                break;
+            case 11://搴撲綅绉昏浆
+                Loc originLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
+                if(originLoc == null){
+                    throw new CoolException("婧愬簱浣嶄笉瀛樺湪");
+                }
+                if (originLoc.getLocStsId() != LocStsType.R.val()) {
+                    throw new CoolException("婧愬簱浣嶇姸鎬佷笉澶勪簬R.鍑哄簱棰勭害");
+                }
+
+                loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()));
+                if(loc == null){
+                    throw new CoolException("鐩爣搴撲綅涓嶅瓨鍦�");
+                }
+                if(loc.getLocStsId() != LocStsType.S.val()){
+                    throw new CoolException("鐩爣搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害");
+                }
+
+                originLoc.setLocStsId(LocStsType.F.val());
+                originLoc.setUpdateTime(new Date());
+                if(!locService.updateById(originLoc)){
+                    throw new CoolException("搴撲綅鐘舵�佸彉鏇村け璐�");
+                }
+
+                loc.setLocStsId(LocStsType.O.val());
+                loc.setUpdateTime(new Date());
+                if(!locService.updateById(loc)){
+                    throw new CoolException("搴撲綅鐘舵�佸彉鏇村け璐�");
+                }
                 break;
         }
 
@@ -496,19 +565,7 @@
             //鍥炴粴璁㈠崟
             for (TaskDetl taskDetl : taskDetls) {
                 if (taskDetl.getDetlId() != null) {
-                    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("宸ヤ綔鏁伴噺鍥炴粴澶辫触");
-                    }
-
+                    orderUtils.updateWorkQty(taskDetl.getDetlId(), taskDetl.getAnfme(), false);
                 }
 
                 //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
@@ -586,7 +643,7 @@
         }
 
         //鑾峰彇婧愬簱浣嶉珮搴�
-        LocTypeBind locTypeBind = locTypeBindService.getOne(new LambdaQueryWrapper<LocTypeBind>().eq(LocTypeBind::getLocId, originLoc.getId()));
+        LocTypeBind locTypeBind = locTypeBindService.getOne(new LambdaQueryWrapper<LocTypeBind>().eq(LocTypeBind::getLocId, originLoc.getId()).in(LocTypeBind::getTypeId, LocBindType.HEIGHT.list()));
         if(locTypeBind == null){
             throw new CoolException("搴撲綅绫诲瀷涓嶅瓨鍦�");
         }
@@ -613,7 +670,7 @@
             throw new CoolException("娌℃湁绌哄簱浣�");
         }
 
-        task.setTaskSts(1L);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.鐢熸垚鍏ュ簱浠诲姟
         task.setTaskType(taskType);
         task.setTargetLoc(loc.getLocNo());
         task.setUpdateTime(new Date());
@@ -631,4 +688,176 @@
 
         return true;
     }
+
+    @Override
+    @Transactional
+    public boolean locAdjust(LocAdjustParam param) {
+        if (param == null) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖");
+        }
+
+        if (Cools.isEmpty(param.getLocNo())) {
+            throw new CoolException("搴撲綅鍙蜂笉鑳戒负绌�");
+        }
+
+        if (param.getDetls() == null) {
+            throw new CoolException("搴撳瓨鏄庣粏涓嶈兘涓虹┖");
+        }
+
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getLocNo()));
+        if (loc == null) {
+            throw new CoolException("搴撲綅涓嶅瓨鍦�");
+        }
+
+        //鍒犻櫎婧愬簱瀛�
+        locDetlService.removeLocDetl(loc.getId());
+
+        List<MatField> matFields = matFieldService.list(new LambdaQueryWrapper<MatField>().eq(MatField::getUnique, 1));
+        for (Map<String, Object> map : param.getDetls()) {
+            LocDetl locDetl = JSON.parseObject(JSON.toJSONString(map), LocDetl.class);
+            HashMap<String, Object> uniqueFields = new HashMap<>();
+            for (Map.Entry<String, Object> entry : map.entrySet()) {
+                for (MatField field : matFields) {
+                    if (entry.getKey().equals(field.getName())) {
+                        uniqueFields.put(entry.getKey(), entry.getValue());
+                    }
+                }
+            }
+            locDetl.setAnfme(Double.parseDouble(map.get("qty").toString()));
+            locDetl.syncFieldMap(uniqueFields);
+
+            if (locDetl.getAnfme() <= 0D) {
+                throw new CoolException("鏁伴噺涓嶈兘灏忎簬0");
+            }
+
+            locDetl.setId(null);
+            locDetl.setLocId(loc.getId());
+            locDetl.setLocNo(loc.getLocNo());
+            boolean save = locDetlService.save(locDetl);
+            if (!save) {
+                throw new CoolException("搴撳瓨璋冩暣澶辫触");
+            }
+
+            //鎻掑叆搴撳瓨鏄庣粏瀛楁
+            for (MatField matField : matFields) {
+                LocDetlField locDetlField = new LocDetlField();
+                locDetlField.setDetlId(locDetl.getId());
+                locDetlField.setFieldId(matField.getId());
+                locDetlField.setName(matField.getName());
+                locDetlField.setValue(Optional.ofNullable(uniqueFields.get(matField.getName()).toString()).orElse(""));
+                locDetlFieldService.save(locDetlField);
+            }
+
+        }
+
+        return true;
+    }
+
+    @Override
+    @Transactional
+    public boolean locTransfer(LocTransferParam param) {
+        if (param == null) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖");
+        }
+
+        if (Cools.isEmpty(param.getSourceLocNo())) {
+            throw new CoolException("婧愬簱浣嶄笉鑳戒负绌�");
+        }
+
+        if (Cools.isEmpty(param.getTargetLocNo())) {
+            throw new CoolException("鐩爣搴撲綅涓嶈兘涓虹┖");
+        }
+
+        Loc sourceLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getSourceLocNo()));
+        if (sourceLoc == null) {
+            throw new CoolException("婧愬簱浣嶄笉瀛樺湪");
+        }
+
+        if (sourceLoc.getLocStsId() != LocStsType.F.val()) {
+            throw new CoolException("婧愬簱浣嶉潪鍦ㄥ簱鐘舵��");
+        }
+
+        Loc targetLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getTargetLocNo()));
+        if (targetLoc == null) {
+            throw new CoolException("鐩爣搴撲綅涓嶅瓨鍦�");
+        }
+
+        if(targetLoc.getLocStsId() != LocStsType.O.val()){
+            throw new CoolException("鐩爣搴撲綅闈炵┖鐘舵��");
+        }
+
+        TaskType taskType = taskTypeService.getById(11);
+        if (taskType == null) {
+            throw new CoolException("浠诲姟绫诲瀷涓嶅瓨鍦�");
+        }
+
+        Task task = new Task();
+        task.setTaskNo(this.generateTaskNo(taskType.getId()));//浠诲姟鍙�
+        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.鐢熸垚鍏ュ簱浠诲姟
+        task.setTaskType(taskType.getId());//浠诲姟绫诲瀷
+        task.setIoPri(this.generateIoPri(taskType.getId()));//浼樺厛绾�
+        task.setOriginLoc(param.getSourceLocNo());
+        task.setTargetLoc(param.getTargetLocNo());
+        task.setOriginSite(null);
+        task.setTargetSite(null);
+        task.setBarcode(sourceLoc.getBarcode());//鎵樼洏鐮�
+        boolean taskSave = taskService.save(task);
+        if (!taskSave) {
+            throw new CoolException("浠诲姟鐢熸垚澶辫触");
+        }
+
+        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId()));
+        if(locDetls.isEmpty()){
+            throw new CoolException("婧愬簱浣嶆槑缁嗕笉瀛樺湪");
+        }
+
+        //鐢熸垚浠诲姟鏄庣粏
+        for (LocDetl locDetl : locDetls) {
+            TaskDetl taskDetl = new TaskDetl();
+            taskDetl.setTaskId(task.getId());
+            taskDetl.setTaskNo(task.getTaskNo());
+            taskDetl.setAnfme(locDetl.getAnfme());//鏁伴噺
+            taskDetl.setStock(0D);//搴撳瓨
+            taskDetl.setBatch(locDetl.getBatch());//鎵瑰彿
+            taskDetl.setBarcode(sourceLoc.getBarcode());
+            taskDetl.setMatId(locDetl.getMatId());
+            taskDetl.setMatnr(locDetl.getMatnr());
+            boolean taskDetlSave = taskDetlService.save(taskDetl);
+            if(!taskDetlSave){
+                throw new CoolException("浠诲姟鏄庣粏鐢熸垚澶辫触");
+            }
+
+            //鐢熸垚鏄庣粏鎵╁睍
+            List<LocDetlField> locDetlFieldList = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()));
+            for (LocDetlField locDetlField : locDetlFieldList) {
+                TaskDetlField taskDetlField = new TaskDetlField();
+                taskDetlField.setName(locDetlField.getName());
+                taskDetlField.setFieldId(locDetlField.getFieldId());
+                taskDetlField.setDetlId(taskDetl.getId());
+                taskDetlField.setValue(locDetlField.getValue());
+                boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
+                if(!taskDetlFieldSave){
+                    throw new CoolException("鏄庣粏鎵╁睍鐢熸垚澶辫触");
+                }
+            }
+        }
+
+        //搴撲綅F => R
+        sourceLoc.setLocStsId(LocStsType.R.val());
+        sourceLoc.setUpdateTime(new Date());
+        boolean sourceLocUpdate = locService.updateById(sourceLoc);
+        if(!sourceLocUpdate){
+            throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
+        }
+
+        //搴撲綅O => S
+        targetLoc.setLocStsId(LocStsType.S.val());
+        targetLoc.setUpdateTime(new Date());
+        boolean targetLocUpdate = locService.updateById(targetLoc);
+        if(!targetLocUpdate){
+            throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
+        }
+
+        return true;
+    }
 }

--
Gitblit v1.9.1