| | |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.moral.api.service.SensorService; |
| | | import com.moral.api.service.UnitConversionService; |
| | | import com.moral.api.utils.StringUtils; |
| | | import com.moral.api.vo.OnlineRateVo; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | |
| | | |
| | | @Autowired |
| | | SensorService sensorService; |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | |
| | | @Autowired |
| | | UnitConversionService unitConversionService; |
| | |
| | | ); |
| | | |
| | | //设备mac |
| | | List<String> macs = (List<String>) params.remove("macs"); |
| | | List<String> macList = (List<String>) params.remove("macs"); |
| | | List<Map<String, Object>> elementLists = new ArrayList<>(); |
| | | |
| | | List<String> idList = macList.stream().filter(it->it.contains(",avg")).collect(Collectors.toList()); |
| | | List<String> idListExcluding = macList.stream().filter(it->!it.contains(",avg")).collect(Collectors.toList()); |
| | | List<String> macs = new ArrayList<>(); |
| | | for(String s : idList){ |
| | | String mm = s.substring(0, s.indexOf(",avg")); |
| | | List<String> macResultList = deviceService.getMacMonitorPointId(Integer.parseInt(mm)); |
| | | macs.addAll(macResultList); |
| | | } |
| | | macs.addAll(idListExcluding); |
| | | macs = macs.stream().distinct().collect(Collectors.toList()); |
| | | for (String mac : macs) { |
| | | //从redis中获取设备因子信息 |
| | | Device device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, mac); |
| | |
| | | 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) { |
| | | /* for (String mac:macs) { |
| | | Map<String, Object> mapParams = new HashMap<>(); |
| | | mapParams.put("startDate",startDate); |
| | | mapParams.put("endDate",endDate); |
| | |
| | | historyHourlyMap.put("time",timeStr); |
| | | list.add(historyHourlyMap); |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | for (String mac:macs) { |
| | | Map<String, Object> mapParams = new HashMap<>(); |
| | | mapParams.put("startDate",startDate); |
| | | mapParams.put("endDate",endDate); |
| | | mapParams.put("mac",mac); |
| | | List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(mapParams, 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_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 = Objects.nonNull(value)&&Objects.nonNull(value.get(sensorCode))?Double.parseDouble(value.get(sensorCode).toString()):0d; |
| | | historyHourlyMap.put(sensorCode,sensorValue); |
| | | Date time = historyFiveMinutely.getTime(); |
| | | String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | historyHourlyMap.put("time",timeStr); |
| | | list.add(historyHourlyMap); |
| | | } |
| | | } |
| | | Date middleDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | while (DateUtils.compareDateStr(endTime,DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_mm_EN),DateUtils.yyyy_MM_dd_HH_mm_EN)<=0){ |
| | | for (String mac:macs) { |
| | | boolean flag = true; |
| | | for (Map map:list) { |
| | | if (map.get("time").equals(DateUtils.dateToDateString(middleDate, DateUtils.yyyy_MM_dd_HH_mm_EN)) && map.get("mac").toString().equals(mac.toString())){ |
| | | flag = false; |
| | | } |
| | | } |
| | | if (flag){ |
| | | Map<String,Object> historyHourlyMap = new HashMap<>(); |
| | | historyHourlyMap.put("mac",mac); |
| | | historyHourlyMap.put(sensorCode,"0.0"); |
| | | historyHourlyMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_mm_EN)); |
| | | list.add(historyHourlyMap); |
| | | } |
| | | } |
| | | middleDate = DateUtils.getDateOfMin(middleDate,5); |
| | | } |
| | | } |
| | | for (Map map:list) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List getMacMonitorPointId(Integer monitorPointId) { |
| | | QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("mac") |
| | | .eq("monitor_point_id", monitorPointId) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | return deviceMapper.selectObjs(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List getMacsByOrgIdAndRegionCode(Integer organizationId, Integer regionCode) { |
| | | QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("mac") |
| | |
| | | long hour = (diff / nh)+1; //获取间隔几个小时 |
| | | |
| | | Map<String, List<OnlineRateVo>> collectList=new HashMap<>(); |
| | | List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getOrganizationId(),onlineRatePageCond.getState()); |
| | | // List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getOrganizationId(),onlineRatePageCond.getState()); |
| | | List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getMacs(),onlineRatePageCond.getState()); |
| | | if (!ObjectUtils.isEmpty(OnlineRateVoList)){ |
| | | |
| | | for (OnlineRateVo onlineRateVo : OnlineRateVoList) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String,Object> getStart(Integer organizationId) { |
| | | public Map<String,Object> getStart(List<String> macs) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | List<OnlineRateVo> lists = deviceMapper.getLists(organizationId, null); |
| | | List<OnlineRateVo> lists = deviceMapper.getLists(macs, null); |
| | | if (!ObjectUtils.isEmpty(lists)){ |
| | | Map<String, List<OnlineRateVo>> collect = lists.stream().collect(Collectors.groupingBy(OnlineRateVo::getState)); |
| | | int size1 = lists.size(); |
| | |
| | | } |
| | | return OrfList; |
| | | } |
| | | private boolean subStr(String mac){ |
| | | if(StringUtils.isNotEmpty(mac)&&mac.contains(",avg")){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |