@GetMapping("/show/warn1") @ResponseBody public PagingMz selectNewWarnEvery1(@RequestParam Integer page, @RequestParam Integer rows) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); List<Chl_data_realtime> realtimes = chl_data_realtimeReadService.selectAll().getResult(); if (realtimes == null || realtimes.size() == 0) { return new PagingMz(); } Date date = realtimes.get(0).getTime(); List<Long> ids = real_warnReadService.selectIdEvery().getResult(); List<Real_warn> chls = real_warnReadService.selectNewWarnEvery(ids).getResult(); // List<Real_warn> chls = real_warnReadService.selectNewWarnEvery1(date).getResult(); if (chls == null || chls.size() == 0) { return new PagingMz(); } List<String> UUIDs = new ArrayList<>(); for (Real_warn chl_data_warn : chls) { UUIDs.add(chl_data_warn.getUUID()); } List<Long> factoryIds = deviceBindingReadService.selectFactoryIdsByUUIDs(UUIDs).getResult(); List<BreedFactory> breedFactories = breedFactoryReadService.findByIds(factoryIds).getResult(); List<Device> devices = deviceReadService.findByCodes(UUIDs).getResult(); if (breedFactories == null || breedFactories.size() == 0) { return new PagingMz(); } List<DeviceBinding> bindings = new ArrayList<>(); bindings = deviceBindingReadService.selectByUUIDs(UUIDs).getResult(); List<Map<String, Object>> resultList = new ArrayList<>(); for (Real_warn chl_data_warn : chls) { if (chl_data_warn.getStatus() == -1) { continue; } if (!UUIDs.contains(chl_data_warn.getUUID())) { continue; } Map<String, Object> map = new HashMap<>(); map.put("id", chl_data_warn.getId()); map.put("signals", chl_data_warn.getSignals()); map.put("voltage", chl_data_warn.getVoltage()); String r=""; try{ if (chl_data_warn.getValue().indexOf(",")>0){ r=chl_data_warn.getValue().split(",")[0]; }else { r=chl_data_warn.getValue(); } }catch (Exception e){ r="0"; } map.put("value",r); map.put("time", sdf.format(chl_data_warn.getTime())); for (Device device : devices) { if (chl_data_warn.getStatus() == 1) { map.put("status", 1); } else { map.put("status", 2); } map.put("type", "液位仪"); Map<String, Object> criteria = new HashMap<>(); criteria.put("relation_id", device.getId()); criteria.put("from", 1); criteria.put("type", 2); criteria.put("status", 1); if (chl_data_warn.getUUID().equals(device.getUUID())) { map.put("devicename", device.getName()); map.put("deviceid", device.getId()); map.put("UUID", device.getUUID()); map.put("alertValueUp", device.getAlertValueUp()); map.put("alertValueDown", device.getAlertValueDown()); map.put("head", device.getHead()); map.put("phone", device.getPhone()); Float va = Float.parseFloat(r); Float up = Float.parseFloat(device.getAlertValueUp()); Float down = Float.parseFloat(device.getAlertValueDown()); if (va > up) { map.put("warnType", "上限告警"); if ((va - up) / up > 0.5) { map.put("warnLevel", 1); } else if ((va - up) / up > 0.3) { map.put("warnLevel", 2); } else { map.put("warnLevel", 3); } } else if (va < down) { map.put("warnType", "下限告警"); if ((down - va) / (down * -1) > 0.5) { map.put("warnLevel", 1); } else if ((down - va) / (down * -1) > 0.3) { map.put("warnLevel", 2); } else { map.put("warnLevel", 3); } } else { map.put("warnType", "正常"); } break; } } for (BreedFactory breedFactory : breedFactories) { for (DeviceBinding binding : bindings) { if (binding.getDevice_UUID().equals(chl_data_warn.getUUID()) && binding.getFactory_id() == breedFactory.getId()) { map.put("factoryName", breedFactory.getName()); map.put("factoryId", breedFactory.getId()); map.put("address", breedFactory.getDetail()); map.put("latitude", breedFactory.getLatitude()); map.put("longitude", breedFactory.getLongitude()); break; } } } resultList.add(map); } Long records = (long) resultList.size(); Long total = (records - 1) / rows + 1; List list = new ArrayList(); if ((page - 1) * rows < resultList.size()) { list = resultList.subList((page - 1) * rows, (page * rows) < resultList.size() ? page * rows : resultList.size()); } return new PagingMz<>(total, records, page, list); }
List<Map<String,Object>> 不写limit在 Controller里面分页
最新推荐文章于 2024-01-04 15:02:42 发布