From 8a48968c7487657795cf180e0ba5b72273fc44ee Mon Sep 17 00:00:00 2001 From: "1049970895@qniao.cn" <1049970895> Date: Mon, 5 Sep 2022 15:32:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=BA=E5=99=A8=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../machine/command/MachineOutputCommand.java | 59 +++++++++++++++++++ .../command/PowerOffMachineCommand.java | 10 ---- .../command/PowerOnMachineCommand.java | 10 ---- .../command/StartMachineWorkingCommand.java | 10 ---- .../command/StopMachineWorkingCommand.java | 10 ---- .../job/IotMachineEventGeneratorJob.java | 48 +++++++++++---- 6 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/MachineOutputCommand.java diff --git a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/MachineOutputCommand.java b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/MachineOutputCommand.java new file mode 100644 index 0000000..22e74d5 --- /dev/null +++ b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/MachineOutputCommand.java @@ -0,0 +1,59 @@ +package com.qniao.iot.machine.command; + +import com.qniao.domain.BaseCommand; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 机器输出命令 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MachineOutputCommand extends BaseCommand { + + private static final long serialVersionUID = 1L; + + /** + * 机器标识(MachineId) + */ + private Long id; + + /** + * 云盒mac + */ + private Long mac; + + /** + * 机器电源状态(0断电 1供电) + */ + private Integer machinePwrStat; + + /** + * 机器工作状态(0未工作 1工作中 2待机中) + */ + private Integer machineWorkingStat; + + /** + * 数据来源(0机智云 1树根) + */ + private Integer dataSource; + + /** + * 当前产能(距离上次的工作生产数量) + */ + private Long currCount; + + /** + * 当前时长(距离上次的作业时长,单位秒) + */ + private Long currDuration; + + /** + * 当前总产量 + */ + private Long currTotalOutput; +} diff --git a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOffMachineCommand.java b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOffMachineCommand.java index c55746d..8b3a086 100644 --- a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOffMachineCommand.java +++ b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOffMachineCommand.java @@ -27,16 +27,6 @@ public class PowerOffMachineCommand extends BaseCommand { */ private Long mac; - /** - * 机器电源状态(0断电 1供电) - */ - private Integer machinePwrStat; - - /** - * 机器工作状态(0未工作 1工作中 2待机中) - */ - private Integer machineWorkingStat; - /** * 数据来源(0机智云 1树根) */ diff --git a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOnMachineCommand.java b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOnMachineCommand.java index 5c6305c..35db388 100644 --- a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOnMachineCommand.java +++ b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOnMachineCommand.java @@ -27,16 +27,6 @@ public class PowerOnMachineCommand extends BaseCommand { */ private Long mac; - /** - * 机器电源状态(0断电 1供电) - */ - private Integer machinePwrStat; - - /** - * 机器工作状态(0未工作 1工作中 2待机中) - */ - private Integer machineWorkingStat; - /** * 数据来源(0机智云 1树根) */ diff --git a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StartMachineWorkingCommand.java b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StartMachineWorkingCommand.java index 2d9fd45..a5d13ae 100644 --- a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StartMachineWorkingCommand.java +++ b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StartMachineWorkingCommand.java @@ -27,16 +27,6 @@ public class StartMachineWorkingCommand extends BaseCommand { */ private Long mac; - /** - * 机器电源状态(0断电 1供电) - */ - private Integer machinePwrStat; - - /** - * 机器工作状态(0未工作 1工作中 2待机中) - */ - private Integer machineWorkingStat; - /** * 数据来源(0机智云 1树根) */ diff --git a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StopMachineWorkingCommand.java b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StopMachineWorkingCommand.java index c52c863..7c25823 100644 --- a/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StopMachineWorkingCommand.java +++ b/iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StopMachineWorkingCommand.java @@ -27,16 +27,6 @@ public class StopMachineWorkingCommand extends BaseCommand { */ private Long mac; - /** - * 机器电源状态(0断电 1供电) - */ - private Integer machinePwrStat; - - /** - * 机器工作状态(0未工作 1工作中 2待机中) - */ - private Integer machineWorkingStat; - /** * 数据来源(0机智云 1树根) */ diff --git a/iot-machine-state-event-generator-job/src/main/java/com/qniao/iot/machine/event/generator/job/IotMachineEventGeneratorJob.java b/iot-machine-state-event-generator-job/src/main/java/com/qniao/iot/machine/event/generator/job/IotMachineEventGeneratorJob.java index 57ff5a7..66e781a 100644 --- a/iot-machine-state-event-generator-job/src/main/java/com/qniao/iot/machine/event/generator/job/IotMachineEventGeneratorJob.java +++ b/iot-machine-state-event-generator-job/src/main/java/com/qniao/iot/machine/event/generator/job/IotMachineEventGeneratorJob.java @@ -6,10 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.db.Db; import cn.hutool.json.JSONUtil; 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.MachineIotDataReceivedEventKafkaDeserializationSchema; import com.qniao.iot.machine.event.MachineIotDataReceivedEventRabbitMqSerializationSchema; @@ -313,7 +310,25 @@ public class IotMachineEventGeneratorJob { @Override 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 @@ -482,58 +497,65 @@ public class IotMachineEventGeneratorJob { Integer lastWorkingStat = lastDataReceivedEvent.getMachineWorkingStat(); Integer workingStat = event.getMachineWorkingStat(); 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)) { // 设备开机 PowerOnMachineCommand command = new PowerOnMachineCommand(); command.setId(machineId); command.setMac(machineIotMac); - command.setMachinePwrStat(pwrStat); - command.setMachineWorkingStat(workingStat); command.setDataSource(dataSource); command.setCurrCount(currCount); command.setCurrDuration(currDuration); command.setCurrTotalOutput(accJobCount); command.setTimestamp(reportTime); out.collect(command); + out.collect(machineOutputCommand); } else if ((lastWorkingStat == 1 || lastWorkingStat == 2) && workingStat == 0) { // 设备关机 PowerOffMachineCommand command = new PowerOffMachineCommand(); command.setId(machineId); command.setMac(machineIotMac); - command.setMachinePwrStat(pwrStat); - command.setMachineWorkingStat(workingStat); command.setDataSource(dataSource); command.setCurrCount(currCount); command.setCurrDuration(currDuration); command.setCurrTotalOutput(accJobCount); command.setTimestamp(reportTime); out.collect(command); + out.collect(machineOutputCommand); } else if (lastWorkingStat == 1 && workingStat == 2) { // 设备开始待机 StopMachineWorkingCommand command = new StopMachineWorkingCommand(); command.setId(machineId); command.setMac(machineIotMac); - command.setMachinePwrStat(pwrStat); - command.setMachineWorkingStat(workingStat); command.setDataSource(dataSource); command.setCurrCount(currCount); command.setCurrDuration(currDuration); command.setCurrTotalOutput(accJobCount); command.setTimestamp(reportTime); out.collect(command); + out.collect(machineOutputCommand); } else if ((lastWorkingStat == 2 || lastWorkingStat == 1) && workingStat == 1) { // 设备开始工作 StartMachineWorkingCommand command = new StartMachineWorkingCommand(); command.setId(machineId); command.setMac(machineIotMac); - command.setMachinePwrStat(pwrStat); - command.setMachineWorkingStat(workingStat); command.setDataSource(dataSource); command.setCurrCount(currCount); command.setCurrDuration(currDuration); command.setCurrTotalOutput(accJobCount); command.setTimestamp(reportTime); out.collect(command); + out.collect(machineOutputCommand); } } }