Junjie
2023-08-09 8b1ec79e5e5a16e44f37643b6225e5d405479851
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
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.WrkMast;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.RedisCommand;
import com.zy.core.model.protocol.StaProtocol;
 
import java.util.ArrayList;
import java.util.Date;
 
public class CommandUtils {
 
    public static void offer(SlaveType type, Integer id, Task task) {
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        if (commandInfoService == null) {
            return;
        }
        WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
        if (wrkMastService == null) {
            return;
        }
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        if (redisUtil == null) {
            return;
        }
 
        CommandInfo commandInfo = null;
        WrkMast wrkMast = null;
        int wrkNo = 0;
        String taskNo = null;
 
        if (type == SlaveType.Crn) {
            RedisCommand<CrnCommand> redisCommand = new RedisCommand();
            ArrayList<CrnCommand> commands = new ArrayList<>();
 
            CrnCommand command = (CrnCommand) task.getData();
            wrkNo = command.getTaskNo();
            if (wrkNo != 0) {
                wrkMast = wrkMastService.selectById(wrkNo);
                taskNo = wrkMast.getTaskNo();
            }
 
            commandInfo = new CommandInfo();
            commandInfo.setWrkNo(wrkNo);
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(1);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice("crn");
            commandInfo.setCommand(JSON.toJSONString(command));
            commandInfoService.insert(commandInfo);
            command.setCommandInfo(commandInfo);
 
            commands.add(command);
            redisCommand.setWrkNo(wrkNo);
            redisCommand.setCommands(commands);
        } else if (type == SlaveType.Devp) {
            RedisCommand<StaProtocol> redisCommand = new RedisCommand();
            ArrayList<StaProtocol> commands = new ArrayList<>();
 
            StaProtocol staProtocol = (StaProtocol) task.getData();
            wrkNo = staProtocol.getWorkNo();
            if (wrkNo != 0) {
                wrkMast = wrkMastService.selectById(wrkNo);
                taskNo = wrkMast.getTaskNo();
            }
 
            commandInfo = new CommandInfo();
            commandInfo.setWrkNo(wrkNo);
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(1);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice("devp");
            commandInfo.setCommand(JSON.toJSONString(staProtocol));
            commandInfoService.insert(commandInfo);
 
            staProtocol.setCommandInfo(commandInfo);
 
            commands.add(staProtocol);
            redisCommand.setWrkNo(wrkNo);
            redisCommand.setCommands(commands);
        }
 
    }
 
}