|
|
|
@ -0,0 +1,68 @@
|
|
|
|
|
package com.shxy.xymanager_framework.mqtt;
|
|
|
|
|
|
|
|
|
|
import com.shxy.xymanager_common.entity.Terminals;
|
|
|
|
|
import com.shxy.xymanager_common.entity.Weathers;
|
|
|
|
|
import com.shxy.xymanager_common.entity.WeathersExample;
|
|
|
|
|
import com.shxy.xymanager_common.model.mqtt.CommonData;
|
|
|
|
|
import com.shxy.xymanager_common.util.DateUtil;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.WeathersMapper;
|
|
|
|
|
import com.shxy.xymanager_service.service.TerminalExtService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class WeatherHandler {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
TerminalExtService terminalExtService;
|
|
|
|
|
@Resource
|
|
|
|
|
WeathersMapper weathersMapper;
|
|
|
|
|
|
|
|
|
|
public void handleUpload(CommonData data, String deviceId) throws Exception {
|
|
|
|
|
Terminals term = terminalExtService.getByCmdid(deviceId);
|
|
|
|
|
if (term == null) {
|
|
|
|
|
log.error("mqtt收到天气,但是该装置" + deviceId + "不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String time = data.getTime().replace("T", "").replace("Z", "");
|
|
|
|
|
Date dTime = DateUtil.parse(time, "yyyyMMddHHmmss");
|
|
|
|
|
long updateTime = dTime.getTime() / 1000;
|
|
|
|
|
|
|
|
|
|
Weathers record = new Weathers();
|
|
|
|
|
record.setTermId(term.getId());
|
|
|
|
|
record.setUpdateTime(updateTime);
|
|
|
|
|
record.setAirTemperature(data.getTemperature());
|
|
|
|
|
record.setHumidity(data.getHumidity());
|
|
|
|
|
record.setAirPressure(data.getAirPressure());
|
|
|
|
|
record.setStandardWindSpeed(data.getInstanWindSpeed());
|
|
|
|
|
record.setWindDirection(data.getInstanWindDirection());
|
|
|
|
|
record.setExtremeWindSpeed(data.getExtremeWindSpeed());
|
|
|
|
|
record.setMaxWindSpeed(data.getMaxWindSpeed10());
|
|
|
|
|
record.setAvgWindSpeed1min(data.getAveWindSspeed1());
|
|
|
|
|
record.setAvgWindDir1min(data.getAveWindDirection1());
|
|
|
|
|
record.setAvgWindSpeed10min(data.getAveWindSspeed10());
|
|
|
|
|
record.setAvgWindDir10min(data.getAveWindDirection10());
|
|
|
|
|
record.setRadiationIntensity(data.getRadiationIntensity());
|
|
|
|
|
record.setPrecipitation(data.getPrecipitation1());
|
|
|
|
|
record.setCreateTime(new Date());
|
|
|
|
|
|
|
|
|
|
WeathersExample example = new WeathersExample();
|
|
|
|
|
WeathersExample.Criteria criteria = example.createCriteria();
|
|
|
|
|
criteria.andTermIdEqualTo(term.getId());
|
|
|
|
|
criteria.andUpdateTimeEqualTo(updateTime);
|
|
|
|
|
List<Weathers> list = weathersMapper.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
weathersMapper.insert(record);
|
|
|
|
|
} else {
|
|
|
|
|
Weathers old = list.get(0);
|
|
|
|
|
record.setId(old.getId());
|
|
|
|
|
weathersMapper.updateByPrimaryKey(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|