4 changed files with 162 additions and 1 deletions
Unified View
Diff Options
-
27root-cloud-statistics/src/main/java/com/qniao/iot/rc/RootCloudIotDataFormatterJob.java
-
17root-cloud-statistics/src/main/java/com/qniao/iot/rc/constant/DataSource.java
-
98root-cloud-statistics/src/main/java/com/qniao/iot/rc/event/MachineIotDataReceivedEvent.java
-
21root-cloud-statistics/src/main/java/com/qniao/iot/rc/event/MachineIotDataReceivedEventSerializationSchema.java
@ -0,0 +1,17 @@ |
|||||
|
package com.qniao.iot.rc.constant; |
||||
|
|
||||
|
/** |
||||
|
* @author Lzk |
||||
|
* @date 2022/7/2 |
||||
|
**/ |
||||
|
|
||||
|
public interface DataSource { |
||||
|
/** |
||||
|
* 树根云 |
||||
|
*/ |
||||
|
Integer ROOT_CLOUD = 1; |
||||
|
/** |
||||
|
* 机智云 |
||||
|
*/ |
||||
|
Integer TACT_CLOUD = 0; |
||||
|
} |
||||
@ -0,0 +1,98 @@ |
|||||
|
package com.qniao.iot.rc.event; |
||||
|
|
||||
|
import com.qniao.iot.rc.RootCloudIotDataReceiptedEvent; |
||||
|
import com.qniao.iot.rc.constant.DataSource; |
||||
|
import lombok.Data; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author Lzk |
||||
|
* @date 2022/7/2 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class MachineIotDataReceivedEvent implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
/** |
||||
|
* 唯一标识 |
||||
|
*/ |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
* 数据来源 |
||||
|
*/ |
||||
|
private Integer dataSource; |
||||
|
|
||||
|
/** |
||||
|
* 设备物联地址(云盒物理标识) |
||||
|
*/ |
||||
|
private Long machineIotMac; |
||||
|
|
||||
|
/** |
||||
|
* 机器电源状态 |
||||
|
*/ |
||||
|
private Integer machinePwrStat; |
||||
|
|
||||
|
/** |
||||
|
* 机器工作状态 |
||||
|
*/ |
||||
|
private Integer machineWorkingStat; |
||||
|
|
||||
|
/** |
||||
|
* 累加作业总数 |
||||
|
*/ |
||||
|
private Long accJobCount; |
||||
|
|
||||
|
/** |
||||
|
* 当前作业计数 |
||||
|
*/ |
||||
|
private Long currJobCount; |
||||
|
|
||||
|
/** |
||||
|
* 当前作业时长 |
||||
|
*/ |
||||
|
private Long currJobDuration; |
||||
|
|
||||
|
/** |
||||
|
* 当前待机时长 |
||||
|
*/ |
||||
|
private Long currWaitingDuration; |
||||
|
|
||||
|
/** |
||||
|
* 当前停机时长 |
||||
|
*/ |
||||
|
private Long currStoppingDuration; |
||||
|
|
||||
|
/** |
||||
|
* 计数开关状态 |
||||
|
*/ |
||||
|
private Integer igStat; |
||||
|
|
||||
|
/** |
||||
|
* 数据采样时间 |
||||
|
*/ |
||||
|
private Long reportTime; |
||||
|
|
||||
|
public static MachineIotDataReceivedEvent transform(RootCloudIotDataReceiptedEvent event) { |
||||
|
|
||||
|
MachineIotDataReceivedEvent machineIotDataReceivedEvent = new MachineIotDataReceivedEvent(); |
||||
|
if (Objects.nonNull(event)) { |
||||
|
machineIotDataReceivedEvent.setId((long) (event.get__assetId__() + System.currentTimeMillis()).hashCode()); |
||||
|
machineIotDataReceivedEvent.setMachineIotMac(Long.valueOf(event.get__assetId__())); |
||||
|
machineIotDataReceivedEvent.setDataSource(DataSource.ROOT_CLOUD); |
||||
|
machineIotDataReceivedEvent.setMachinePwrStat(event.getPWR_sta()); |
||||
|
machineIotDataReceivedEvent.setMachineWorkingStat(event.getWorking_sta()); |
||||
|
machineIotDataReceivedEvent.setIgStat(event.getIG_sta()); |
||||
|
machineIotDataReceivedEvent.setAccJobCount(event.getACC_count_total()); |
||||
|
machineIotDataReceivedEvent.setCurrJobCount(event.getACC_count()); |
||||
|
machineIotDataReceivedEvent.setCurrJobDuration(Objects.isNull(event.getRunning_duration()) ? null : event.getRunning_duration().longValue()); |
||||
|
machineIotDataReceivedEvent.setCurrStoppingDuration(StringUtils.isBlank(event.getStoping_duration()) ? null : Long.valueOf(event.getStoping_duration())); |
||||
|
machineIotDataReceivedEvent.setCurrWaitingDuration(Objects.isNull(event.getWaiting_duration()) ? null : event.getWaiting_duration().longValue()); |
||||
|
machineIotDataReceivedEvent.setReportTime(System.currentTimeMillis()); |
||||
|
} |
||||
|
return machineIotDataReceivedEvent; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package com.qniao.iot.rc.event; |
||||
|
|
||||
|
import org.apache.flink.api.common.serialization.SerializationSchema; |
||||
|
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException; |
||||
|
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
|
||||
|
/** |
||||
|
* @author Lzk |
||||
|
*/ |
||||
|
public class MachineIotDataReceivedEventSerializationSchema implements SerializationSchema<MachineIotDataReceivedEvent> { |
||||
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
||||
|
|
||||
|
@Override |
||||
|
public byte[] serialize(MachineIotDataReceivedEvent event) { |
||||
|
try { |
||||
|
return OBJECT_MAPPER.writeValueAsBytes(event); |
||||
|
} catch (JsonProcessingException e) { |
||||
|
throw new IllegalArgumentException("Could not serialize record: " + event, e); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save