自动化立体仓库 - WCS系统
zhangc
2025-03-11 d5449236ef0b3adafb3e4cc872f50479efa0ce7b
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.zy.asrs.utils;
 
import com.alibaba.fastjson.JSON;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.CommandStatusType;
import com.zy.core.enums.CommandType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.command.CommandPackage;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.protocol.StaProtocol;
 
import java.util.Date;
 
public class CommandUtils {
 
    public static boolean offer(SlaveType type, Integer id, Task task) {
        return offer(type, id, task, true);
    }
 
    public static boolean offer(SlaveType type, Integer id, Task task, Boolean auto) {
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        if (commandInfoService == null) {
            return false;
        }
        TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
        if (taskWrkService == null) {
            return false;
        }
 
        CommandInfo commandInfo = null;
        TaskWrk taskWrk = null;
        int wrkNo = 0;//工作号
        String taskNo = null;//任务号
 
        if (type == SlaveType.Crn) {
            CommandPackage<CrnCommand> commandPackage = new CommandPackage<>();
            CrnCommand command = (CrnCommand) task.getData();
            wrkNo = command.getTaskNo();
            if (auto && wrkNo != 0) {
                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
                taskNo = taskWrk.getTaskNo();
            }
 
            commandInfo = new CommandInfo();
            commandInfo.setWrkNo(wrkNo);
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(CommandStatusType.CREATE.id);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice(SlaveType.Crn.toString());
            commandInfo.setCommandType(auto ? CommandType.AUTO.id : CommandType.MANUAL.id);
 
            commandInfoService.insert(commandInfo);//插入指令
 
            command.setCommandId(commandInfo.getId());
            commandPackage.setWrkNo(wrkNo);
            commandPackage.setDevice("堆垛机");
            commandPackage.setCommand(command);//保存命令报文
            commandInfo.setCommand(JSON.toJSONString(commandPackage));
            commandInfoService.updateById(commandInfo);
 
            if (!auto) {
                //将指令进行投递
                if (!MessageQueue.offer(type, id, task)) {
                    return false;
                }
            }
            return true;
        } else if (type == SlaveType.Devp) {
            CommandPackage<StaProtocol> commandPackage = new CommandPackage<>();
            StaProtocol staProtocol = (StaProtocol) task.getData();
            wrkNo = staProtocol.getWorkNo();
            if (auto && wrkNo != 0) {
                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
                taskNo = taskWrk.getTaskNo();
            }
 
            commandInfo = new CommandInfo();
            commandInfo.setWrkNo(wrkNo);
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(CommandStatusType.CREATE.id);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice(SlaveType.Devp.toString());
            commandInfo.setCommandType(auto ? CommandType.AUTO.id : CommandType.MANUAL.id);
 
            commandInfoService.insert(commandInfo);//插入指令
 
            staProtocol.setCommandId(commandInfo.getId());
            commandPackage.setCommand(staProtocol);
            commandPackage.setWrkNo(wrkNo);
            commandPackage.setDevice("输送线");
            commandInfo.setCommand(JSON.toJSONString(commandPackage));//保存命令报文
            commandInfoService.updateById(commandInfo);
 
            if (!auto) {
                //将指令进行投递
                if (!MessageQueue.offer(type, id, task)) {
                    return false;
                }
            }
            return true;
        }
 
        return false;
    }
 
}