|  |  |  | 
|---|
|  |  |  | import com.moral.api.config.mybatis.MybatisPlusConfig; | 
|---|
|  |  |  | import com.moral.api.entity.*; | 
|---|
|  |  |  | import com.moral.api.mapper.DeviceMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.HistoryFiveMinutelyMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.HistoryHourlyMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.OrganizationUnitAlarmMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UnitConversionMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | HistoryHourlyMapper historyHourlyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | HistoryFiveMinutelyMapper historyFiveMinutelyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | middleDate = DateUtils.addDays(middleDate,1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | } else if ("monthly".equals(type)){ | 
|---|
|  |  |  | end = DateUtils.getDateAddMonth(endTime, 1); | 
|---|
|  |  |  | timeUnits = "monthly"; | 
|---|
|  |  |  | dateFormat = "%Y-%m"; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | middleDate = DateUtils.addMonths(middleDate,1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  | Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  | List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH); | 
|---|
|  |  |  | for (String mac:macs) { | 
|---|
|  |  |  | QueryWrapper<HistoryFiveMinutely> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("mac", mac); | 
|---|
|  |  |  | wrapper.between("time", startDate, endDate); | 
|---|
|  |  |  | List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(wrapper, tableNames); | 
|---|
|  |  |  | HistoryFiveMinutelys = HistoryFiveMinutelys.stream().distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | List<HistoryFiveMinutely> distinctHistoryHourlies = new ArrayList<>(); | 
|---|
|  |  |  | Map<String, Object> disMap = new HashMap<>(); | 
|---|
|  |  |  | for (HistoryFiveMinutely historyFiveMinutely:HistoryFiveMinutelys) { | 
|---|
|  |  |  | Date time = historyFiveMinutely.getTime(); | 
|---|
|  |  |  | String timeStr = DateUtils.dateToDateString(time,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  | if (!disMap.containsKey(timeStr)){ | 
|---|
|  |  |  | distinctHistoryHourlies.add(historyFiveMinutely); | 
|---|
|  |  |  | disMap.put(timeStr,true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (HistoryFiveMinutely historyFiveMinutely:distinctHistoryHourlies) { | 
|---|
|  |  |  | Map<String,Object> historyHourlyMap = new HashMap<>(); | 
|---|
|  |  |  | historyHourlyMap.put("mac",mac); | 
|---|
|  |  |  | JSONObject value = JSONObject.parseObject(historyFiveMinutely.getValue()); | 
|---|
|  |  |  | Double sensorValue = Double.parseDouble(value.get(sensorCode).toString()); | 
|---|
|  |  |  | historyHourlyMap.put(sensorCode,sensorValue); | 
|---|
|  |  |  | Date time = historyFiveMinutely.getTime(); | 
|---|
|  |  |  | String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  | historyHourlyMap.put("time",timeStr); | 
|---|
|  |  |  | list.add(historyHourlyMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Map map:list) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<HistoryFiveMinutely> FiveMinuteTableQuery(QueryWrapper<HistoryFiveMinutely> wrapper, List<String> tableNames) { | 
|---|
|  |  |  | List<HistoryFiveMinutely> result = new ArrayList<>(); | 
|---|
|  |  |  | for (String tableName : tableNames) { | 
|---|
|  |  |  | MybatisPlusConfig.tableName.set(tableName); | 
|---|
|  |  |  | List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.selectList(wrapper); | 
|---|
|  |  |  | result.addAll(datas); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MybatisPlusConfig.tableName.remove(); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|