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.core.enums.SlaveType;
|
import com.zy.core.model.Task;
|
import com.zy.core.model.command.CrnCommand;
|
import com.zy.core.model.command.LedCommand;
|
import com.zy.core.model.protocol.StaProtocol;
|
|
import java.util.Date;
|
import java.util.List;
|
|
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;
|
}
|
|
CommandInfo commandInfo = null;
|
WrkMast wrkMast = null;
|
int taskNo = 0;
|
switch (type) {
|
case Crn:
|
CrnCommand command = (CrnCommand) task.getData();
|
taskNo = command.getTaskNo();
|
wrkMast = wrkMastService.selectById(taskNo);
|
|
commandInfo = new CommandInfo();
|
commandInfo.setWrkNo(taskNo);
|
commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
|
commandInfo.setCommandStatus(1);
|
commandInfo.setStartTime(new Date());
|
commandInfo.setDevice("crn");
|
commandInfo.setCommand(JSON.toJSONString(command));
|
commandInfoService.insert(commandInfo);
|
|
command.setCommandInfo(commandInfo);
|
break;
|
case Devp:
|
StaProtocol staProtocol = (StaProtocol) task.getData();
|
taskNo = staProtocol.getWorkNo();
|
wrkMast = wrkMastService.selectById(taskNo);
|
|
commandInfo = new CommandInfo();
|
commandInfo.setWrkNo(taskNo);
|
commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
|
commandInfo.setCommandStatus(1);
|
commandInfo.setStartTime(new Date());
|
commandInfo.setDevice("devp");
|
commandInfo.setCommand(JSON.toJSONString(staProtocol));
|
commandInfoService.insert(commandInfo);
|
|
staProtocol.setCommandInfo(commandInfo);
|
break;
|
case Led:
|
List<LedCommand> data = (List<LedCommand>) task.getData();
|
for (LedCommand ledCommand : data) {
|
taskNo = ledCommand.getWorkNo();
|
wrkMast = wrkMastService.selectById(taskNo);
|
|
commandInfo = new CommandInfo();
|
commandInfo.setWrkNo(ledCommand.getWorkNo());
|
commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
|
commandInfo.setCommandStatus(1);
|
commandInfo.setStartTime(new Date());
|
commandInfo.setDevice("led");
|
commandInfo.setCommand(JSON.toJSONString(ledCommand));
|
commandInfoService.insert(commandInfo);
|
|
ledCommand.setCommandInfo(commandInfo);
|
}
|
break;
|
}
|
|
}
|
|
}
|