Browse Source

新增机器指令命令

master
1049970895@qniao.cn 3 years ago
parent
commit
8a48968c74
6 changed files with 94 additions and 53 deletions
  1. 59
      iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/MachineOutputCommand.java
  2. 10
      iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOffMachineCommand.java
  3. 10
      iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/PowerOnMachineCommand.java
  4. 10
      iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StartMachineWorkingCommand.java
  5. 10
      iot-machine-data-command/src/main/java/com/qniao/iot/machine/command/StopMachineWorkingCommand.java
  6. 48
      iot-machine-state-event-generator-job/src/main/java/com/qniao/iot/machine/event/generator/job/IotMachineEventGeneratorJob.java

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

10
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树根
*/

10
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树根
*/

10
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树根
*/

10
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树根
*/

48
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);
}
}
}
Loading…
Cancel
Save