2021与蓝度共同重构项目,服务端
chenjiantian
2022-01-17 b861218460bd7d96bf638242608ecb2002299880
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.sandu.ximon.admin.manager.iot.amqp.processor;
 
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightErrorCodeReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightTimeSyncReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5LightReportEnum;
import com.sandu.ximon.admin.service.LightReportDataService;
import com.sandu.ximon.admin.service.LightReportErrorService;
import com.sandu.ximon.admin.service.LightService;
import lombok.extern.slf4j.Slf4j;
 
/**
 * @author chenjiantian
 * @date 2021/12/13 11:58
 * 单灯数据上报处理
 */
@Slf4j
public class LightDataProcessor implements IMessageProcessor {
 
    private LightDataProcessor() {
    }
 
    public static LightDataProcessor getInstance() {
        return LightDataProcessorHolder.INSTANCE;
    }
 
    private static class LightDataProcessorHolder {
 
        private static final LightDataProcessor INSTANCE = new LightDataProcessor();
    }
 
    @Override
    public void process(String productKey, String deviceName, CommonFrame frame) {
        String functionCode = frame.getPayload().substring(2, 4);
        if (A5LightReportEnum.HeartBeat_Data.getCode().equals(functionCode)) {
            log.info("心跳相应");
            A5LightHeartbeatReportInnerFrame heartbeatReportInnerFrame = new A5LightHeartbeatReportInnerFrame().transformFrame(frame.getPayload());
 
            if (heartbeatReportInnerFrame.isValidate()) {
                SpringContextHolder.getBean(LightReportDataService.class).saveReportData(deviceName, heartbeatReportInnerFrame.getHeartBeatDataPackage());
                SpringContextHolder.getBean(LightService.class).saveLight(deviceName, heartbeatReportInnerFrame.getHeartBeatDataPackage());
            }
 
        } else if (A5LightReportEnum.Time_Synchronized.getCode().equals(functionCode)) {
//            log.info("请求时间同步");
            A5LightTimeSyncReportInnerFrame syncRespInnerFrame = new A5LightTimeSyncReportInnerFrame().transformFrame(frame.getPayload());
//            log.info(syncRespInnerFrame.toString());
        } else if (A5LightReportEnum.Error_Code.getCode().equals(functionCode)) {
            log.info("故障码上报");
            A5LightErrorCodeReportInnerFrame codeRespInnerFrame = new A5LightErrorCodeReportInnerFrame().transformFrame(frame.getPayload());
            if (codeRespInnerFrame.isValidate() && codeRespInnerFrame.getErrorCode() != 0) {
                SpringContextHolder.getBean(LightReportErrorService.class).saveReportError(deviceName, codeRespInnerFrame);
            }
        }
    }
}