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);
|
}
|
|
}
|
|
}
|