| | |
| | | package com.moral.api.util; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | import java.util.Set; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.googlecode.aviator.AviatorEvaluator; |
| | | import com.googlecode.aviator.Expression; |
| | | import com.moral.api.entity.DeviceAdjustValue; |
| | | import com.moral.api.mapper.HistoryHourlyMapper; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class AdjustDataUtils { |
| | | |
| | | @Autowired |
| | | private HistoryHourlyMapper historyHourlyMapper; |
| | | /** |
| | | * @param deviceData 设备数据 |
| | | * @param adjustFormula 校准公式,包含所有因子校准公式,key为因子code,value为校准公式(各个时间段的公式List) |
| | | * @param aqiMap 与设备绑定的国控站点aqi数据 |
| | | * @return Map<String, Object> 校准后数据 |
| | | */ |
| | | public Map<String, Object> adjust(Map<String, Object> deviceData, Map<String, Object> adjustFormula, Map<String, Object> aqiMap) { |
| | | public Map<String, Object> adjust(Map<String, Object> deviceData, Map<String, Object> adjustFormula, Map<String, Object> aqiMap,String code) { |
| | | try { |
| | | Date time = DateUtils.getDate((String) deviceData.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN); |
| | | String mac = deviceData.remove("mac").toString(); |
| | | long finalTime = DateUtils.dataToTimeStampTime(time, DateUtils.HH_mm_ss_EN).getTime(); |
| | | |
| | | //先校准烟气流速,再用流速校准烟气流量 |
| | |
| | | deviceData.put(key, Double.parseDouble(String.format("%.4f", measuredValue))); |
| | | } |
| | | } |
| | | if (code.equals("2")){ |
| | | HashMap<String, Object> result = new HashMap<>(); |
| | | String yearAndMonth = DateUtils.dateToDateString(DateUtils.addHours(time, -2), DateUtils.yyyyMM_EN); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00"); |
| | | String format = simpleDateFormat.format(DateUtils.addHours(time, -2)); |
| | | result.put("timeUnits",yearAndMonth); |
| | | result.put("mac",mac); |
| | | result.put("time",format); |
| | | Map<String, Object> map = historyHourlyMapper.selectHistoryHourly(result); |
| | | if (ObjectUtils.isEmpty(map)){ |
| | | return deviceData; |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a21005"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a21005 = jsonObject.get("a21005").toString(); |
| | | deviceData.put("a21005",Double.parseDouble(a21005)); |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a21026"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a21026 = jsonObject.get("a21026").toString(); |
| | | deviceData.put("a21026",Double.parseDouble(a21026)); |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a21004"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a21004 = jsonObject.get("a21004").toString(); |
| | | deviceData.put("a21004",Double.parseDouble(a21004)); |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a34002"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a34002 = jsonObject.get("a34002").toString(); |
| | | deviceData.put("a34002",Double.parseDouble(a34002)); |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a34004"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a34004 = jsonObject.get("a34004").toString(); |
| | | deviceData.put("a34004",Double.parseDouble(a34004)); |
| | | } |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a05024"))){ |
| | | JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString()); |
| | | String a05024 = jsonObject.get("a05024").toString(); |
| | | deviceData.put("a05024",Double.parseDouble(a05024)); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("param[0] deviceData:" + JSON.toJSONString(deviceData)); |
| | | } |