|
@@ -1,22 +1,24 @@
|
|
package com.huaxu.service.impl;
|
|
package com.huaxu.service.impl;
|
|
|
|
|
|
import com.huaxu.dao.MonitorDataReportMapper;
|
|
import com.huaxu.dao.MonitorDataReportMapper;
|
|
-import com.huaxu.dto.MonitorDataChartReportAttributeDto;
|
|
|
|
-import com.huaxu.dto.MonitorDataChartReportDeviceDto;
|
|
|
|
-import com.huaxu.dto.MonitorDataChartReportValueDto;
|
|
|
|
|
|
+import com.huaxu.dto.*;
|
|
import com.huaxu.dto.generalView.*;
|
|
import com.huaxu.dto.generalView.*;
|
|
import com.huaxu.entity.DeviceEntity;
|
|
import com.huaxu.entity.DeviceEntity;
|
|
import com.huaxu.entity.MonitorDataEntity;
|
|
import com.huaxu.entity.MonitorDataEntity;
|
|
import com.huaxu.entity.MonitorDataValueEntity;
|
|
import com.huaxu.entity.MonitorDataValueEntity;
|
|
|
|
+import com.huaxu.entity.SceneEntity;
|
|
|
|
+import com.huaxu.model.AjaxMessage;
|
|
import com.huaxu.model.LoginUser;
|
|
import com.huaxu.model.LoginUser;
|
|
-import com.huaxu.service.MonitorDataReportService;
|
|
|
|
-import com.huaxu.service.MonitorDataService;
|
|
|
|
|
|
+import com.huaxu.model.ResultStatus;
|
|
|
|
+import com.huaxu.service.*;
|
|
import com.huaxu.util.ByteArrayUtils;
|
|
import com.huaxu.util.ByteArrayUtils;
|
|
|
|
+import com.huaxu.util.OrgInfoUtil;
|
|
import com.huaxu.util.RedisUtil;
|
|
import com.huaxu.util.RedisUtil;
|
|
import com.huaxu.util.UserUtil;
|
|
import com.huaxu.util.UserUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.sound.midi.Receiver;
|
|
import javax.sound.midi.Receiver;
|
|
@@ -44,6 +46,15 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrgInfoUtil orgInfoUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SceneService sceneService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MonitorInfoService monitorInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeviceService deviceService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<MonitorDataChartReportDeviceDto> monitorDataChartReportByDay(Long sceneId, Integer year, Integer month , Integer day) {
|
|
public List<MonitorDataChartReportDeviceDto> monitorDataChartReportByDay(Long sceneId, Integer year, Integer month , Integer day) {
|
|
@@ -924,14 +935,97 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
return waterSupplyCharts;
|
|
return waterSupplyCharts;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ComUsageDto getYieldPowerUsage(Long companyOrgId) {
|
|
|
|
+ ComUsageDto sceneUsageDto = new ComUsageDto();
|
|
|
|
+ //查询公司下的场景
|
|
|
|
+ SceneEntity sceneEntity = new SceneEntity();
|
|
|
|
+ sceneEntity.setSceneTypeName("水厂");
|
|
|
|
+ List<SceneEntity> sceneEntities = sceneService.selectByTypeNameForCom(sceneEntity, companyOrgId);
|
|
|
|
+ for (SceneEntity itemScene : sceneEntities) {
|
|
|
|
+ //查询场景下的所有设备信息
|
|
|
|
+ List<DeviceDto> devices = new ArrayList<>();
|
|
|
|
+ DeviceDto deviceDto = new DeviceDto();
|
|
|
|
+ deviceDto.setSceneIds(sceneService.findByParentIdsLike(itemScene.getId()));
|
|
|
|
+ if (deviceDto.getSceneIds().size() == 0)
|
|
|
|
+ continue;
|
|
|
|
+ devices.addAll(deviceService.selectList(deviceDto));
|
|
|
|
+ //取前一天
|
|
|
|
+ LocalDateTime dateTime = LocalDateTime.now().plusDays(-1);
|
|
|
|
+ for (DeviceDto item : devices) {
|
|
|
|
+ //设备的几个参数值
|
|
|
|
+ SceneDeviceAttributeDto sceneDeviceAttributeDto = new SceneDeviceAttributeDto();
|
|
|
|
+ sceneDeviceAttributeDto.setDeviceId(item.getId());
|
|
|
|
+ sceneDeviceAttributeDto.setYear(dateTime.getYear());
|
|
|
|
+ sceneDeviceAttributeDto.setMonth(dateTime.getMonthValue());
|
|
|
|
+ sceneDeviceAttributeDto.setDay(dateTime.getDayOfMonth());
|
|
|
|
+ sceneDeviceAttributeDto.setSceneId(itemScene.getId());
|
|
|
|
+ List<SceneDeviceAttributeDto> sceneDeviceAttributeDtos = monitorInfoService.findAttributeList(sceneDeviceAttributeDto);
|
|
|
|
+ //取缓存里的数据
|
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
|
|
|
|
+ if (bytes != null && bytes.length > 0) {
|
|
|
|
+ MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
|
+ //筛选该设备相同属性的值
|
|
|
|
+ Map<Long, MonitorDataValueEntity> map = new HashMap<>();
|
|
|
|
+ //将缓存中的实时数据放到map中方便进行遍历
|
|
|
|
+ for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
|
|
|
|
+ map.put(dateValue.getAttributeId(), dateValue);
|
|
|
|
+ }
|
|
|
|
+ for (SceneDeviceAttributeDto itemAttribute : sceneDeviceAttributeDtos) {
|
|
|
|
+ Double attributeDiffValue = 0d;
|
|
|
|
+ if (!map.containsKey(itemAttribute.getAttributeId())) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (map.get(itemAttribute.getAttributeId()).getDataValue() != null && itemAttribute.getLatestValue() != null) {
|
|
|
|
+ attributeDiffValue = map.get(itemAttribute.getAttributeId()).getDataValue() - itemAttribute.getLatestValue();
|
|
|
|
+ } else if (map.get(itemAttribute.getAttributeId()).getDataValue() != null && itemAttribute.getLatestValue() == null) {
|
|
|
|
+ attributeDiffValue = map.get(itemAttribute.getAttributeId()).getDataValue();
|
|
|
|
+ }
|
|
|
|
+ switch (itemAttribute.getAttributeType()) {
|
|
|
|
+ case "3":
|
|
|
|
+ sceneUsageDto.setYieldWaterUsage(sceneUsageDto.getYieldWaterUsage() != null ? (double) Math.round((sceneUsageDto.getYieldWaterUsage() + attributeDiffValue) * 1000) / 1000 : (double) Math.round((attributeDiffValue) * 1000) / 1000);
|
|
|
|
+ break;
|
|
|
|
+ case "5":
|
|
|
|
+ sceneUsageDto.setPowerUsage(sceneUsageDto.getPowerUsage() != null ? (double) Math.round((sceneUsageDto.getPowerUsage() + attributeDiffValue) * 1000) / 1000 : (double) Math.round((attributeDiffValue) * 1000) / 1000);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (sceneUsageDto.getYieldWaterUsage() == null)
|
|
|
|
+ sceneUsageDto.setYieldWaterUsage(sceneUsageDto.getYieldWaterUsage());
|
|
|
|
+ if (sceneUsageDto.getPowerUsage() == null)
|
|
|
|
+ sceneUsageDto.setPowerUsage(sceneUsageDto.getPowerUsage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sceneUsageDto.getPowerUsage() != null && sceneUsageDto.getYieldWaterUsage() != null && sceneUsageDto.getPowerUsage() != 0) {
|
|
|
|
+ sceneUsageDto.setYieldPowerUsage((double) Math.round((sceneUsageDto.getPowerUsage() / sceneUsageDto.getYieldWaterUsage()) * 100) / 100);
|
|
|
|
+ } else {
|
|
|
|
+ sceneUsageDto.setYieldPowerUsage(0d);
|
|
|
|
+ }
|
|
|
|
+ //对数据进行单位转换 按万进行统计
|
|
|
|
+ sceneUsageDto.setYieldWaterUsage(sceneUsageDto.getYieldWaterUsage() != null ? (double) Math.round(sceneUsageDto.getYieldWaterUsage() / (float) 100) / 100 : 0);
|
|
|
|
+ return sceneUsageDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<WaterSupplyChart> waterSupplyChartsByMonth(String sceneTypeName, Integer companyOrgId) {
|
|
public List<WaterSupplyChart> waterSupplyChartsByMonth(String sceneTypeName, Integer companyOrgId) {
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
String tenantId = loginUser.getTenantId();
|
|
String tenantId = loginUser.getTenantId();
|
|
List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyDataByMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyDataByMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
List<WaterSupplyData> waterSupplyDatasForCurrentMonth = monitorDataReportMapper.getWaterSupplyDataByMonthForCurrentMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
List<WaterSupplyData> waterSupplyDatasForCurrentMonth = monitorDataReportMapper.getWaterSupplyDataByMonthForCurrentMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
- if(waterSupplyDatasForCurrentMonth.size()>0)
|
|
|
|
- waterSupplyDatas.add(waterSupplyDatasForCurrentMonth.get(0));
|
|
|
|
|
|
+ if(waterSupplyDatasForCurrentMonth.size()>0) {
|
|
|
|
+ //获取当天数据
|
|
|
|
+ ComUsageDto comUsageDto = getYieldPowerUsage(companyOrgId!=null?Long.valueOf(companyOrgId):null);
|
|
|
|
+ if(comUsageDto!=null) {
|
|
|
|
+ for (WaterSupplyData item : waterSupplyDatasForCurrentMonth) {
|
|
|
|
+ if (item.getParmType() == 3)
|
|
|
|
+ item.setAmount(item.getAmount() != null ? item.getAmount().add(BigDecimal.valueOf(comUsageDto.getYieldWaterUsage())) : item.getAmount());
|
|
|
|
+ if (item.getParmType() == 5)
|
|
|
|
+ item.setAmount(item.getAmount() != null ? item.getAmount().add(BigDecimal.valueOf(comUsageDto.getPowerUsage())) : item.getAmount());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ waterSupplyDatas.addAll(waterSupplyDatasForCurrentMonth);
|
|
|
|
+ }
|
|
List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
|
|
List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
|
|
waterSupplyDatas.stream()
|
|
waterSupplyDatas.stream()
|
|
.collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth()))
|
|
.collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth()))
|
|
@@ -1005,18 +1099,9 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
}
|
|
}
|
|
//将获取到 实时数据转换为map,方便匹配数据deviceId
|
|
//将获取到 实时数据转换为map,方便匹配数据deviceId
|
|
Map<Integer, MonitorDataEntity> MonitorDataMap = monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
|
|
Map<Integer, MonitorDataEntity> MonitorDataMap = monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
LocalDate localDate = LocalDate.now();
|
|
LocalDate localDate = LocalDate.now();
|
|
-
|
|
|
|
-// BigDecimal amountNow =BigDecimal.ZERO;
|
|
|
|
BigDecimal amountDay =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());
|
|
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) {
|
|
for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
|
|
MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
|
|
@@ -1030,34 +1115,27 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
if(searchType == null || searchType == 1){
|
|
if(searchType == null || searchType == 1){
|
|
return amountDay;
|
|
return amountDay;
|
|
}
|
|
}
|
|
-
|
|
|
|
BigDecimal amountMonth =BigDecimal.ZERO;
|
|
BigDecimal amountMonth =BigDecimal.ZERO;
|
|
//当月数据
|
|
//当月数据
|
|
BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
if (waterSupplyAmountForMonth != null) {
|
|
if (waterSupplyAmountForMonth != null) {
|
|
amountMonth = waterSupplyAmountForMonth.add(amountDay);
|
|
amountMonth = waterSupplyAmountForMonth.add(amountDay);
|
|
}
|
|
}
|
|
-
|
|
|
|
if(searchType != null && searchType == 2){
|
|
if(searchType != null && searchType == 2){
|
|
return amountMonth;
|
|
return amountMonth;
|
|
}
|
|
}
|
|
-
|
|
|
|
//当年数据
|
|
//当年数据
|
|
BigDecimal amountYear =BigDecimal.ZERO;
|
|
BigDecimal amountYear =BigDecimal.ZERO;
|
|
BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
if (waterSupplyAmountForYear != null) {
|
|
if (waterSupplyAmountForYear != null) {
|
|
amountYear = waterSupplyAmountForYear.add(amountMonth);
|
|
amountYear = waterSupplyAmountForYear.add(amountMonth);
|
|
}
|
|
}
|
|
-
|
|
|
|
if(searchType != null && searchType == 3){
|
|
if(searchType != null && searchType == 3){
|
|
return amountYear;
|
|
return amountYear;
|
|
}
|
|
}
|
|
return BigDecimal.ZERO;
|
|
return BigDecimal.ZERO;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|