|
|
@ -6,10 +6,7 @@ import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.db.Db; |
|
|
import cn.hutool.db.Db; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import com.qniao.domain.BaseCommand; |
|
|
import com.qniao.domain.BaseCommand; |
|
|
import com.qniao.iot.machine.command.PowerOffMachineCommand; |
|
|
|
|
|
import com.qniao.iot.machine.command.PowerOnMachineCommand; |
|
|
|
|
|
import com.qniao.iot.machine.command.StartMachineWorkingCommand; |
|
|
|
|
|
import com.qniao.iot.machine.command.StopMachineWorkingCommand; |
|
|
|
|
|
|
|
|
import com.qniao.iot.machine.command.*; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEvent; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEvent; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEventKafkaDeserializationSchema; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEventKafkaDeserializationSchema; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEventRabbitMqSerializationSchema; |
|
|
import com.qniao.iot.machine.event.MachineIotDataReceivedEventRabbitMqSerializationSchema; |
|
|
@ -313,7 +310,25 @@ public class IotMachineEventGeneratorJob { |
|
|
@Override |
|
|
@Override |
|
|
public String computeRoutingKey(BaseCommand command) { |
|
|
public String computeRoutingKey(BaseCommand command) { |
|
|
|
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_MACHINE_COMMAND_ROUTING_KEY); |
|
|
|
|
|
|
|
|
if (command instanceof PowerOnMachineCommand) { |
|
|
|
|
|
// 机器通电 |
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_POWER_ON_MACHINE_COMMAND_ROUTING_KEY); |
|
|
|
|
|
} |
|
|
|
|
|
if (command instanceof PowerOffMachineCommand) { |
|
|
|
|
|
// 机器断电 |
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_POWER_OFF_MACHINE_COMMAND_ROUTING_KEY); |
|
|
|
|
|
} |
|
|
|
|
|
if (command instanceof StopMachineWorkingCommand) { |
|
|
|
|
|
// 机器待机 |
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_STOP_MACHINE_WORKING_COMMAND_ROUTING_KEY); |
|
|
|
|
|
} |
|
|
|
|
|
if (command instanceof StartMachineWorkingCommand) { |
|
|
|
|
|
// 机器工作 |
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_START_MACHINE_WORKING_COMMAND_ROUTING_KEY); |
|
|
|
|
|
}else { |
|
|
|
|
|
// 机器命令 |
|
|
|
|
|
return ApolloConfig.getStr(ConfigConstant.SINK_RABBITMQ_MACHINE_COMMAND_ROUTING_KEY); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@ -482,58 +497,65 @@ public class IotMachineEventGeneratorJob { |
|
|
Integer lastWorkingStat = lastDataReceivedEvent.getMachineWorkingStat(); |
|
|
Integer lastWorkingStat = lastDataReceivedEvent.getMachineWorkingStat(); |
|
|
Integer workingStat = event.getMachineWorkingStat(); |
|
|
Integer workingStat = event.getMachineWorkingStat(); |
|
|
Integer pwrStat = event.getMachinePwrStat(); |
|
|
Integer pwrStat = event.getMachinePwrStat(); |
|
|
|
|
|
MachineOutputCommand machineOutputCommand = new MachineOutputCommand(); |
|
|
|
|
|
machineOutputCommand.setId(machineId); |
|
|
|
|
|
machineOutputCommand.setMac(machineIotMac); |
|
|
|
|
|
machineOutputCommand.setMachinePwrStat(pwrStat); |
|
|
|
|
|
machineOutputCommand.setMachineWorkingStat(workingStat); |
|
|
|
|
|
machineOutputCommand.setDataSource(dataSource); |
|
|
|
|
|
machineOutputCommand.setCurrCount(currCount); |
|
|
|
|
|
machineOutputCommand.setCurrDuration(currDuration); |
|
|
|
|
|
machineOutputCommand.setCurrTotalOutput(accJobCount); |
|
|
|
|
|
machineOutputCommand.setTimestamp(reportTime); |
|
|
|
|
|
|
|
|
if (lastWorkingStat == 0 && (workingStat == 1 || workingStat == 2)) { |
|
|
if (lastWorkingStat == 0 && (workingStat == 1 || workingStat == 2)) { |
|
|
// 设备开机 |
|
|
// 设备开机 |
|
|
PowerOnMachineCommand command = new PowerOnMachineCommand(); |
|
|
PowerOnMachineCommand command = new PowerOnMachineCommand(); |
|
|
command.setId(machineId); |
|
|
command.setId(machineId); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMachinePwrStat(pwrStat); |
|
|
|
|
|
command.setMachineWorkingStat(workingStat); |
|
|
|
|
|
command.setDataSource(dataSource); |
|
|
command.setDataSource(dataSource); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setTimestamp(reportTime); |
|
|
command.setTimestamp(reportTime); |
|
|
out.collect(command); |
|
|
out.collect(command); |
|
|
|
|
|
out.collect(machineOutputCommand); |
|
|
} else if ((lastWorkingStat == 1 || lastWorkingStat == 2) && workingStat == 0) { |
|
|
} else if ((lastWorkingStat == 1 || lastWorkingStat == 2) && workingStat == 0) { |
|
|
// 设备关机 |
|
|
// 设备关机 |
|
|
PowerOffMachineCommand command = new PowerOffMachineCommand(); |
|
|
PowerOffMachineCommand command = new PowerOffMachineCommand(); |
|
|
command.setId(machineId); |
|
|
command.setId(machineId); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMachinePwrStat(pwrStat); |
|
|
|
|
|
command.setMachineWorkingStat(workingStat); |
|
|
|
|
|
command.setDataSource(dataSource); |
|
|
command.setDataSource(dataSource); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setTimestamp(reportTime); |
|
|
command.setTimestamp(reportTime); |
|
|
out.collect(command); |
|
|
out.collect(command); |
|
|
|
|
|
out.collect(machineOutputCommand); |
|
|
} else if (lastWorkingStat == 1 && workingStat == 2) { |
|
|
} else if (lastWorkingStat == 1 && workingStat == 2) { |
|
|
// 设备开始待机 |
|
|
// 设备开始待机 |
|
|
StopMachineWorkingCommand command = new StopMachineWorkingCommand(); |
|
|
StopMachineWorkingCommand command = new StopMachineWorkingCommand(); |
|
|
command.setId(machineId); |
|
|
command.setId(machineId); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMachinePwrStat(pwrStat); |
|
|
|
|
|
command.setMachineWorkingStat(workingStat); |
|
|
|
|
|
command.setDataSource(dataSource); |
|
|
command.setDataSource(dataSource); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setTimestamp(reportTime); |
|
|
command.setTimestamp(reportTime); |
|
|
out.collect(command); |
|
|
out.collect(command); |
|
|
|
|
|
out.collect(machineOutputCommand); |
|
|
} else if ((lastWorkingStat == 2 || lastWorkingStat == 1) && workingStat == 1) { |
|
|
} else if ((lastWorkingStat == 2 || lastWorkingStat == 1) && workingStat == 1) { |
|
|
// 设备开始工作 |
|
|
// 设备开始工作 |
|
|
StartMachineWorkingCommand command = new StartMachineWorkingCommand(); |
|
|
StartMachineWorkingCommand command = new StartMachineWorkingCommand(); |
|
|
command.setId(machineId); |
|
|
command.setId(machineId); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMac(machineIotMac); |
|
|
command.setMachinePwrStat(pwrStat); |
|
|
|
|
|
command.setMachineWorkingStat(workingStat); |
|
|
|
|
|
command.setDataSource(dataSource); |
|
|
command.setDataSource(dataSource); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrCount(currCount); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrDuration(currDuration); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setCurrTotalOutput(accJobCount); |
|
|
command.setTimestamp(reportTime); |
|
|
command.setTimestamp(reportTime); |
|
|
out.collect(command); |
|
|
out.collect(command); |
|
|
|
|
|
out.collect(machineOutputCommand); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |