#
Junjie
2025-05-10 2a7fd275313003968fc186ee4617aec4eca90266
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.zy.asrs.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.exception.CoolException;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.TaskWrkLog;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.TaskWrkLogService;
import com.zy.asrs.service.TaskWrkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
@Slf4j
@Component
public class AgvTaskLogScheduler {
 
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private TaskWrkLogService taskWrkLogService;
    @Autowired
    private LocMastService locMastService;
 
    /**
     * AGV任务转历史
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void execute() {
        List<TaskWrk> taskWrkList = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("status", TaskStatusType.COMPLETE.id));
        for (TaskWrk taskWrk : taskWrkList) {
            Date now = new Date();
            String originPoint = taskWrk.getStartPoint();
            String targetPoint = taskWrk.getTargetPoint();
            LocMast startLocMast = locMastService.selectByLocNo(originPoint);
            if(startLocMast == null){
                throw new CoolException("取货点库位不存在");
            }
 
            if (!startLocMast.getLocSts().equals("R")) {
                throw new CoolException("取货点不处于出库预约");
            }
 
            LocMast targetLocMast = locMastService.selectByLocNo(targetPoint);
            if(targetLocMast == null){
                throw new CoolException("放货点库位不存在");
            }
 
            if (!targetLocMast.getLocSts().equals("S")) {
                throw new CoolException("放货点不处于入库预约");
            }
 
            startLocMast.setLocSts("O");
            startLocMast.setModiTime(now);
            locMastService.updateById(startLocMast);
 
            targetLocMast.setLocSts("F");
            targetLocMast.setModiTime(now);
            locMastService.updateById(targetLocMast);
 
            TaskWrkLog taskWrkLog = new TaskWrkLog(taskWrk);
            if (!taskWrkLogService.insert(taskWrkLog)) {
                throw new CoolException("转历史档失败" + taskWrkLog);
            }
            if (!taskWrkService.deleteById(taskWrk)) {
                throw new CoolException("任务档删除失败" + taskWrkLog);
            }
        }
    }
}