#
Junjie
2024-11-28 a19133219811f9286fa71a0fb8c1deb628cf74a3
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("保存任务历史档失败");
                }
@@ -70,6 +79,8 @@
                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("保存任务明细历史档失败");
                    }
@@ -80,6 +91,8 @@
                        //明细扩展字段数据保存至历史档
                        TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
                        taskDetlFieldLog.sync(detlField);
                        taskDetlFieldLog.setId(null);
                        taskDetlFieldLog.setDetlId(taskDetlLog.getId());
                        if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
                            throw new CoolException("明细扩展字段转历史档案失败");
                        }
@@ -100,6 +113,10 @@
                //更新订单信息
                for (TaskDetl taskDetl : taskDetls) {
                    if (taskDetl.getDetlId() == null) {
                        continue;
                    }
                    OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
                    if (orderDetl == null) {
                        throw new CoolException("订单明细不存在");
@@ -145,18 +162,55 @@
    public void outExecute() {
        InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
        try {
            //获取入库完成任务
            List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 200));
            //获取出库完成任务
            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("保存任务历史档失败");
                }
@@ -166,14 +220,11 @@
                    throw new CoolException("删除任务档失败");
                }
                //保存任务明细历史档
                List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId());
                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("保存任务明细历史档失败");
                    }
@@ -184,6 +235,8 @@
                        //明细扩展字段数据保存至历史档
                        TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
                        taskDetlFieldLog.sync(detlField);
                        taskDetlFieldLog.setId(null);
                        taskDetlFieldLog.setDetlId(taskDetlLog.getId());
                        if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
                            throw new CoolException("明细扩展字段转历史档案失败");
                        }
@@ -204,6 +257,10 @@
                //更新订单信息
                for (TaskDetl taskDetl : taskDetls) {
                    if (taskDetl.getDetlId() == null) {
                        continue;
                    }
                    OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
                    if (orderDetl == null) {
                        throw new CoolException("订单明细不存在");