|
@@ -255,300 +255,300 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
|
|
|
|
|
|
|
|
|
-// @Override
|
|
|
-// public List monitorDataGeneralView() {
|
|
|
-// List result = new ArrayList();
|
|
|
-// LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
-// String tenantId = loginUser.getTenantId();
|
|
|
-// //查询设备编码
|
|
|
-// List<String> deviceCodes = monitorDataReportMapper.selectDeviceCode(tenantId);
|
|
|
-// //根据编码获取redis中的实时数据
|
|
|
-// List<MonitorDataEntity> monitorDataEntities = new ArrayList<>();
|
|
|
-// for (String deviceCode : deviceCodes) {
|
|
|
-// //先取缓存里的数据
|
|
|
-// byte[] bytes = redisUtil.get(("sms_water_" + deviceCode).getBytes());
|
|
|
-// if (bytes != null && bytes.length > 0) {
|
|
|
-// monitorDataEntities.add((MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //将获取到 实时数据转换为map,方便匹配数据deviceId
|
|
|
-// Map<Integer, MonitorDataEntity> MonitorDataMap = monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
|
|
|
-//
|
|
|
-//
|
|
|
-// LocalDate localDate = LocalDate.now();
|
|
|
-// //水厂近30天供水量
|
|
|
-// List<DeviceWaterSupply> deviceWaterSupplies = monitorDataReportMapper.getDeviceWaterFor30Day(tenantId);
|
|
|
-// for (int i = 0; i < 30; i++) {
|
|
|
-// LocalDate newLocalDate = localDate.plusDays(-i - 1);
|
|
|
-// if (i <= deviceWaterSupplies.size()
|
|
|
-// || !newLocalDate.isEqual(LocalDate.of(deviceWaterSupplies.get(i).getYear(),
|
|
|
-// deviceWaterSupplies.get(i).getMonth(),
|
|
|
-// deviceWaterSupplies.get(i).getDay()))) {
|
|
|
-//
|
|
|
-// DeviceWaterSupply deviceWaterSupply = new DeviceWaterSupply();
|
|
|
-// deviceWaterSupply.setOrderNo(i + 1);
|
|
|
-// deviceWaterSupply.setAmount(BigDecimal.ZERO);
|
|
|
-// deviceWaterSupply.setYear(newLocalDate.getYear());
|
|
|
-// deviceWaterSupply.setMonth(newLocalDate.getMonthValue());
|
|
|
-// deviceWaterSupply.setDay(newLocalDate.getDayOfMonth());
|
|
|
-// deviceWaterSupply.setDate(newLocalDate);
|
|
|
-// deviceWaterSupplies.add(i, deviceWaterSupply);
|
|
|
-// } else {
|
|
|
-// deviceWaterSupplies.get(i).setOrderNo(i + 1);
|
|
|
-// deviceWaterSupplies.get(i).setDate(newLocalDate);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //0 30天水量
|
|
|
-// result.add(deviceWaterSupplies);
|
|
|
-//
|
|
|
-// //供水详情数据(合计:瞬时、本天、本月、本年)
|
|
|
-// DeviceWaterAmount deviceWaterAmount = new DeviceWaterAmount();
|
|
|
-// //14瞬时流量
|
|
|
-// List<DeviceWaterDetail> deviceSupplyWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水厂", 14, tenantId);
|
|
|
-// List<DeviceWaterDetail> deviceIntakeWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水源", 14, tenantId);
|
|
|
-//
|
|
|
-// //水厂获取实时流量并计算出当天流量
|
|
|
-// for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForNow) {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
-// if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
-// //水厂累计瞬时流量
|
|
|
-// deviceWaterAmount.addWaterSupplyAmountForNow(new BigDecimal(monitorDataValueEntity.getDataValue()));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// //水源获取实时流量并计算出当天流量
|
|
|
-// for (DeviceWaterDetail deviceWaterDetail : deviceIntakeWaterDetailsForNow) {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
-// if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
-// //水源累计瞬时流量
|
|
|
-// deviceWaterAmount.addWaterIntakeAmountForNow(new BigDecimal(monitorDataValueEntity.getDataValue()));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //3供水 4取水
|
|
|
-// List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay("水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
|
|
|
-// List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay("水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
|
|
|
-//
|
|
|
-// //水厂获取实时流量并计算出当天流量
|
|
|
-// for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
-// if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
-// //累计当天流量
|
|
|
-// deviceWaterAmount.addWaterSupplyAmountForDay(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount()));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// //水源获取实时流量并计算出当天流量
|
|
|
-// for (DeviceWaterDetail deviceWaterDetail : deviceIntakeWaterDetailsForDay) {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
-// if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
-// //累计当天流量
|
|
|
-// deviceWaterAmount.addWaterIntakeAmountForDay(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount()));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth("水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue());
|
|
|
-// BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水厂", 3, tenantId, localDate.getYear());
|
|
|
-// if (waterSupplyAmountForMonth == null) {
|
|
|
-// waterSupplyAmountForMonth = BigDecimal.ZERO;
|
|
|
-// }
|
|
|
-// if (waterSupplyAmountForYear == null) {
|
|
|
-// waterSupplyAmountForYear = BigDecimal.ZERO;
|
|
|
-// }
|
|
|
-// //水厂当月流量
|
|
|
-// if (deviceWaterAmount.getWaterSupplyAmountForDay() == null) {
|
|
|
-// deviceWaterAmount.setWaterSupplyAmountForMonth(waterSupplyAmountForMonth);
|
|
|
-// } else {
|
|
|
-// deviceWaterAmount.setWaterSupplyAmountForMonth(waterSupplyAmountForMonth.add(deviceWaterAmount.getWaterSupplyAmountForDay()));
|
|
|
-// }
|
|
|
-// //水厂当年流量
|
|
|
-// if (deviceWaterAmount.getWaterSupplyAmountForMonth() == null) {
|
|
|
-// deviceWaterAmount.setWaterSupplyAmountForYear(waterSupplyAmountForYear);
|
|
|
-// } else {
|
|
|
-// deviceWaterAmount.setWaterSupplyAmountForYear(waterSupplyAmountForYear.add(deviceWaterAmount.getWaterSupplyAmountForMonth()));
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth("水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue());
|
|
|
-// BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水源", 4, tenantId, localDate.getYear());
|
|
|
-// if (waterIntakeAmountForMonth == null) {
|
|
|
-// waterIntakeAmountForMonth = BigDecimal.ZERO;
|
|
|
-// }
|
|
|
-// if (waterIntakeAmountForYear == null) {
|
|
|
-// waterIntakeAmountForYear = BigDecimal.ZERO;
|
|
|
-// }
|
|
|
-// //水源当月流量
|
|
|
-// if (deviceWaterAmount.getWaterIntakeAmountForDay() == null) {
|
|
|
-// deviceWaterAmount.setWaterIntakeAmountForMonth(waterIntakeAmountForMonth);
|
|
|
-// } else {
|
|
|
-// deviceWaterAmount.setWaterIntakeAmountForMonth(waterIntakeAmountForMonth.add(deviceWaterAmount.getWaterIntakeAmountForDay()));
|
|
|
-// }
|
|
|
-// //水源当年流量
|
|
|
-// if (deviceWaterAmount.getWaterIntakeAmountForMonth() == null) {
|
|
|
-// deviceWaterAmount.setWaterIntakeAmountForYear(waterIntakeAmountForYear);
|
|
|
-// } else {
|
|
|
-// deviceWaterAmount.setWaterIntakeAmountForYear(waterIntakeAmountForYear.add(deviceWaterAmount.getWaterIntakeAmountForMonth()));
|
|
|
-// }
|
|
|
-// //1
|
|
|
-// result.add(deviceWaterAmount);
|
|
|
-//
|
|
|
-// //实时报警信息
|
|
|
-// List<SceneAlarm> sceneAlarms = monitorDataReportMapper.getAlarmInfoForScene(tenantId);
|
|
|
-//
|
|
|
-// //2报警
|
|
|
-// result.add(sceneAlarms);
|
|
|
-// //管网水质(水质 -1、8PH、10浊度、11余氯)
|
|
|
-// List<SceneNormalRate> SceneNormalRates = new ArrayList<>();
|
|
|
-// //水质
|
|
|
-// SceneNormalRate sceneNormalRate1 = monitorDataReportMapper.getQualificationForScene(tenantId, -1);
|
|
|
-// //PH
|
|
|
-// SceneNormalRate sceneNormalRate2 = monitorDataReportMapper.getQualificationForScene(tenantId, 8);
|
|
|
-// //浊度
|
|
|
-// SceneNormalRate sceneNormalRate3 = monitorDataReportMapper.getQualificationForScene(tenantId, 10);
|
|
|
-// //余氯
|
|
|
-// SceneNormalRate sceneNormalRate4 = monitorDataReportMapper.getQualificationForScene(tenantId, 11);
|
|
|
-// SceneNormalRates.add(sceneNormalRate1);
|
|
|
-// SceneNormalRates.add(sceneNormalRate2);
|
|
|
-// SceneNormalRates.add(sceneNormalRate3);
|
|
|
-// SceneNormalRates.add(sceneNormalRate4);
|
|
|
-// //3水质情况
|
|
|
-// result.add(SceneNormalRates);
|
|
|
-//
|
|
|
-// //压力分布
|
|
|
-// List<DeviceWaterDetail> devicePressureWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水厂", 13, tenantId);
|
|
|
-//
|
|
|
-// List<SceneWaterAmount> sceneWaterPressureAmounts = new ArrayList<>();
|
|
|
-//
|
|
|
-// devicePressureWaterDetailsForNow.stream()
|
|
|
-// .filter(item -> StringUtils.isNotBlank(item.getSceneName()))
|
|
|
-// .collect(Collectors.groupingBy(item -> item.getSceneName(), Collectors.toList()))
|
|
|
-// .forEach((key, value) -> {
|
|
|
-// SceneWaterAmount sceneWaterAmount = new SceneWaterAmount();
|
|
|
-// sceneWaterAmount.setSceneName(key);
|
|
|
-// sceneWaterAmount.setWaterAmount(BigDecimal.ZERO);
|
|
|
-// value.stream().forEach(deviceWaterDetail -> {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// monitorDataEntity.getDataValues().stream()
|
|
|
-// .filter(monitorDataValueEntity -> monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId()))
|
|
|
-// .forEach(monitorDataValueEntity ->
|
|
|
-// //累计当前压力
|
|
|
-// sceneWaterAmount.setWaterAmount(sceneWaterAmount.getWaterAmount().add(new BigDecimal(monitorDataValueEntity.getDataValue())))
|
|
|
-// );
|
|
|
-// }
|
|
|
-// });
|
|
|
-// sceneWaterPressureAmounts.add(sceneWaterAmount);
|
|
|
-// });
|
|
|
-//
|
|
|
-// //进行压力分组
|
|
|
-// SceneWaterPressure sceneWaterPressure = new SceneWaterPressure();
|
|
|
-// SceneWaterAmount amountMax = null;
|
|
|
-// SceneWaterAmount amountMin = null;
|
|
|
-// for (SceneWaterAmount waterPressure : sceneWaterPressureAmounts) {
|
|
|
-// if (StringUtils.isNotBlank(waterPressure.getSceneName()) && waterPressure.getWaterAmount() != null) {
|
|
|
-// BigDecimal amount = waterPressure.getWaterAmount();
|
|
|
-// amountMax = amountMax == null || amount.compareTo(amountMax.getWaterAmount()) == 1 ? waterPressure : amountMax;
|
|
|
-// amountMin = amountMin == null || amount.compareTo(amountMin.getWaterAmount()) == -1 ? waterPressure : amountMin;
|
|
|
-//
|
|
|
-// if (amount.compareTo(new BigDecimal(0.15)) == -1) {
|
|
|
-// sceneWaterPressure.setPressureLevel1(sceneWaterPressure.getPressureLevel1() + 1);
|
|
|
-// } else if (amount.compareTo(new BigDecimal(0.15)) != 1 && amount.compareTo(new BigDecimal(0.30)) == -1) {
|
|
|
-// sceneWaterPressure.setPressureLevel2(sceneWaterPressure.getPressureLevel2() + 1);
|
|
|
-// } else if (amount.compareTo(new BigDecimal(0.30)) != -1 && amount.compareTo(new BigDecimal(0.40)) == -1) {
|
|
|
-// sceneWaterPressure.setPressureLevel3(sceneWaterPressure.getPressureLevel3() + 1);
|
|
|
-// } else if (amount.compareTo(new BigDecimal(0.40)) != -1 && amount.compareTo(new BigDecimal(0.50)) == -1) {
|
|
|
-// sceneWaterPressure.setPressureLevel4(sceneWaterPressure.getPressureLevel4() + 1);
|
|
|
-// } else if (amount.compareTo(new BigDecimal(0.50)) != -1) {
|
|
|
-// sceneWaterPressure.setPressureLevel5(sceneWaterPressure.getPressureLevel5() + 1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (amountMax != null) {
|
|
|
-// sceneWaterPressure.setMaxPressureSceneName(amountMax.getSceneName());
|
|
|
-// sceneWaterPressure.setMaxPressureValue(amountMax.getWaterAmount());
|
|
|
-// }
|
|
|
-// if (amountMax != null) {
|
|
|
-// sceneWaterPressure.setMinPressureSceneName(amountMin.getSceneName());
|
|
|
-// sceneWaterPressure.setMinPressureValue(amountMin.getWaterAmount());
|
|
|
-// }
|
|
|
-//
|
|
|
-// //4压力分组
|
|
|
-// result.add(sceneWaterPressure);
|
|
|
-//
|
|
|
-// //今日水厂制水量排行
|
|
|
-//// deviceSupplyWaterDetailsForDay
|
|
|
-// List<SceneWaterAmount> sceneWaterAmounts = new ArrayList<>();
|
|
|
-// deviceSupplyWaterDetailsForDay.stream()
|
|
|
-// .filter(item -> StringUtils.isNotBlank(item.getSceneName()))
|
|
|
-// .collect(Collectors.groupingBy(item -> item.getSceneName(), Collectors.toList()))
|
|
|
-// .forEach((key, value) -> {
|
|
|
-// SceneWaterAmount sceneWaterAmount = new SceneWaterAmount();
|
|
|
-// sceneWaterAmount.setSceneName(key);
|
|
|
-// sceneWaterAmount.setWaterAmount(BigDecimal.ZERO);
|
|
|
-// value.stream().forEach(deviceWaterDetail -> {
|
|
|
-// MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
-// if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
-// monitorDataEntity.getDataValues().stream()
|
|
|
-// .filter(monitorDataValueEntity -> monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId()))
|
|
|
-// .forEach(monitorDataValueEntity ->
|
|
|
-// //累计当天流量
|
|
|
-// sceneWaterAmount.setWaterAmount(sceneWaterAmount.getWaterAmount().add(
|
|
|
-// new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount())))
|
|
|
-// );
|
|
|
-// }
|
|
|
-// });
|
|
|
-// sceneWaterAmounts.add(sceneWaterAmount);
|
|
|
-// });
|
|
|
-// //倒序排序
|
|
|
-// sceneWaterAmounts.sort(Comparator.comparing(SceneWaterAmount::getWaterAmount).reversed());
|
|
|
-// //5水量排行
|
|
|
-// result.add(sceneWaterAmounts);
|
|
|
-//
|
|
|
-// //水厂制水、药耗、电耗对比曲线
|
|
|
-// List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyData(tenantId);
|
|
|
-// List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
|
|
|
-// waterSupplyDatas.stream()
|
|
|
-// .collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth() + "-" + item.getDay()))
|
|
|
-// .forEach((key, value) -> {
|
|
|
-// WaterSupplyChart waterSupplyChart = new WaterSupplyChart();
|
|
|
-// waterSupplyChart.setDate(key);
|
|
|
-// value.stream().forEach(waterSupplyData -> {
|
|
|
-// Period period = Period.between(LocalDate.of(waterSupplyData.getYear(), waterSupplyData.getMonth(), waterSupplyData.getDay()), localDate);
|
|
|
-// waterSupplyChart.setSort(period.getDays());
|
|
|
-//
|
|
|
-// if (waterSupplyData.getParmType() == 3) { //供水
|
|
|
-// waterSupplyChart.setWaterData(waterSupplyData.getAmount());
|
|
|
-// } else if (waterSupplyData.getParmType() == 5) {//电耗
|
|
|
-// waterSupplyChart.setPowerData(waterSupplyData.getAmount());
|
|
|
-// } else if (waterSupplyData.getParmType() == 6) {//药耗
|
|
|
-// waterSupplyChart.setDrugData(waterSupplyData.getAmount());
|
|
|
-// }
|
|
|
-// });
|
|
|
-// waterSupplyCharts.add(waterSupplyChart);
|
|
|
-// });
|
|
|
-// waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort));
|
|
|
-//
|
|
|
-// //6曲线图
|
|
|
-// result.add(waterSupplyCharts);
|
|
|
-//
|
|
|
-// return result;
|
|
|
-// }
|
|
|
+ @Override
|
|
|
+ public GeneralViewResults monitorDataGeneralView() {
|
|
|
+ GeneralViewResults generalViewResults = new GeneralViewResults();
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ String tenantId = loginUser.getTenantId();
|
|
|
+ //查询设备编码
|
|
|
+ List<String> deviceCodes = monitorDataReportMapper.selectDeviceCode(tenantId);
|
|
|
+ //根据编码获取redis中的实时数据
|
|
|
+ List<MonitorDataEntity> monitorDataEntities = new ArrayList<>();
|
|
|
+ for (String deviceCode : deviceCodes) {
|
|
|
+ //先取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_" + deviceCode).getBytes());
|
|
|
+ if (bytes != null && bytes.length > 0) {
|
|
|
+ monitorDataEntities.add((MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将获取到 实时数据转换为map,方便匹配数据deviceId
|
|
|
+ Map<Integer, MonitorDataEntity> MonitorDataMap = monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
|
|
|
+
|
|
|
+
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ //水厂近30天供水量
|
|
|
+ List<DeviceWaterSupply> deviceWaterSupplies = monitorDataReportMapper.getDeviceWaterFor30Day(tenantId);
|
|
|
+ for (int i = 0; i < 30; i++) {
|
|
|
+ LocalDate newLocalDate = localDate.plusDays(-i - 1);
|
|
|
+ if (i <= deviceWaterSupplies.size()
|
|
|
+ || !newLocalDate.isEqual(LocalDate.of(deviceWaterSupplies.get(i).getYear(),
|
|
|
+ deviceWaterSupplies.get(i).getMonth(),
|
|
|
+ deviceWaterSupplies.get(i).getDay()))) {
|
|
|
+
|
|
|
+ DeviceWaterSupply deviceWaterSupply = new DeviceWaterSupply();
|
|
|
+ deviceWaterSupply.setOrderNo(i + 1);
|
|
|
+ deviceWaterSupply.setAmount(BigDecimal.ZERO);
|
|
|
+ deviceWaterSupply.setYear(newLocalDate.getYear());
|
|
|
+ deviceWaterSupply.setMonth(newLocalDate.getMonthValue());
|
|
|
+ deviceWaterSupply.setDay(newLocalDate.getDayOfMonth());
|
|
|
+ deviceWaterSupply.setDate(newLocalDate);
|
|
|
+ deviceWaterSupplies.add(i, deviceWaterSupply);
|
|
|
+ } else {
|
|
|
+ deviceWaterSupplies.get(i).setOrderNo(i + 1);
|
|
|
+ deviceWaterSupplies.get(i).setDate(newLocalDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //0 30天水量
|
|
|
+ generalViewResults.setDeviceWaterSupplies(deviceWaterSupplies);
|
|
|
+
|
|
|
+ //供水详情数据(合计:瞬时、本天、本月、本年)
|
|
|
+ DeviceWaterAmount deviceWaterAmount = new DeviceWaterAmount();
|
|
|
+ //14瞬时流量
|
|
|
+ List<DeviceWaterDetail> deviceSupplyWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水厂", 14, tenantId);
|
|
|
+ List<DeviceWaterDetail> deviceIntakeWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水源", 14, tenantId);
|
|
|
+
|
|
|
+ //水厂获取实时流量并计算出当天流量
|
|
|
+ for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForNow) {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
+ if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
+ //水厂累计瞬时流量
|
|
|
+ deviceWaterAmount.addWaterSupplyAmountForNow(new BigDecimal(monitorDataValueEntity.getDataValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //水源获取实时流量并计算出当天流量
|
|
|
+ for (DeviceWaterDetail deviceWaterDetail : deviceIntakeWaterDetailsForNow) {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
+ if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
+ //水源累计瞬时流量
|
|
|
+ deviceWaterAmount.addWaterIntakeAmountForNow(new BigDecimal(monitorDataValueEntity.getDataValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //3供水 4取水
|
|
|
+ List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay("水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
|
|
|
+ List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay("水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
|
|
|
+
|
|
|
+ //水厂获取实时流量并计算出当天流量
|
|
|
+ for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
+ if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
+ //累计当天流量
|
|
|
+ deviceWaterAmount.addWaterSupplyAmountForDay(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //水源获取实时流量并计算出当天流量
|
|
|
+ for (DeviceWaterDetail deviceWaterDetail : deviceIntakeWaterDetailsForDay) {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
+ if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
+ //累计当天流量
|
|
|
+ deviceWaterAmount.addWaterIntakeAmountForDay(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth("水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue());
|
|
|
+ BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水厂", 3, tenantId, localDate.getYear());
|
|
|
+ if (waterSupplyAmountForMonth == null) {
|
|
|
+ waterSupplyAmountForMonth = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ if (waterSupplyAmountForYear == null) {
|
|
|
+ waterSupplyAmountForYear = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //水厂当月流量
|
|
|
+ if (deviceWaterAmount.getWaterSupplyAmountForDay() == null) {
|
|
|
+ deviceWaterAmount.setWaterSupplyAmountForMonth(waterSupplyAmountForMonth);
|
|
|
+ } else {
|
|
|
+ deviceWaterAmount.setWaterSupplyAmountForMonth(waterSupplyAmountForMonth.add(deviceWaterAmount.getWaterSupplyAmountForDay()));
|
|
|
+ }
|
|
|
+ //水厂当年流量
|
|
|
+ if (deviceWaterAmount.getWaterSupplyAmountForMonth() == null) {
|
|
|
+ deviceWaterAmount.setWaterSupplyAmountForYear(waterSupplyAmountForYear);
|
|
|
+ } else {
|
|
|
+ deviceWaterAmount.setWaterSupplyAmountForYear(waterSupplyAmountForYear.add(deviceWaterAmount.getWaterSupplyAmountForMonth()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth("水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue());
|
|
|
+ BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水源", 4, tenantId, localDate.getYear());
|
|
|
+ if (waterIntakeAmountForMonth == null) {
|
|
|
+ waterIntakeAmountForMonth = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ if (waterIntakeAmountForYear == null) {
|
|
|
+ waterIntakeAmountForYear = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //水源当月流量
|
|
|
+ if (deviceWaterAmount.getWaterIntakeAmountForDay() == null) {
|
|
|
+ deviceWaterAmount.setWaterIntakeAmountForMonth(waterIntakeAmountForMonth);
|
|
|
+ } else {
|
|
|
+ deviceWaterAmount.setWaterIntakeAmountForMonth(waterIntakeAmountForMonth.add(deviceWaterAmount.getWaterIntakeAmountForDay()));
|
|
|
+ }
|
|
|
+ //水源当年流量
|
|
|
+ if (deviceWaterAmount.getWaterIntakeAmountForMonth() == null) {
|
|
|
+ deviceWaterAmount.setWaterIntakeAmountForYear(waterIntakeAmountForYear);
|
|
|
+ } else {
|
|
|
+ deviceWaterAmount.setWaterIntakeAmountForYear(waterIntakeAmountForYear.add(deviceWaterAmount.getWaterIntakeAmountForMonth()));
|
|
|
+ }
|
|
|
+ //1
|
|
|
+ generalViewResults.setDeviceWaterAmount(deviceWaterAmount);
|
|
|
+
|
|
|
+ //实时报警信息
|
|
|
+ List<SceneAlarm> sceneAlarms = monitorDataReportMapper.getAlarmInfoForScene(tenantId);
|
|
|
+
|
|
|
+ //2报警
|
|
|
+ generalViewResults.setSceneAlarms(sceneAlarms);
|
|
|
+ //管网水质(水质 -1、8PH、10浊度、11余氯)
|
|
|
+ List<SceneNormalRate> SceneNormalRates = new ArrayList<>();
|
|
|
+ //水质
|
|
|
+ SceneNormalRate sceneNormalRate1 = monitorDataReportMapper.getQualificationForScene(tenantId, -1);
|
|
|
+ //PH
|
|
|
+ SceneNormalRate sceneNormalRate2 = monitorDataReportMapper.getQualificationForScene(tenantId, 8);
|
|
|
+ //浊度
|
|
|
+ SceneNormalRate sceneNormalRate3 = monitorDataReportMapper.getQualificationForScene(tenantId, 10);
|
|
|
+ //余氯
|
|
|
+ SceneNormalRate sceneNormalRate4 = monitorDataReportMapper.getQualificationForScene(tenantId, 11);
|
|
|
+ SceneNormalRates.add(sceneNormalRate1);
|
|
|
+ SceneNormalRates.add(sceneNormalRate2);
|
|
|
+ SceneNormalRates.add(sceneNormalRate3);
|
|
|
+ SceneNormalRates.add(sceneNormalRate4);
|
|
|
+ //3水质情况
|
|
|
+ generalViewResults.setSceneNormalRates(SceneNormalRates);
|
|
|
+
|
|
|
+ //压力分布
|
|
|
+ List<DeviceWaterDetail> devicePressureWaterDetailsForNow = monitorDataReportMapper.getDeviceWaterDetailForNow("水厂", 13, tenantId);
|
|
|
+
|
|
|
+ List<SceneWaterAmount> sceneWaterPressureAmounts = new ArrayList<>();
|
|
|
+
|
|
|
+ devicePressureWaterDetailsForNow.stream()
|
|
|
+ .filter(item -> StringUtils.isNotBlank(item.getSceneName()))
|
|
|
+ .collect(Collectors.groupingBy(item -> item.getSceneName(), Collectors.toList()))
|
|
|
+ .forEach((key, value) -> {
|
|
|
+ SceneWaterAmount sceneWaterAmount = new SceneWaterAmount();
|
|
|
+ sceneWaterAmount.setSceneName(key);
|
|
|
+ sceneWaterAmount.setWaterAmount(BigDecimal.ZERO);
|
|
|
+ value.stream().forEach(deviceWaterDetail -> {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ monitorDataEntity.getDataValues().stream()
|
|
|
+ .filter(monitorDataValueEntity -> monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId()))
|
|
|
+ .forEach(monitorDataValueEntity ->
|
|
|
+ //累计当前压力
|
|
|
+ sceneWaterAmount.setWaterAmount(sceneWaterAmount.getWaterAmount().add(new BigDecimal(monitorDataValueEntity.getDataValue())))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sceneWaterPressureAmounts.add(sceneWaterAmount);
|
|
|
+ });
|
|
|
+
|
|
|
+ //进行压力分组
|
|
|
+ SceneWaterPressure sceneWaterPressure = new SceneWaterPressure();
|
|
|
+ SceneWaterAmount amountMax = null;
|
|
|
+ SceneWaterAmount amountMin = null;
|
|
|
+ for (SceneWaterAmount waterPressure : sceneWaterPressureAmounts) {
|
|
|
+ if (StringUtils.isNotBlank(waterPressure.getSceneName()) && waterPressure.getWaterAmount() != null) {
|
|
|
+ BigDecimal amount = waterPressure.getWaterAmount();
|
|
|
+ amountMax = amountMax == null || amount.compareTo(amountMax.getWaterAmount()) == 1 ? waterPressure : amountMax;
|
|
|
+ amountMin = amountMin == null || amount.compareTo(amountMin.getWaterAmount()) == -1 ? waterPressure : amountMin;
|
|
|
+
|
|
|
+ if (amount.compareTo(new BigDecimal(0.15)) == -1) {
|
|
|
+ sceneWaterPressure.setPressureLevel1(sceneWaterPressure.getPressureLevel1() + 1);
|
|
|
+ } else if (amount.compareTo(new BigDecimal(0.15)) != 1 && amount.compareTo(new BigDecimal(0.30)) == -1) {
|
|
|
+ sceneWaterPressure.setPressureLevel2(sceneWaterPressure.getPressureLevel2() + 1);
|
|
|
+ } else if (amount.compareTo(new BigDecimal(0.30)) != -1 && amount.compareTo(new BigDecimal(0.40)) == -1) {
|
|
|
+ sceneWaterPressure.setPressureLevel3(sceneWaterPressure.getPressureLevel3() + 1);
|
|
|
+ } else if (amount.compareTo(new BigDecimal(0.40)) != -1 && amount.compareTo(new BigDecimal(0.50)) == -1) {
|
|
|
+ sceneWaterPressure.setPressureLevel4(sceneWaterPressure.getPressureLevel4() + 1);
|
|
|
+ } else if (amount.compareTo(new BigDecimal(0.50)) != -1) {
|
|
|
+ sceneWaterPressure.setPressureLevel5(sceneWaterPressure.getPressureLevel5() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amountMax != null) {
|
|
|
+ sceneWaterPressure.setMaxPressureSceneName(amountMax.getSceneName());
|
|
|
+ sceneWaterPressure.setMaxPressureValue(amountMax.getWaterAmount());
|
|
|
+ }
|
|
|
+ if (amountMax != null) {
|
|
|
+ sceneWaterPressure.setMinPressureSceneName(amountMin.getSceneName());
|
|
|
+ sceneWaterPressure.setMinPressureValue(amountMin.getWaterAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //4压力分组
|
|
|
+ generalViewResults.setSceneWaterPressure(sceneWaterPressure);
|
|
|
+
|
|
|
+ //今日水厂制水量排行
|
|
|
+// deviceSupplyWaterDetailsForDay
|
|
|
+ List<SceneWaterAmount> sceneWaterAmounts = new ArrayList<>();
|
|
|
+ deviceSupplyWaterDetailsForDay.stream()
|
|
|
+ .filter(item -> StringUtils.isNotBlank(item.getSceneName()))
|
|
|
+ .collect(Collectors.groupingBy(item -> item.getSceneName(), Collectors.toList()))
|
|
|
+ .forEach((key, value) -> {
|
|
|
+ SceneWaterAmount sceneWaterAmount = new SceneWaterAmount();
|
|
|
+ sceneWaterAmount.setSceneName(key);
|
|
|
+ sceneWaterAmount.setWaterAmount(BigDecimal.ZERO);
|
|
|
+ value.stream().forEach(deviceWaterDetail -> {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0) {
|
|
|
+ monitorDataEntity.getDataValues().stream()
|
|
|
+ .filter(monitorDataValueEntity -> monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId()))
|
|
|
+ .forEach(monitorDataValueEntity ->
|
|
|
+ //累计当天流量
|
|
|
+ sceneWaterAmount.setWaterAmount(sceneWaterAmount.getWaterAmount().add(
|
|
|
+ new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()).add(deviceWaterDetail.getAmount())))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sceneWaterAmounts.add(sceneWaterAmount);
|
|
|
+ });
|
|
|
+ //倒序排序
|
|
|
+ sceneWaterAmounts.sort(Comparator.comparing(SceneWaterAmount::getWaterAmount).reversed());
|
|
|
+ //5水量排行
|
|
|
+ generalViewResults.setSceneWaterAmounts(sceneWaterAmounts);
|
|
|
+
|
|
|
+ //水厂制水、药耗、电耗对比曲线
|
|
|
+ List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyData(tenantId);
|
|
|
+ List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
|
|
|
+ waterSupplyDatas.stream()
|
|
|
+ .collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth() + "-" + item.getDay()))
|
|
|
+ .forEach((key, value) -> {
|
|
|
+ WaterSupplyChart waterSupplyChart = new WaterSupplyChart();
|
|
|
+ waterSupplyChart.setDate(key);
|
|
|
+ value.stream().forEach(waterSupplyData -> {
|
|
|
+ Period period = Period.between(LocalDate.of(waterSupplyData.getYear(), waterSupplyData.getMonth(), waterSupplyData.getDay()), localDate);
|
|
|
+ waterSupplyChart.setSort(period.getDays());
|
|
|
+
|
|
|
+ if (waterSupplyData.getParmType() == 3) { //供水
|
|
|
+ waterSupplyChart.setWaterData(waterSupplyData.getAmount());
|
|
|
+ } else if (waterSupplyData.getParmType() == 5) {//电耗
|
|
|
+ waterSupplyChart.setPowerData(waterSupplyData.getAmount());
|
|
|
+ } else if (waterSupplyData.getParmType() == 6) {//药耗
|
|
|
+ waterSupplyChart.setDrugData(waterSupplyData.getAmount());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ waterSupplyCharts.add(waterSupplyChart);
|
|
|
+ });
|
|
|
+ waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort));
|
|
|
+
|
|
|
+ //6曲线图
|
|
|
+ generalViewResults.setWaterSupplyCharts(waterSupplyCharts);
|
|
|
+
|
|
|
+ return generalViewResults;
|
|
|
+ }
|
|
|
|
|
|
//水厂近30天供水量
|
|
|
@Override
|