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/timer/TaskLogTimer.java | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 153 insertions(+), 7 deletions(-) diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskLogTimer.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskLogTimer.java index 2ede7d5..a64b3a9 100644 --- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskLogTimer.java +++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskLogTimer.java @@ -3,10 +3,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; +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.OrderSettleType; +import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; import com.zy.asrs.wms.asrs.service.*; +import com.zy.asrs.wms.system.entity.Dict; +import com.zy.asrs.wms.system.service.DictService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -35,6 +39,10 @@ private OrderService orderService; @Autowired private OrderDetlService orderDetlService; + @Autowired + private DictService dictService; + @Autowired + private WaveService waveService; @Scheduled(cron = "0/3 * * * * ? ") @Transactional @@ -42,7 +50,7 @@ InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); try { //鑾峰彇鍏ュ簱瀹屾垚浠诲姟 - List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 100)); + List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, TaskStsType.UPDATED_IN.id)); if (list.isEmpty()) { return; } @@ -53,6 +61,7 @@ //淇濆瓨浠诲姟鍘嗗彶妗� TaskLog taskLog = new TaskLog(); taskLog.sync(task); + taskLog.setId(null); if (!taskLogService.save(taskLog)) { throw new CoolException("淇濆瓨浠诲姟鍘嗗彶妗eけ璐�"); } @@ -64,12 +73,14 @@ //淇濆瓨浠诲姟鏄庣粏鍘嗗彶妗� List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); - if(taskDetls.isEmpty()) { + if (taskDetls.isEmpty()) { throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�"); } for (TaskDetl taskDetl : taskDetls) { TaskDetlLog taskDetlLog = new TaskDetlLog(); taskDetlLog.sync(taskDetl); + taskDetlLog.setId(null); + taskDetlLog.setTaskId(taskLog.getId()); if (!taskDetlLogService.save(taskDetlLog)) { throw new CoolException("淇濆瓨浠诲姟鏄庣粏鍘嗗彶妗eけ璐�"); } @@ -80,26 +91,32 @@ //鏄庣粏鎵╁睍瀛楁鏁版嵁淇濆瓨鑷冲巻鍙叉。 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){ + if (!removeField) { throw new CoolException("鍒犻櫎鏄庣粏鎵╁睍澶辫触"); } } //鍒犻櫎鏄庣粏 boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); - if(!removeDetl){ + if (!removeDetl) { throw new CoolException("鏄庣粏鍒犻櫎澶辫触"); } } //鏇存柊璁㈠崟淇℃伅 for (TaskDetl taskDetl : taskDetls) { + if (taskDetl.getDetlId() == null) { + continue; + } + OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); if (orderDetl == null) { throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�"); @@ -117,7 +134,7 @@ if (checkOrderComplete) { //璁㈠崟宸茬粡瀹屾垚 Order order = orderService.getById(orderDetl.getOrderId()); - if(order == null) { + if (order == null) { throw new CoolException("璁㈠崟涓嶅瓨鍦�"); } @@ -135,7 +152,7 @@ } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - }finally { + } finally { InterceptorIgnoreHelper.clearIgnoreStrategy(); } } @@ -145,11 +162,140 @@ public void outExecute() { InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); try { + //鑾峰彇鍑哄簱瀹屾垚浠诲姟 + List<Task> list = taskService.list(new LambdaQueryWrapper<Task>() + .eq(Task::getTaskSts, TaskStsType.UPDATED_OUT.id) + .in(Task::getTaskType, 101, 53, 57)); + if (list.isEmpty()) { + return; + } + Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "taskLogDiffDays").eq(Dict::getStatus, 1)); + if(dict == null) { + return; + } + for (Task task : list) { + int diff = DateUtils.diff(task.getCreateTime(), new Date()); + int taskLogDiffDays = Integer.parseInt(dict.getValue()); + if (diff < taskLogDiffDays) { + continue; + } + + Long hostId = task.getHostId(); + + //淇濆瓨浠诲姟鏄庣粏鍘嗗彶妗� + List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); + if (taskDetls.isEmpty()) { + throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�"); + } + + boolean flag = false; + for (TaskDetl taskDetl : taskDetls) { + if (taskDetl.getWaveId() == null) { + continue; + } + + Wave wave = waveService.getById(taskDetl.getWaveId()); + if (wave != null) { + flag = true;//娉㈡鏈畬鎴� + break; + } + } + + if (flag) { + continue; + } + + + //淇濆瓨浠诲姟鍘嗗彶妗� + TaskLog taskLog = new TaskLog(); + taskLog.sync(task); + taskLog.setId(null); + if (!taskLogService.save(taskLog)) { + throw new CoolException("淇濆瓨浠诲姟鍘嗗彶妗eけ璐�"); + } + + //鍒犻櫎浠诲姟鍘嗗彶妗f + if (!taskService.removeById(task.getId())) { + throw new CoolException("鍒犻櫎浠诲姟妗eけ璐�"); + } + + for (TaskDetl taskDetl : taskDetls) { + TaskDetlLog taskDetlLog = new TaskDetlLog(); + taskDetlLog.sync(taskDetl); + taskDetlLog.setId(null); + taskDetlLog.setTaskId(taskLog.getId()); + if (!taskDetlLogService.save(taskDetlLog)) { + throw new CoolException("淇濆瓨浠诲姟鏄庣粏鍘嗗彶妗eけ璐�"); + } + + //淇濆瓨鏄庣粏鎵╁睍瀛楁鍘嗗彶妗� + List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId)); + 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("鍒犻櫎鏄庣粏鎵╁睍澶辫触"); + } + } + + //鍒犻櫎鏄庣粏 + boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); + if (!removeDetl) { + throw new CoolException("鏄庣粏鍒犻櫎澶辫触"); + } + } + + //鏇存柊璁㈠崟淇℃伅 + for (TaskDetl taskDetl : taskDetls) { + if (taskDetl.getDetlId() == null) { + continue; + } + + OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); + if (orderDetl == null) { + throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦�"); + } + + orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());//宸ヤ綔涓暟閲忓噺灏� + orderDetl.setQty(orderDetl.getQty() + taskDetl.getAnfme());//宸插畬鎴愭暟閲忓鍔� + orderDetl.setUpdateTime(new Date()); + if (!orderDetlService.updateById(orderDetl)) { + throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触"); + } + + //妫�娴嬭鍗曟槸鍚﹀畬鎴� + boolean checkOrderComplete = orderService.checkOrderComplete(orderDetl.getOrderId()); + if (checkOrderComplete) { + //璁㈠崟宸茬粡瀹屾垚 + Order order = orderService.getById(orderDetl.getOrderId()); + if (order == null) { + throw new CoolException("璁㈠崟涓嶅瓨鍦�"); + } + + order.setOrderSettle(OrderSettleType.COMPLETE.val()); + order.setUpdateTime(new Date()); + if (!orderService.updateById(order)) { + throw new CoolException("璁㈠崟鏇存柊澶辫触"); + } + } + } + + + } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - }finally { + } finally { InterceptorIgnoreHelper.clearIgnoreStrategy(); } } -- Gitblit v1.9.1