jinpengyong
2022-11-29 25576c047e39101a4784d8acffc92af3f35aa215
screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -22,6 +22,7 @@
import com.moral.constant.RedisConstants;
import com.moral.util.ConvertUtils;
import com.moral.util.DateUtils;
import com.sun.javafx.collections.MappingChange;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +37,8 @@
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -441,8 +444,10 @@
        return deviceInfo;
    }
    @Autowired
    private  HistoryHourlyMapper historyHourlyMapper;
    @Override
    public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData) {
    public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData,String code) {
        String mac = deviceData.remove("mac").toString();
        //从redis获取校准公式
        Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac);
@@ -454,6 +459,26 @@
            if (govMpInfo.get("guid") != null) {
                aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString());
            }
            if (code.equals("2")){
                if (ObjectUtils.isEmpty(aqiMap.get("a21005")) || ObjectUtils.isEmpty(aqiMap.get("a21026"))
                 || ObjectUtils.isEmpty(aqiMap.get("a21004")) || ObjectUtils.isEmpty(aqiMap.get("a34002"))
                 || ObjectUtils.isEmpty(aqiMap.get("a34004")) || ObjectUtils.isEmpty(aqiMap.get("a05024"))
                 || ObjectUtils.isEmpty(aqiMap)){
                    HashMap<String, Object> result = new HashMap<>();
                    String dataTime = deviceData.get("DataTime").toString();
                    Date time = DateUtils.getDate(dataTime, DateUtils.yyyyMMddHHmmss_EN);
                    String yearAndMonth = DateUtils.dateToDateString(DateUtils.addHours(time, -1), DateUtils.yyyyMM_EN);
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
                    String format = simpleDateFormat.format(DateUtils.addHours(time, -1));
                    result.put("timeUnits",yearAndMonth);
                    result.put("mac",mac);
                    result.put("time",format);
                    Map<String, Object> map = historyHourlyMapper.selectHistoryHourly(result);
                    if (!ObjectUtils.isEmpty(map)){
                       return JSON.parseObject(map.get("value").toString(),  Map.class);
                    }
                }
            }
            return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap);
        }
        deviceData.remove("DataTime");