From c6c9b7d3baa822765768c110304d27623f946286 Mon Sep 17 00:00:00 2001
From: pjb <123456>
Date: 星期二, 15 七月 2025 14:29:09 +0800
Subject: [PATCH] `1`
---
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java | 1548 ++++++++++++++++++++++++++++++++++-------------------------
1 files changed, 895 insertions(+), 653 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 97ceb6c..ba6dff2 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,653 +1,895 @@
-package com.zy.asrs.wms.asrs.service.impl;
-
-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.*;
-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 com.zy.asrs.wms.utils.Utils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.*;
-
-@Service("workService")
-public class WorkServiceImpl implements WorkService {
-
- @Autowired
- private TaskService taskService;
- @Autowired
- private TaskDetlService taskDetlService;
- @Autowired
- private WaitPakinService waitPakinService;
- @Autowired
- private TaskTypeService taskTypeService;
- @Autowired
- private OrderDetlFieldService orderDetlFieldService;
- @Autowired
- private TaskDetlFieldService taskDetlFieldService;
- @Autowired
- private OrderService orderService;
- @Autowired
- private OrderDetlService orderDetlService;
- @Autowired
- private LocService locService;
- @Autowired
- private LocStsService locStsService;
- @Autowired
- private TaskLogService taskLogService;
- @Autowired
- private TaskDetlLogService taskDetlLogService;
- @Autowired
- 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;
- @Autowired
- private WaveDetlService waveDetlService;
-
- @Override
- public String generateTaskNo(Long taskType) {
- Random random = new Random();
- int nextInt = random.nextInt(99999);
- return "R" + nextInt;
- }
-
- @Override
- public Integer generateIoPri(Long taskType) {
- return 10;
- }
-
- @Override
- 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("鏈厤缃笂鏋惰鍒�");
- }
- 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;
-
- 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;
- }
- }
- }
- }
-
- return defaultLoc;
- }
-
- @Override
- 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("鎵樼洏鏈粍鎵�");
- }
-
- WaitPakin waitPakin = waitPakins.get(0);
- OrderDetl detl = waitPakin.getDetl$();
- 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;
-
- 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;
- }
- }
-
- 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;
- }
- }
- }
- }
- return defaultLoc;
- }
-
- @Override
- @Transactional
- public boolean generatePakIn(GeneratePakInParam param) {
- List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, param.getBarcode()));
- if (param.getTaskType() != 10 && waitPakins.isEmpty()) {
- throw new CoolException("鎵樼洏鏈粍鎵�");
- }
-
- TaskType taskType = taskTypeService.getById(param.getTaskType());
- if (taskType == null) {
- 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(), param.getBarcode(), param.getLocTypeHeight());
- if(loc == 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(null);
- task.setTargetLoc(loc.getLocNo());
- task.setOriginSite(param.getOriginSite());
- task.setTargetSite(null);
- task.setBarcode(param.getBarcode());//鎵樼洏鐮�
- boolean taskSave = taskService.save(task);
- if (!taskSave) {
- throw new CoolException("浠诲姟鐢熸垚澶辫触");
- }
-
- //鐢熸垚浠诲姟鏄庣粏
- for (WaitPakin waitPakin : waitPakins) {
- TaskDetl taskDetl = new TaskDetl();
- taskDetl.setTaskId(task.getId());
- taskDetl.setTaskNo(task.getTaskNo());
- taskDetl.setAnfme(waitPakin.getAnfme());//鏁伴噺
- taskDetl.setStock(0D);//搴撳瓨
- taskDetl.setBatch(waitPakin.getDetl$().getBatch());//鎵瑰彿
- taskDetl.setBarcode(waitPakin.getBarcode());
- taskDetl.setOrderId(waitPakin.getOrderId());
- 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("浠诲姟鏄庣粏鐢熸垚澶辫触");
- }
-
- //鐢熸垚鏄庣粏鎵╁睍
- List<OrderDetlField> orderDetlFields = orderDetlFieldService.list(new LambdaQueryWrapper<OrderDetlField>().eq(OrderDetlField::getDetlId, waitPakin.getDetlId()));
- for (OrderDetlField orderDetlField : orderDetlFields) {
- TaskDetlField taskDetlField = new TaskDetlField();
- taskDetlField.setName(orderDetlField.getName());
- taskDetlField.setFieldId(orderDetlField.getFieldId());
- taskDetlField.setDetlId(taskDetl.getId());
- taskDetlField.setValue(orderDetlField.getValue());
- boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
- if(!taskDetlFieldSave){
- throw new CoolException("鏄庣粏鎵╁睍鐢熸垚澶辫触");
- }
- }
-
- //鏇存柊缁勬墭閫氱煡妗�
- waitPakin.setIoStatus(1);
- waitPakin.setUpdateTime(new Date());
- boolean waitPakinUpdate = waitPakinService.updateById(waitPakin);
- if(!waitPakinUpdate){
- throw new CoolException("缁勬墭閫氱煡妗f洿鏂板け璐�");
- }
-
- //鏇存柊璁㈠崟鏄庣粏鏁版嵁
- 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("璁㈠崟鏄庣粏鏇存柊澶辫触");
- }
-
- //鑾峰彇璁㈠崟
- 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(TaskStsType.GENERATE_IN.id);//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
- loc.setLocStsId(LocStsType.S.val());
- loc.setUpdateTime(new Date());
- boolean locUpdate = locService.updateById(loc);
- if(!locUpdate){
- throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
- }
-
- return true;
- }
-
- @Override
- public boolean completeTask(Long taskId) {
- Task task = taskService.getById(taskId);
- if(task == null){
- throw new CoolException("浠诲姟涓嶅瓨鍦�");
- }
-
- List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
- if (taskDetls.isEmpty()) {
- throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
- }
-
- if (task.getTaskType() < 100) {
- //鍏ュ簱
- task.setTaskSts(TaskStsType.COMPLETE_IN.id);//99.鍏ュ簱瀹屾垚
- }else {
- //鍑哄簱
- 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());
- if (!taskService.updateById(task)) {
- throw new CoolException("浠诲姟鏇存柊澶辫触");
- }
-
- return true;
- }
-
- @Override
- @Transactional
- public boolean cancelTask(Long taskId) {
- Task task = taskService.getById(taskId);
- if(task == null){
- throw new CoolException("浠诲姟涓嶅瓨鍦�");
- }
-
- //鏇存柊搴撲綅鐘舵��
- Loc loc = null;
- switch (task.getTaskType().intValue()) {
- case 1://鍏ュ簱
- case 10://绌烘澘
- case 53://鎷f枡
- case 54://骞舵澘
- case 57://鐩樼偣
- 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.鍏ュ簱棰勭害");
- }
- loc.setLocStsId(LocStsType.O.val());
- loc.setUpdateTime(new Date());
- if(!locService.updateById(loc)){
- throw new CoolException("搴撲綅鐘舵�佸彉鏇村け璐�");
- }
- break;
- case 101://鍑哄簱
- 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("搴撲綅涓嶅瓨鍦�");
- }
- if(loc.getLocStsId() != LocStsType.R.val()){
- throw new CoolException("搴撲綅鐘舵�佷笉澶勪簬R.鍑哄簱棰勭害");
- }
- loc.setLocStsId(LocStsType.F.val());
- loc.setUpdateTime(new Date());
- 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;
- }
-
- //鏁版嵁淇濆瓨鑷冲巻鍙叉。
- 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()) {
- throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
- }
-
- //鍥炴粴璁㈠崟
- for (TaskDetl taskDetl : taskDetls) {
- if (taskDetl.getDetlId() != null) {
- orderUtils.updateWorkQty(taskDetl.getDetlId(), taskDetl.getAnfme(), false);
- }
-
- //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
- 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洖婊氬け璐�");
- }
- }
-
- //鏄庣粏鏁版嵁淇濆瓨鑷冲巻鍙叉。
- 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("鏄庣粏鎵╁睍瀛楁杞巻鍙叉。妗堝け璐�");
- }
-
- //鍒犻櫎鏄庣粏鎵╁睍
- boolean removeField = taskDetlFieldService.removeById(detlField.getId());
- if(!removeField){
- throw new CoolException("鍥炴粴鎵╁睍鏄庣粏澶辫触");
- }
- }
- }
- }
-
- return true;
- }
-
- @Override
- public boolean pickTask(Long taskId) {
- Task task = taskService.getById(taskId);
- if(task == null){
- 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(TaskStsType.GENERATE_IN.id);//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;
- }
-}
+package com.zy.asrs.wms.asrs.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.DateUtils;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+
+@Service("workService")
+public class WorkServiceImpl implements WorkService {
+
+ public static final Logger logger = LoggerFactory.getLogger(WorkServiceImpl.class);
+
+ @Autowired
+ private TaskService taskService;
+ @Autowired
+ private TaskDetlService taskDetlService;
+ @Autowired
+ private WaitPakinService waitPakinService;
+ @Autowired
+ private TaskTypeService taskTypeService;
+ @Autowired
+ private OrderDetlFieldService orderDetlFieldService;
+ @Autowired
+ private TaskDetlFieldService taskDetlFieldService;
+ @Autowired
+ private OrderService orderService;
+ @Autowired
+ private OrderDetlService orderDetlService;
+ @Autowired
+ private LocService locService;
+ @Autowired
+ private LocDetlService locDetlService;
+ @Autowired
+ private LocDetlFieldService locDetlFieldService;
+ @Autowired
+ private LocStsService locStsService;
+ @Autowired
+ private TaskLogService taskLogService;
+ @Autowired
+ private TaskDetlLogService taskDetlLogService;
+ @Autowired
+ 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;
+ @Autowired
+ private WaveDetlService waveDetlService;
+ @Autowired
+ private MatFieldService matFieldService;
+
+ @Override
+ public String generateTaskNo(Long taskType) {
+ String format = DateUtils.format(new Date(), "MMddHHmm");
+ Random random = new Random();
+ int nextInt = random.nextInt(99999);
+ logger.info("R" + format + nextInt);
+ return "R" + format + nextInt;
+ }
+
+ @Override
+ public Integer generateIoPri(Long taskType) {
+ return 10;
+ }
+
+ @Override
+ 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("鏈厤缃笂鏋惰鍒�");
+ }
+ 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;
+
+ 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)) {
+ return locUtils.getGlobalEmptyLocToCtu(locTypeHeight);
+ //浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
+// List<Loc> globalLoc = locUtils.getGlobalEmptyLoc(taskType, locTypeHeight, laneRowList, currentLev);
+// //鑾峰彇搴撲綅
+// if (!globalLoc.isEmpty()) {
+// defaultLoc = locUtils.filterAllLoc(globalLoc);
+// if (defaultLoc != null) {
+// return defaultLoc;
+// }
+// }
+ }
+ }
+
+ return defaultLoc;
+ }
+
+ @Override
+ 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("鎵樼洏鏈粍鎵�");
+ }
+
+ WaitPakin waitPakin = waitPakins.get(0);
+ OrderDetl detl = waitPakin.getDetl$();
+ 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;
+
+ 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;
+ }
+ }
+
+ 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)) {
+ return locUtils.getGlobalEmptyLocToCtu(locTypeHeight);
+ //浠庡叏灞�搴撲綅涓幏鍙�(瀹屾暣宸烽亾)
+// List<Loc> globalLoc = locUtils.getGlobalLoc(taskType, locTypeHeight, laneRowList, currentLev);
+// //鑾峰彇搴撲綅
+// if (!globalLoc.isEmpty()) {
+// defaultLoc = locUtils.filterAllLoc(globalLoc);
+// if (defaultLoc != null) {
+// return defaultLoc;
+// }
+// }
+ }
+ }
+ return defaultLoc;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean generatePakIn(GeneratePakInParam param) {
+ List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, param.getBarcode()));
+ if (param.getTaskType() != 10 && waitPakins.isEmpty()) {
+ throw new CoolException("鎵樼洏鏈粍鎵�");
+ }
+
+ TaskType taskType = taskTypeService.getById(param.getTaskType());
+ if (taskType == null) {
+ 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(), param.getBarcode(), param.getLocTypeHeight());
+ if (loc == null) {
+ throw new CoolException("娌℃湁绌哄簱浣�");
+ }
+
+ Task task = new Task();
+ //浠诲姟鍙�
+ task.setTaskNo(this.generateTaskNo(taskType.getId()));
+ //1.鐢熸垚鍏ュ簱浠诲姟
+ task.setTaskSts(TaskStsType.GENERATE_IN.id);
+ //浠诲姟绫诲瀷
+ 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(param.getBarcode());
+ boolean taskSave = taskService.save(task);
+ if (!taskSave) {
+ throw new CoolException("浠诲姟鐢熸垚澶辫触");
+ }
+
+ //鐢熸垚浠诲姟鏄庣粏
+ for (WaitPakin waitPakin : waitPakins) {
+ TaskDetl taskDetl = new TaskDetl();
+ taskDetl.setTaskId(task.getId());
+ taskDetl.setTaskNo(task.getTaskNo());
+ //鏁伴噺
+ taskDetl.setAnfme(waitPakin.getAnfme());
+ //搴撳瓨
+ taskDetl.setStock(0D);
+ //鎵瑰彿
+ taskDetl.setBatch(waitPakin.getDetl$().getBatch());
+ taskDetl.setBarcode(waitPakin.getBarcode());
+ taskDetl.setOrderId(waitPakin.getOrderId());
+ 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("浠诲姟鏄庣粏鐢熸垚澶辫触");
+ }
+
+ //鐢熸垚鏄庣粏鎵╁睍
+ List<OrderDetlField> orderDetlFields = orderDetlFieldService.list(new LambdaQueryWrapper<OrderDetlField>().eq(OrderDetlField::getDetlId, waitPakin.getDetlId()));
+ for (OrderDetlField orderDetlField : orderDetlFields) {
+ TaskDetlField taskDetlField = new TaskDetlField();
+ taskDetlField.setName(orderDetlField.getName());
+ taskDetlField.setFieldId(orderDetlField.getFieldId());
+ taskDetlField.setDetlId(taskDetl.getId());
+ taskDetlField.setValue(orderDetlField.getValue());
+ boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
+ if (!taskDetlFieldSave) {
+ throw new CoolException("鏄庣粏鎵╁睍鐢熸垚澶辫触");
+ }
+ }
+
+ //鏇存柊缁勬墭閫氱煡妗�
+ waitPakin.setIoStatus(1);
+ waitPakin.setUpdateTime(new Date());
+ boolean waitPakinUpdate = waitPakinService.updateById(waitPakin);
+ if (!waitPakinUpdate) {
+ throw new CoolException("缁勬墭閫氱煡妗f洿鏂板け璐�");
+ }
+
+ //鏇存柊璁㈠崟鏄庣粏鏁版嵁
+ 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("璁㈠崟鏄庣粏鏇存柊澶辫触");
+ }
+
+ //鑾峰彇璁㈠崟
+ 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(TaskStsType.GENERATE_IN.id);//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
+ loc.setLocStsId(LocStsType.S.val());
+ loc.setUpdateTime(new Date());
+ boolean locUpdate = locService.updateById(loc);
+ if (!locUpdate) {
+ throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean completeTask(Long taskId) {
+ Task task = taskService.getById(taskId);
+ if (task == null) {
+ throw new CoolException("浠诲姟涓嶅瓨鍦�");
+ }
+
+ List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
+ if (taskDetls.isEmpty()) {
+ throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
+ }
+
+ if (task.getTaskType() < 100) {
+ //鍏ュ簱
+ task.setTaskSts(TaskStsType.COMPLETE_IN.id);//99.鍏ュ簱瀹屾垚
+ } else {
+ //鍑哄簱
+ TaskDetl taskDetl = taskDetls.get(0); //TODO 鍑哄簱娴佺▼寰呯‘璁わ紝ESS鍙栬揣鍚庯紝杈撻�佺嚎娴佽浆鍒版壂鐮佸鐘舵��
+ if (taskDetl.getWaveId() == null && task.getTaskType() != 103 && task.getTaskType() != 107) {
+ task.setTaskSts(TaskStsType.COMPLETE_OUT.id);//199.鍑哄簱瀹屾垚
+ } else {
+ task.setTaskSts(TaskStsType.WAVE_SEED.id);//198.鎾涓�
+ }
+ }
+ task.setUpdateTime(new Date());
+ if (!taskService.updateById(task)) {
+ throw new CoolException("浠诲姟鏇存柊澶辫触");
+ }
+
+ return true;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean cancelTask(Long taskId) {
+ Task task = taskService.getById(taskId);
+ if (task == null) {
+ throw new CoolException("浠诲姟涓嶅瓨鍦�");
+ }
+
+ //鏇存柊搴撲綅鐘舵��
+ Loc loc = null;
+ switch (task.getTaskType().intValue()) {
+ case 1://鍏ュ簱
+ case 10://绌烘澘
+ case 53://鎷f枡
+ case 54://骞舵澘
+ case 57://鐩樼偣
+ 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.鍏ュ簱棰勭害");
+ }
+ loc.setLocStsId(LocStsType.O.val());
+ loc.setUpdateTime(new Date());
+ if (!locService.updateById(loc)) {
+ throw new CoolException("搴撲綅鐘舵�佸彉鏇村け璐�");
+ }
+ break;
+ case 101://鍑哄簱
+ 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("搴撲綅涓嶅瓨鍦�");
+ }
+ if (loc.getLocStsId() != LocStsType.R.val()) {
+ throw new CoolException("搴撲綅鐘舵�佷笉澶勪簬R.鍑哄簱棰勭害");
+ }
+ loc.setLocStsId(LocStsType.F.val());
+ loc.setUpdateTime(new Date());
+ 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;
+ }
+
+ //鏁版嵁淇濆瓨鑷冲巻鍙叉。
+ 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()) {
+ throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
+ }
+
+ //鍥炴粴璁㈠崟
+ for (TaskDetl taskDetl : taskDetls) {
+ if (taskDetl.getDetlId() != null) {
+ orderUtils.updateWorkQty(taskDetl.getDetlId(), taskDetl.getAnfme(), false);
+ }
+
+ //鍏ュ簱鍥炴粴缁勬墭閫氱煡妗�
+ 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洖婊氬け璐�");
+ }
+ }
+
+ //鏄庣粏鏁版嵁淇濆瓨鑷冲巻鍙叉。
+ 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("鏄庣粏鎵╁睍瀛楁杞巻鍙叉。妗堝け璐�");
+ }
+
+ //鍒犻櫎鏄庣粏鎵╁睍
+ boolean removeField = taskDetlFieldService.removeById(detlField.getId());
+ if (!removeField) {
+ throw new CoolException("鍥炴粴鎵╁睍鏄庣粏澶辫触");
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean pickTask(Long taskId) {
+ Task task = taskService.getById(taskId);
+ if (task == null) {
+ throw new CoolException("浠诲姟涓嶅瓨鍦�");
+ }
+
+ if (task.getTaskType() != 103 && task.getTaskType() != 107) {
+ throw new CoolException("浠诲姟绫诲瀷涓嶅彲鎷f枡");
+ }
+
+ if (task.getTaskSts() != 198) {
+ 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);
+ //鐢熸垚鏂扮殑搴撲綅 !important
+// Loc loc = this.generateLoc(taskType, taskDetl.getMatId(), taskDetl.getBatch(), taskDetl.getUniqueField(), locTypeHeightType.id);
+// if(loc == null) {
+// throw new CoolException("娌℃湁绌哄簱浣�");
+// }
+ Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
+ if (loc == null) {
+ throw new CoolException("娌℃湁绌哄簱浣�");
+ }
+ // 鑾峰彇鏂颁换鍔″彿
+ String taskNo = generateTaskNo(53L);
+ // 璁剧疆鏂颁换鍔″彿
+ task.setTaskNo(taskNo);
+ //102鎷f枡姝ゅ闇�淇敼涓篧CS_CONTAINER_RECEIVE,瀹氭椂浠诲姟鏌ヨ鍚庯紝鑷姩涓嬪彂鍏ュ簱浠诲姟鑷矱SS
+ task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.鐢熸垚鍏ュ簱浠诲姟
+ task.setTaskType(taskType);
+ //鍘熷簱浣嶅彉鐩爣搴撲綅, 鍘熺珯鐐瑰彉鐩爣绔欑偣
+ //todo 闇�纭鍘熺珯鐐逛负绌猴紝璇ユ�庝箞澶勭悊
+ task.setTargetLoc(task.getOriginLoc());
+ task.setUpdateTime(new Date());
+ if (!taskService.updateById(task)) {
+ throw new CoolException("鎷f枡澶辫触");
+ }
+ // 鏇存柊浠诲姟鏄庣粏鏂颁换鍔″彿
+ UpdateWrapper<TaskDetl> updateWrapper = new UpdateWrapper<>();
+ updateWrapper.set("task_no",taskNo).eq("task_id",task.getId());
+ //搴撲綅鐘舵�佹敼涓洪绾﹀叆搴� R => S
+ loc.setLocStsId(LocStsType.S.val());
+ loc.setUpdateTime(new Date());
+ boolean locUpdate = locService.updateById(loc);
+ if (!locUpdate) {
+ throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
+ }
+
+ return true;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ 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