| | |
| | | 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.LedCommand; |
| | | import com.zy.core.model.command.RedisCommand; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public class CommandUtils { |
| | | |
| | |
| | | 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; |
| | | switch (type) { |
| | | case Crn: |
| | | |
| | | 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) { |
| | |
| | | commandInfo.setDevice("crn"); |
| | | commandInfo.setCommand(JSON.toJSONString(command)); |
| | | commandInfoService.insert(commandInfo); |
| | | |
| | | command.setCommandInfo(commandInfo); |
| | | break; |
| | | case Devp: |
| | | |
| | | 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) { |
| | |
| | | commandInfoService.insert(commandInfo); |
| | | |
| | | staProtocol.setCommandInfo(commandInfo); |
| | | break; |
| | | case Led: |
| | | List<LedCommand> data = (List<LedCommand>) task.getData(); |
| | | for (LedCommand ledCommand : data) { |
| | | wrkNo = ledCommand.getWorkNo(); |
| | | if (wrkNo != 0) { |
| | | wrkMast = wrkMastService.selectById(wrkNo); |
| | | taskNo = wrkMast.getTaskNo(); |
| | | } |
| | | |
| | | commandInfo = new CommandInfo(); |
| | | commandInfo.setWrkNo(ledCommand.getWorkNo()); |
| | | commandInfo.setTaskNo(taskNo); |
| | | commandInfo.setCommandStatus(1); |
| | | commandInfo.setStartTime(new Date()); |
| | | commandInfo.setDevice("led"); |
| | | commandInfo.setCommand(JSON.toJSONString(ledCommand)); |
| | | commandInfoService.insert(commandInfo); |
| | | |
| | | ledCommand.setCommandInfo(commandInfo); |
| | | } |
| | | break; |
| | | commands.add(staProtocol); |
| | | redisCommand.setWrkNo(wrkNo); |
| | | redisCommand.setCommands(commands); |
| | | } |
| | | |
| | | } |