|  |  | 
 |  |  |  | 
 |  |  | import java.math.BigDecimal; | 
 |  |  | import java.text.ParseException; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.time.Instant; | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.HashSet; | 
 |  |  | import java.util.Iterator; | 
 |  |  | import java.util.LinkedHashMap; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | 
 |  |  | import com.moral.common.util.ReportTimeFormat; | 
 |  |  | import com.moral.common.util.ResourceUtil; | 
 |  |  | import com.moral.common.util.ValidateUtil; | 
 |  |  | import com.moral.entity.Area; | 
 |  |  | import com.moral.entity.City; | 
 |  |  | import com.moral.entity.MonitorPoint; | 
 |  |  | import com.moral.entity.Province; | 
 |  |  | import com.moral.entity.Sensor; | 
 |  |  | import com.moral.entity.charts.DataCondition; | 
 |  |  | import com.moral.entity.charts.LineChartCriteria; | 
 |  |  | import com.moral.entity.charts.TimePeriod; | 
 |  |  | import com.moral.mapper.AlarmDailyMapper; | 
 |  |  | import com.moral.mapper.AreaMapper; | 
 |  |  | import com.moral.mapper.CityMapper; | 
 |  |  | import com.moral.mapper.DeviceMapper; | 
 |  |  | import com.moral.mapper.HistoryMapper; | 
 |  |  | import com.moral.mapper.HistoryMinutelyMapper; | 
 |  |  | import com.moral.mapper.MonitorPointMapper; | 
 |  |  | import com.moral.mapper.ProvinceMapper; | 
 |  |  | import com.moral.mapper.SensorMapper; | 
 |  |  | import com.moral.service.HistoryMinutelyService; | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private AlarmDailyMapper alarmDailyMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private AreaMapper areaMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ProvinceMapper provinceMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private CityMapper cityMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private MonitorPointMapper monitorPointMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) { | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<Map<String, Object>> getAreaAvgDataByAreaCode(Map<String, Object> parameters) throws Exception { | 
 |  |  |         convertQueryParam(parameters); | 
 |  |  |         if (!ObjectUtils.isEmpty(parameters.get("compensate"))) { | 
 |  |  |             parameters.put("timeUnits", "10min"); | 
 |  |  |         } | 
 |  |  |         return historyMinutelyMapper.getAreaAvgDataByAreaCode(parameters); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void convertQueryParam(Map<String, Object> parameters) throws ParseException { | 
 |  |  |         if (!parameters.containsKey("field")) { | 
 |  |  |             // String type = (String) parameters.get("type"); | 
 |  |  | 
 |  |  |                         String[] timeStr = parameters.get("time").toString().split("-"); | 
 |  |  |                         int year = Integer.valueOf(timeStr[0]); | 
 |  |  |                         int month = Integer.valueOf(timeStr[1]); | 
 |  |  |                         String yearAndMonth; | 
 |  |  |                         if (month < 10) { | 
 |  |  |                             yearAndMonth = "minutely_" + year + "0" + month; | 
 |  |  |                         } else { | 
 |  |  |                             yearAndMonth = "minutely_" + year + month; | 
 |  |  |                         } | 
 |  |  |                         if (year >= 2020) { | 
 |  |  |                             String yearAndMonth; | 
 |  |  |                             if (month < 10) { | 
 |  |  |                                 yearAndMonth = "minutely_" + year + "0" + month; | 
 |  |  |                             } else { | 
 |  |  |                                 yearAndMonth = "minutely_" + year + month; | 
 |  |  |                             } | 
 |  |  |                             parameters.put("timeUnits", yearAndMonth); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  | 
 |  |  |         return historyMinutelyMapper.getDevicesSensorsAvgDataToExcel(parameters); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<Map<String, Object>> get5MinutesOrHalfHour(Map<String, Object> parameters) throws ParseException { | 
 |  |  |         if (parameters.get("city") == null) { | 
 |  |  |             return new ArrayList<Map<String, Object>>(); | 
 |  |  |         } | 
 |  |  |         String string = parameters.get("time").toString(); | 
 |  |  |         String year = string.substring(0, 4); | 
 |  |  |         String[] split = string.substring(5).split("-"); | 
 |  |  |         String month = split[0]; | 
 |  |  |         String day = split[1]; | 
 |  |  |         if (split[0].length() < 2) { | 
 |  |  |             month = 0 + split[0]; | 
 |  |  |         } | 
 |  |  |         if (split[1].length() < 2) { | 
 |  |  |             day = 0 + split[1]; | 
 |  |  |         } | 
 |  |  |         String time = year + "-" + month + "-" + day; | 
 |  |  |         String cityName = parameters.get("city").toString(); | 
 |  |  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |         String type = parameters.get("type").toString(); | 
 |  |  |         String range = parameters.get("range").toString(); | 
 |  |  |         Area area = areaMapper.getAreaByName(cityName); | 
 |  |  |         Integer code; | 
 |  |  |         String name; | 
 |  |  |         if (area == null) { | 
 |  |  |             City city = cityMapper.getCityByName(cityName); | 
 |  |  |             if (city == null) { | 
 |  |  |                 Province province = provinceMapper.getProvinceByName(cityName); | 
 |  |  |                 code = province.getProvinceCode(); | 
 |  |  |                 name = province.getProvinceName(); | 
 |  |  |             } else { | 
 |  |  |                 code = city.getCityCode(); | 
 |  |  |                 name = city.getCityName(); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             code = area.getAreaCode(); | 
 |  |  |             name = area.getAreaName(); | 
 |  |  |         } | 
 |  |  |         parameters.put("cityCode", code); | 
 |  |  |         parameters.put("name", name); | 
 |  |  |         Map<String, Object> map = new HashMap<>(); | 
 |  |  |         if (code.toString().endsWith("0000")) { | 
 |  |  |             map.put("provinceCode", code); | 
 |  |  |         } else if (code.toString().endsWith("00")) { | 
 |  |  |             map.put("cityCode", code); | 
 |  |  |         } else { | 
 |  |  |             map.put("areaCode", code); | 
 |  |  |         } | 
 |  |  |         //List<String> sensorKeys = sensorMapper.getSensorKeys(); | 
 |  |  |  | 
 |  |  |         List<String> sensorKeys = new ArrayList<String>(); | 
 |  |  |         Collections.addAll(sensorKeys, "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e10", "e11", "e12", "e13", "e14", "e15" | 
 |  |  |                 , "e16", "e17", "e18", "e21", "e23", "e25", "e26", "e27", "e28", "e31", "e33", "e45", "e49", "e97", "e98", "e102"); | 
 |  |  |  | 
 |  |  |         String timeUnits = "minutely_" + time.substring(0, 7).replace("-", ""); | 
 |  |  |         map.put("sensorKeys", sensorKeys); | 
 |  |  |         map.put("timeUnits", timeUnits); | 
 |  |  |         Calendar cal = Calendar.getInstance(); | 
 |  |  |         List<Map<String, Object>> resultList = new ArrayList<>(); | 
 |  |  |         int seg; | 
 |  |  |         long startTime; | 
 |  |  |         long endTime; | 
 |  |  |         int minuteChange; | 
 |  |  |         if ("m".equals(type)) { | 
 |  |  |             cal.setTime(sdf.parse(time + " 00:05:00")); | 
 |  |  |             startTime = cal.getTimeInMillis(); | 
 |  |  |             cal.add(Calendar.DAY_OF_MONTH, 1); | 
 |  |  |             endTime = cal.getTimeInMillis(); | 
 |  |  |             seg = 5 * 60 * 1000; | 
 |  |  |             minuteChange = -5; | 
 |  |  |         } else { | 
 |  |  |             cal.setTime(sdf.parse(time + " 00:30:00")); | 
 |  |  |             startTime = cal.getTimeInMillis(); | 
 |  |  |             cal.add(Calendar.DAY_OF_MONTH, 1); | 
 |  |  |             endTime = cal.getTimeInMillis(); | 
 |  |  |             seg = 30 * 60 * 1000; | 
 |  |  |             minuteChange = -30; | 
 |  |  |         } | 
 |  |  |         for (long time1 = startTime; time1 < endTime; time1 += seg) { | 
 |  |  |             Date end = new Date(time1); | 
 |  |  |             cal.setTime(end); | 
 |  |  |             cal.add(Calendar.MINUTE, minuteChange); | 
 |  |  |             Date start = cal.getTime(); | 
 |  |  |             map.put("start", start); | 
 |  |  |             map.put("end", end); | 
 |  |  |             Map<String, Object> dataMap = historyMinutelyMapper.get5MiutesOrHalfHourByDay(map); | 
 |  |  |             if (dataMap == null) { | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             dataMap.put("time", sdf.format(end)); | 
 |  |  |             dataMap.put("city", name); | 
 |  |  |             Set<String> set = dataMap.keySet(); | 
 |  |  |             Iterator<String> it = set.iterator(); | 
 |  |  |             List<String> listKey = new ArrayList<>(); | 
 |  |  |             while (it.hasNext()) { | 
 |  |  |                 String key = it.next(); | 
 |  |  |                 if (dataMap.get(key) == null || "".equals(dataMap.get(key))) { | 
 |  |  |                     listKey.add(key); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             for (String key : listKey) { | 
 |  |  |                 dataMap.remove(key); | 
 |  |  |             } | 
 |  |  |             resultList.add(dataMap); | 
 |  |  |         } | 
 |  |  |         return resultList; | 
 |  |  |     } | 
 |  |  | } |