9 changed files with 367 additions and 152 deletions
Split View
Diff Options
-
2root-cloud-mocker/src/main/java/com/qniao/iot/rc/RootCloudIotDataEventSourceMocker.java
-
45root-cloud-statistics/pom.xml
-
38root-cloud-statistics/src/main/java/com/qniao/iot/rc/DeviceState.java
-
266root-cloud-statistics/src/main/java/com/qniao/iot/rc/RootCloudIotDataFormatterJob.java
-
23root-cloud-statistics/src/main/java/com/qniao/iot/rc/command/BaseCommandSerializationSchema.java
-
17root-cloud-statistics/src/main/java/com/qniao/iot/rc/constant/DataSource.java
-
102root-cloud-statistics/src/main/java/com/qniao/iot/rc/event/MachineIotDataReceivedEvent.java
-
1root-cloud-statistics/src/main/java/com/qniao/iot/rc/event/MachineIotDataReceivedEventSerializationSchema.java
-
25root-cloud-statistics/target/classes/log4j2.properties
@ -0,0 +1,38 @@ |
|||
package com.qniao.iot.rc; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class DeviceState { |
|||
|
|||
private Long id; |
|||
|
|||
/** |
|||
* 设备物联地址(云盒物理标识) |
|||
*/ |
|||
private Long machineIotMac; |
|||
|
|||
/** |
|||
* 状态: 0:关机 1:生产中 2:待机 |
|||
*/ |
|||
private Integer status; |
|||
|
|||
/** |
|||
* 发生时间 |
|||
*/ |
|||
private Long updateTime; |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "设备状态:{" + |
|||
"id='" + id + '\'' + |
|||
", status='" + status + |
|||
", updateTime='" + updateTime + |
|||
'\'' + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
package com.qniao.iot.rc.command; |
|||
|
|||
import com.qniao.domain.BaseCommand; |
|||
import com.qniao.iot.machine.command.PowerOffMachineCommand; |
|||
import com.qniao.iot.machine.event.MachineIotDataReceivedEvent; |
|||
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; |
|||
|
|||
|
|||
public class BaseCommandSerializationSchema implements SerializationSchema<BaseCommand> { |
|||
|
|||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|||
|
|||
@Override |
|||
public byte[] serialize(BaseCommand command) { |
|||
try { |
|||
return OBJECT_MAPPER.writeValueAsBytes(command); |
|||
} catch (JsonProcessingException e) { |
|||
throw new IllegalArgumentException("Could not serialize record: " + command, e); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
package com.qniao.iot.rc.constant; |
|||
|
|||
/** |
|||
* @author Lzk |
|||
* @date 2022/7/2 |
|||
**/ |
|||
|
|||
public interface DataSource { |
|||
/** |
|||
* 树根云 |
|||
*/ |
|||
Integer ROOT_CLOUD = 1; |
|||
/** |
|||
* 机智云 |
|||
*/ |
|||
Integer TACT_CLOUD = 0; |
|||
} |
|||
@ -1,102 +0,0 @@ |
|||
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.math.BigDecimal; |
|||
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()); |
|||
if (StringUtils.isNotBlank(event.getStoping_duration())) { |
|||
BigDecimal stoppingDuration = new BigDecimal(event.getStoping_duration()); |
|||
machineIotDataReceivedEvent.setCurrStoppingDuration(stoppingDuration.longValue()); |
|||
} |
|||
machineIotDataReceivedEvent.setCurrWaitingDuration(Objects.isNull(event.getWaiting_duration()) ? null : event.getWaiting_duration().longValue()); |
|||
machineIotDataReceivedEvent.setReportTime(System.currentTimeMillis()); |
|||
} |
|||
return machineIotDataReceivedEvent; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
################################################################################ |
|||
# Licensed to the Apache Software Foundation (ASF) under one |
|||
# or more contributor license agreements. See the NOTICE file |
|||
# distributed with this work for additional information |
|||
# regarding copyright ownership. The ASF licenses this file |
|||
# to you under the Apache License, Version 2.0 (the |
|||
# "License"); you may not use this file except in compliance |
|||
# with the License. You may obtain a copy of the License at |
|||
# |
|||
# http://www.apache.org/licenses/LICENSE-2.0 |
|||
# |
|||
# Unless required by applicable law or agreed to in writing, software |
|||
# distributed under the License is distributed on an "AS IS" BASIS, |
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
# See the License for the specific language governing permissions and |
|||
# limitations under the License. |
|||
################################################################################ |
|||
|
|||
rootLogger.level = INFO |
|||
rootLogger.appenderRef.console.ref = ConsoleAppender |
|||
|
|||
appender.console.name = ConsoleAppender |
|||
appender.console.type = CONSOLE |
|||
appender.console.layout.type = PatternLayout |
|||
appender.console.layout.pattern = %d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n |
|||
Write
Preview
Loading…
Cancel
Save