|
@@ -559,9 +559,19 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
List<DeviceWaterSupply> deviceWaterSupplies = monitorDataReportMapper.getDeviceWaterFor30Day(tenantId,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
|
|
|
LocalDate localDate = LocalDate.now();
|
|
|
+ BigDecimal amountCountDay = getAmountCount(null,null,"水厂",3,1);
|
|
|
+ DeviceWaterSupply deviceWaterSupplyDay = new DeviceWaterSupply();
|
|
|
+ deviceWaterSupplyDay.setOrderNo( 1);
|
|
|
+ deviceWaterSupplyDay.setAmount(amountCountDay != null?amountCountDay:BigDecimal.ZERO);
|
|
|
+ deviceWaterSupplyDay.setYear(localDate.getYear());
|
|
|
+ deviceWaterSupplyDay.setMonth(localDate.getMonthValue());
|
|
|
+ deviceWaterSupplyDay.setDay(localDate.getDayOfMonth());
|
|
|
+ deviceWaterSupplyDay.setDate(localDate);
|
|
|
+ deviceWaterSupplies.add(0, deviceWaterSupplyDay);
|
|
|
+
|
|
|
|
|
|
for (int i = 0; i < 30; i++) {
|
|
|
- LocalDate newLocalDate = localDate.plusDays(-i - 1);
|
|
|
+ LocalDate newLocalDate = localDate.plusDays(-i);
|
|
|
if (i == deviceWaterSupplies.size()
|
|
|
|| !newLocalDate.isEqual(LocalDate.of(deviceWaterSupplies.get(i).getYear(),
|
|
|
deviceWaterSupplies.get(i).getMonth(),
|
|
@@ -589,6 +599,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
public DeviceWaterAmount deviceWaterAmount() {
|
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
String tenantId = loginUser.getTenantId();
|
|
|
+
|
|
|
Map<Integer, MonitorDataEntity> MonitorDataMap = getIntegerMonitorDataEntityMap(loginUser);
|
|
|
|
|
|
LocalDate localDate = LocalDate.now();
|
|
@@ -625,8 +636,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
}
|
|
|
|
|
|
//3供水 4取水
|
|
|
- List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
- List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
|
|
|
//水厂获取实时流量并计算出当天流量
|
|
|
for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
|
|
@@ -656,8 +667,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
- BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水厂", 3, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,null,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(null,null,"水厂", 3, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
if (waterSupplyAmountForMonth == null) {
|
|
|
waterSupplyAmountForMonth = BigDecimal.ZERO;
|
|
|
}
|
|
@@ -678,8 +689,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
- BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水源", 4, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,null,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(null,null,"水源", 4, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
if (waterIntakeAmountForMonth == null) {
|
|
|
waterIntakeAmountForMonth = BigDecimal.ZERO;
|
|
|
}
|
|
@@ -842,7 +853,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
Map<Integer, MonitorDataEntity> MonitorDataMap = getIntegerMonitorDataEntityMap(loginUser);
|
|
|
|
|
|
LocalDate localDate = LocalDate.now();
|
|
|
- List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
|
|
|
List<SceneWaterAmount> sceneWaterAmounts = new ArrayList<>();
|
|
|
deviceSupplyWaterDetailsForDay.stream()
|
|
@@ -950,7 +961,6 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
|
|
|
//查询设备编码
|
|
|
List<String> deviceCodes = monitorDataReportMapper.selectDeviceCode(loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
- deviceCodes.add("300220070692");
|
|
|
//根据编码获取redis中的实时数据
|
|
|
List<MonitorDataEntity> monitorDataEntities = new ArrayList<>();
|
|
|
for (String deviceCode : deviceCodes) {
|
|
@@ -964,4 +974,86 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
return monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param companyOrgId 公司id
|
|
|
+ * @param sceneId 场景类型
|
|
|
+ * @param sceneTypeName 场景类型
|
|
|
+ * @param parmType 标记值
|
|
|
+ * @param searchType 查询类型:1日 2月 3年
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BigDecimal getAmountCount(Integer companyOrgId, Integer sceneId, String sceneTypeName, Integer parmType,Integer searchType){
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ String tenantId = loginUser.getTenantId();
|
|
|
+
|
|
|
+
|
|
|
+ //查询设备编码
|
|
|
+ List<String> deviceCodes = monitorDataReportMapper.selectDeviceCodeByConditions(companyOrgId,sceneId,sceneTypeName, loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ //根据编码获取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();
|
|
|
+
|
|
|
+// BigDecimal amountNow =BigDecimal.ZERO;
|
|
|
+ BigDecimal amountDay =BigDecimal.ZERO;
|
|
|
+
|
|
|
+
|
|
|
+ //
|
|
|
+ List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+
|
|
|
+ //获取实时数据并计算出当天数据
|
|
|
+ for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
|
|
|
+ MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
|
+ if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0
|
|
|
+ && deviceWaterDetail != null && deviceWaterDetail.getLatestValue() != null) {
|
|
|
+ for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
|
|
|
+ if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
|
|
|
+ //累计当天数据
|
|
|
+ amountDay = amountDay.add(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(searchType == null || searchType == 1){
|
|
|
+ return amountDay;
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amountMonth =BigDecimal.ZERO;
|
|
|
+ //当月数据
|
|
|
+ BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ if (waterSupplyAmountForMonth != null) {
|
|
|
+ amountMonth = waterSupplyAmountForMonth.add(amountDay);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(searchType != null && searchType == 2){
|
|
|
+ return amountMonth;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当年数据
|
|
|
+ BigDecimal amountYear =BigDecimal.ZERO;
|
|
|
+ BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
+ if (waterSupplyAmountForYear != null) {
|
|
|
+ amountYear = waterSupplyAmountForYear.add(amountMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(searchType != null && searchType == 3){
|
|
|
+ return amountYear;
|
|
|
+ }
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|