CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.ld.igds.protocol.fzzy.analysis;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.common.CoreDeviceIotService;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.grain.dto.GrainIotData;
import com.ld.igds.models.DeviceIot;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.models.WeatherInfo;
import com.ld.igds.protocol.fzzy.command.BaseRemoteImpl;
import com.ld.igds.protocol.fzzy.dto.ReMessage;
import com.ld.igds.protocol.fzzy.resp.Response6001;
import com.ld.igds.util.RedisUtil;
import com.ld.igds.weather.CoreWeatherService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
 
/**
 * 物联网设备数据解析
 *
 * @author chen
 */
@Slf4j
@Component(AnalysisIot.BEAN_ID)
public class AnalysisIot extends BaseRemoteImpl {
 
    public static final String BEAN_ID = "fzzy.analysisIot";
 
    @Autowired
    private CoreDeviceIotService coreDeviceIotService;
    @Autowired
    private CoreWeatherService weatherService;
    @Autowired
    private RedisUtil redisUtil;
 
    public void analysis6001(ReMessage reMessage, DeviceSer ser) {
 
        Response6001 resp = JSONObject.parseObject(reMessage.getContent(), Response6001.class);
 
        if (null == resp || StringUtils.isEmpty(resp.getDeviceId())) {
            log.error("控制柜------>>>平台:未获取IOt设备编码" + resp);
            return;
        }
 
        try {
            List<DeviceIot> deviceIots = coreDeviceIotService.getCacheDeviceIotBySerId(ser.getCompanyId(), ser.getId());
 
            DeviceIot deviceIot = deviceIots.stream().filter(item -> (item.getPassCode() + "").equals(resp.getDeviceId())).findAny().orElse(null);
 
            if (null == deviceIot) {
                log.error("控制柜------>>>平台:未获取IOt设备" + resp);
                return;
            }
 
            GrainIotData data = new GrainIotData();
            data.setCompanyId(ser.getCompanyId());
 
            data.setDepotId(deviceIot.getDepotId());
            data.setName(deviceIot.getName());
 
            data.setDeviceId(deviceIot.getId());
            data.setHum(resp.getHum());
            data.setTemp(resp.getTemp());
            data.setTime(resp.getTime());
 
            //外温外湿
            WeatherInfo weatherInfo = weatherService.getCacheWeather(ser.getCompanyId());
            Double tOut = -100.0, hOut = -100.0;
            if (null != weatherInfo) {
                if (weatherInfo.getTemp().indexOf("℃") > 0) {
                    weatherInfo.setTemp(weatherInfo.getTemp().replace("℃", ""));
                }
                if (weatherInfo.getHumidity().indexOf("%") > 0) {
                    weatherInfo.setHumidity(weatherInfo.getHumidity().replace("%",
                            ""));
                }
                tOut = Double.valueOf(weatherInfo.getTemp());
                hOut = Double.valueOf(weatherInfo.getHumidity());
            }
            if(tOut > -100){
                data.setOutTemp(tOut);
            }
            if(hOut > -100){
                data.setOutHum(hOut);
            }
 
            //物联网关温湿度设备解析数据暂时存入缓存,以供后续使用。
            String ket = RedisConst.buildKey(ser.getCompanyId(), RedisConst.KEY_IOT_DEPOT_TEMP_HUM, deviceIot.getDepotId(), deviceIot.getId());
            redisUtil.set(ket, data);
            log.info("物联网关设备温湿度解析成功:" + data.toString());
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}