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