#
Junjie
2024-06-18 95d473bc8c09ef41e1455f93dec49c5ee6ac548f
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/TaskTimer.java
@@ -1,18 +1,19 @@
package com.zy.asrs.wcs.core.timer;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.wcs.core.entity.Loc;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.entity.*;
import com.zy.asrs.wcs.core.model.enums.LocStsType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.LocService;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
@@ -22,9 +23,16 @@
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskLogService taskLogService;
    @Autowired
    private MotionService motionService;
    @Autowired
    private MotionLogService motionLogService;
    @Autowired
    private LocService locService;
    @Scheduled(cron = "0/1 * * * * ? ")
    @Transactional
    public synchronized void clearCompletedTask() {
        ArrayList<Long> taskSts = new ArrayList<>();
        taskSts.add(TaskStsType.COMPLETE_INBOUND.sts);
@@ -39,12 +47,18 @@
        for (Task task : tasks) {
            //记录库存信息
            updateRecordLoc(task);
            //任务转历史档
            saveTaskLog(task);
        }
    }
    //更新库存信息
    private void updateRecordLoc(Task task) {
    @Transactional
    public void updateRecordLoc(Task task) {
        if (task.getRecordLoc() == null) {
            return;
        }
        if (task.getRecordLoc().equals("Y")) {//记录库存信息
            //源库位 => 空库
            //目标库位 => 在库
@@ -60,6 +74,7 @@
                locService.updateById(destLoc);
            }
        } else if (task.getRecordLoc().equals("record-dest")) {//只记录目标库位信息
            //目标库位 => 在库
            Loc destLoc = locService.selectByLocNo(task.getDestLoc());
            if (destLoc != null) {
                destLoc.setLocSts(LocStsType.F.val());
@@ -68,4 +83,28 @@
        }
    }
    //更新历史档
    @Transactional
    public void saveTaskLog(Task task) {
        //创建历史档
        TaskLog taskLog = new TaskLog();
        taskLog.sync(task);
        taskLog.setUpdateTime(new Date());
        taskLogService.save(taskLog);
        List<Motion> motions = motionService.list(new LambdaQueryWrapper<Motion>().eq(Motion::getTaskNo, task.getTaskNo()).eq(Motion::getHostId, task.getHostId()));
        for (Motion motion : motions) {
            //创建动作历史档
            MotionLog motionLog = new MotionLog();
            motionLog.sync(motion);
            motionLog.setUpdateTime(new Date());
            motionLogService.save(motionLog);
        }
        //删除源任务
        taskService.removeById(task.getId());
        //删除动作
        motionService.remove(new LambdaQueryWrapper<Motion>().eq(Motion::getTaskNo, task.getTaskNo()).eq(Motion::getHostId, task.getHostId()));
    }
}