7 changed files with 561 additions and 9 deletions
@ -0,0 +1,58 @@ |
|||||||
|
package com.mh.web.controller.comprehensive; |
||||||
|
|
||||||
|
import com.mh.common.core.controller.BaseController; |
||||||
|
import com.mh.common.core.domain.AjaxResult; |
||||||
|
import com.mh.common.core.domain.vo.EnergyConsumptionVO; |
||||||
|
import com.mh.common.core.page.TableDataInfo; |
||||||
|
import com.mh.common.utils.DateUtils; |
||||||
|
import com.mh.system.service.overview.IBigScreenService; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 大屏接口分析记录 |
||||||
|
* @date 2025-03-21 11:43:11 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/bigScreen") |
||||||
|
public class BigScreenController extends BaseController { |
||||||
|
|
||||||
|
private final IBigScreenService bigScreenService; |
||||||
|
|
||||||
|
public BigScreenController(IBigScreenService bigScreenService) { |
||||||
|
this.bigScreenService = bigScreenService; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取能耗总览和基本信息数据内容 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping("/overview") |
||||||
|
public TableDataInfo overview(@RequestBody EnergyConsumptionVO vo){ |
||||||
|
DateUtils.energyDateChange(vo); |
||||||
|
return getDataTable(bigScreenService.overview(vo)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取子系统能耗 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping("/subSystem") |
||||||
|
public TableDataInfo subSystem(@RequestBody EnergyConsumptionVO vo){ |
||||||
|
DateUtils.energyDateChange(vo); |
||||||
|
return getDataTable(bigScreenService.subSystem(vo)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取所有系统用电趋势 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping("/systemTrend") |
||||||
|
public TableDataInfo systemTrend(@RequestBody EnergyConsumptionVO vo){ |
||||||
|
DateUtils.energyDateChange(vo); |
||||||
|
return getDataTable(bigScreenService.systemTrend(vo)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,154 @@ |
|||||||
|
package com.mh.common.core.domain.dto; |
||||||
|
|
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 能耗总览和基本信息 |
||||||
|
* @date 2025-03-21 14:06:49 |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
public class BigScreenOverviewAndBasicDTO { |
||||||
|
|
||||||
|
/** |
||||||
|
* 总用电量 |
||||||
|
*/ |
||||||
|
private BigDecimal totalEle; |
||||||
|
|
||||||
|
/** |
||||||
|
* 总用水量 |
||||||
|
*/ |
||||||
|
private BigDecimal totalWater; |
||||||
|
|
||||||
|
/** |
||||||
|
* 总冷量 |
||||||
|
*/ |
||||||
|
private BigDecimal totalCold; |
||||||
|
|
||||||
|
/** |
||||||
|
* 总气量 |
||||||
|
*/ |
||||||
|
private BigDecimal totalGas; |
||||||
|
|
||||||
|
/** |
||||||
|
* 建筑面积 |
||||||
|
*/ |
||||||
|
private BigDecimal buildingArea; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用电面积单耗 |
||||||
|
*/ |
||||||
|
private BigDecimal eleUnitArea; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用水面积单耗 |
||||||
|
*/ |
||||||
|
private BigDecimal waterUnitArea; |
||||||
|
|
||||||
|
/** |
||||||
|
* 冷量面积单耗 |
||||||
|
*/ |
||||||
|
private BigDecimal coldUnitArea; |
||||||
|
|
||||||
|
/** |
||||||
|
* 气面积单耗 |
||||||
|
*/ |
||||||
|
private BigDecimal gasUnitArea; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用电标准煤 |
||||||
|
*/ |
||||||
|
private BigDecimal eleStandardCoal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用水标准煤 |
||||||
|
*/ |
||||||
|
private BigDecimal waterStandardCoal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 冷量标准煤 |
||||||
|
*/ |
||||||
|
private BigDecimal coldStandardCoal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 气标准煤 |
||||||
|
*/ |
||||||
|
private BigDecimal gasStandardCoal; |
||||||
|
|
||||||
|
public void setTotalEle(BigDecimal totalEle) { |
||||||
|
this.totalEle = totalEle.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTotalWater(BigDecimal totalWater) { |
||||||
|
this.totalWater = totalWater.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTotalCold(BigDecimal totalCold) { |
||||||
|
this.totalCold = totalCold.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTotalGas(BigDecimal totalGas) { |
||||||
|
this.totalGas = totalGas.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setBuildingArea(BigDecimal buildingArea) { |
||||||
|
this.buildingArea = buildingArea.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setEleUnitArea(BigDecimal eleUnitArea) { |
||||||
|
this.eleUnitArea = eleUnitArea.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setWaterUnitArea(BigDecimal waterUnitArea) { |
||||||
|
this.waterUnitArea = waterUnitArea.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setColdUnitArea(BigDecimal coldUnitArea) { |
||||||
|
this.coldUnitArea = coldUnitArea.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setGasUnitArea(BigDecimal gasUnitArea) { |
||||||
|
this.gasUnitArea = gasUnitArea.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setEleStandardCoal(BigDecimal eleStandardCoal) { |
||||||
|
this.eleStandardCoal = eleStandardCoal.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setWaterStandardCoal(BigDecimal waterStandardCoal) { |
||||||
|
this.waterStandardCoal = waterStandardCoal.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setColdStandardCoal(BigDecimal coldStandardCoal) { |
||||||
|
this.coldStandardCoal = coldStandardCoal.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setGasStandardCoal(BigDecimal gasStandardCoal) { |
||||||
|
this.gasStandardCoal = gasStandardCoal.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return new ToStringBuilder(this) |
||||||
|
.append("totalEle", totalEle) |
||||||
|
.append("totalWater", totalWater) |
||||||
|
.append("totalCold", totalCold) |
||||||
|
.append("totalGas", totalGas) |
||||||
|
.append("buildingArea", buildingArea) |
||||||
|
.append("eleUnitArea", eleUnitArea) |
||||||
|
.append("waterUnitArea", waterUnitArea) |
||||||
|
.append("coldUnitArea", coldUnitArea) |
||||||
|
.append("gasUnitArea", gasUnitArea) |
||||||
|
.append("eleStandardCoal", eleStandardCoal) |
||||||
|
.append("waterStandardCoal", waterStandardCoal) |
||||||
|
.append("coldStandardCoal", coldStandardCoal) |
||||||
|
.append("gasStandardCoal", gasStandardCoal) |
||||||
|
.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,72 @@ |
|||||||
|
package com.mh.system.mapper.energy; |
||||||
|
|
||||||
|
import com.mh.common.core.domain.entity.DataMonth; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.apache.ibatis.annotations.Select; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 大屏sql查询 |
||||||
|
* @date 2025-03-21 14:46:18 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface BigScreenMapper { |
||||||
|
|
||||||
|
@Select("<script>" + |
||||||
|
"select coalesce(sum(dm.calc_value), 0) from ${tableName} dm " + |
||||||
|
"where exists( " + |
||||||
|
"select " + |
||||||
|
" 1 " + |
||||||
|
"from " + |
||||||
|
" collection_params_manage cpm " + |
||||||
|
"where " + |
||||||
|
" cpm.param_type = #{paramType} " + |
||||||
|
" and cpm.grade = #{grade} " + |
||||||
|
" and cpm.mt_is_sum = #{mtIsSum} " + |
||||||
|
" and cpm.mt_num = dm.device_num " + |
||||||
|
"<if test='systemType != null and systemType != \"\"'>" + |
||||||
|
" and cpm.system_type = #{systemType} " + |
||||||
|
"</if>" + |
||||||
|
" ) " + |
||||||
|
" and dm.cur_time between #{startTime}::timestamp and #{endTime}::timestamp " + |
||||||
|
"</script>") |
||||||
|
BigDecimal selectOverviewData(@Param("tableName") String tableName, |
||||||
|
@Param("paramType") String paramType, |
||||||
|
@Param("startTime") String startTime, |
||||||
|
@Param("endTime") String endTime, |
||||||
|
@Param("mtIsSum") int mtIsSum, |
||||||
|
@Param("grade") int grade, |
||||||
|
@Param("systemType") String systemType); |
||||||
|
|
||||||
|
@Select("<script>" + |
||||||
|
"select * from ${tableName} dm " + |
||||||
|
"where exists( " + |
||||||
|
"select " + |
||||||
|
" 1 " + |
||||||
|
"from " + |
||||||
|
" collection_params_manage cpm " + |
||||||
|
"where " + |
||||||
|
" cpm.param_type = #{paramType} " + |
||||||
|
" and cpm.grade = #{grade} " + |
||||||
|
" and cpm.mt_is_sum = #{mtIsSum} " + |
||||||
|
" and cpm.mt_num = dm.device_num " + |
||||||
|
"<if test='systemType != null and systemType != \"\"'>" + |
||||||
|
" and cpm.system_type = #{systemType} " + |
||||||
|
"</if>" + |
||||||
|
" ) " + |
||||||
|
" and dm.cur_time between #{startTime}::timestamp and #{endTime}::timestamp " + |
||||||
|
"</script>") |
||||||
|
List<DataMonth> selectDataByRangeTime(@Param("tableName") String tableName, |
||||||
|
@Param("paramType") String paramType, |
||||||
|
@Param("startTime") String startTime, |
||||||
|
@Param("endTime") String endTime, |
||||||
|
@Param("mtIsSum") int mtIsSum, |
||||||
|
@Param("grade") int grade, |
||||||
|
@Param("systemType") String systemType); |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
package com.mh.system.service.overview; |
||||||
|
|
||||||
|
import com.mh.common.core.domain.vo.EnergyConsumptionVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 大屏相关服务类 |
||||||
|
* @date 2025-03-21 11:46:47 |
||||||
|
*/ |
||||||
|
public interface IBigScreenService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取能耗总览数据 |
||||||
|
* @param vo |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
List<?> overview(EnergyConsumptionVO vo); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取子系统能耗数据 |
||||||
|
* @param vo |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
List<?> subSystem(EnergyConsumptionVO vo); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取系统能耗趋势 |
||||||
|
* @param vo |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
List<?> systemTrend(EnergyConsumptionVO vo); |
||||||
|
} |
@ -0,0 +1,232 @@ |
|||||||
|
package com.mh.system.service.overview.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.mh.common.core.domain.ColumnFilter; |
||||||
|
import com.mh.common.core.domain.dto.BigScreenOverviewAndBasicDTO; |
||||||
|
import com.mh.common.core.domain.dto.OverviewEnergyDTO; |
||||||
|
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||||
|
import com.mh.common.core.domain.entity.DataMonth; |
||||||
|
import com.mh.common.core.domain.entity.SysParams; |
||||||
|
import com.mh.common.core.domain.vo.EnergyConsumptionVO; |
||||||
|
import com.mh.common.utils.DateUtils; |
||||||
|
import com.mh.system.mapper.SysParamsMapper; |
||||||
|
import com.mh.system.mapper.device.CollectionParamsManageMapper; |
||||||
|
import com.mh.system.mapper.energy.BigScreenMapper; |
||||||
|
import com.mh.system.service.overview.IBigScreenService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.*; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 大屏实现类 |
||||||
|
* @date 2025-03-21 11:47:12 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class BigScreenServiceImpl implements IBigScreenService { |
||||||
|
|
||||||
|
private final CollectionParamsManageMapper collectionParamsManageMapper; |
||||||
|
|
||||||
|
private final BigScreenMapper bigScreenMapper; |
||||||
|
|
||||||
|
private final SysParamsMapper sysParamsMapper; |
||||||
|
|
||||||
|
public BigScreenServiceImpl(CollectionParamsManageMapper collectionParamsManageMapper, BigScreenMapper bigScreenMapper, SysParamsMapper sysParamsMapper) { |
||||||
|
this.collectionParamsManageMapper = collectionParamsManageMapper; |
||||||
|
this.bigScreenMapper = bigScreenMapper; |
||||||
|
this.sysParamsMapper = sysParamsMapper; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<?> overview(EnergyConsumptionVO vo) { |
||||||
|
// 判断时间类型
|
||||||
|
String tableName = getTableName(vo); |
||||||
|
// 查询总表的数据采集参数
|
||||||
|
String[] paramTypes = {"16", "17", "18", "19"}; |
||||||
|
BigScreenOverviewAndBasicDTO bigScreenOverviewAndBasicDTO = new BigScreenOverviewAndBasicDTO(); |
||||||
|
for (String paramType : paramTypes) { |
||||||
|
int mtIsSum = queryCollectionParams(paramType, 40); |
||||||
|
BigDecimal useValue = bigScreenMapper.selectOverviewData(tableName, paramType, vo.getStartTime(), vo.getEndTime(), mtIsSum, 40, null); |
||||||
|
switch (paramType) { |
||||||
|
case "16": |
||||||
|
bigScreenOverviewAndBasicDTO.setTotalEle(useValue); |
||||||
|
break; |
||||||
|
case "17": |
||||||
|
bigScreenOverviewAndBasicDTO.setTotalCold(useValue); |
||||||
|
break; |
||||||
|
case "18": |
||||||
|
bigScreenOverviewAndBasicDTO.setTotalWater(useValue); |
||||||
|
break; |
||||||
|
case "19": |
||||||
|
bigScreenOverviewAndBasicDTO.setTotalGas(useValue); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
// 换算标准煤
|
||||||
|
// 用电转换,公式:标准煤量(kgce)= 用电量(kWh)×0.1229
|
||||||
|
bigScreenOverviewAndBasicDTO.setEleStandardCoal(bigScreenOverviewAndBasicDTO.getTotalEle().multiply(new BigDecimal("0.1229"))); |
||||||
|
// 用冷转换,公式:标准煤量(kgce)= 3.6*用冷量(kW)➗29.3076
|
||||||
|
bigScreenOverviewAndBasicDTO.setColdStandardCoal(bigScreenOverviewAndBasicDTO.getTotalCold().multiply(new BigDecimal("3.6")).divide(new BigDecimal("29.3076"))); |
||||||
|
// 用水转换,公式:标准煤量(kgce)=用水量(吨)×0.0857
|
||||||
|
bigScreenOverviewAndBasicDTO.setWaterStandardCoal(bigScreenOverviewAndBasicDTO.getTotalWater().multiply(new BigDecimal("0.0857"))); |
||||||
|
// 用气转换,公式:标准煤量(kgce)=用蒸汽量(吨)×0.0948
|
||||||
|
bigScreenOverviewAndBasicDTO.setGasStandardCoal(bigScreenOverviewAndBasicDTO.getTotalGas().multiply(new BigDecimal("0.0948"))); |
||||||
|
// 获取建筑面积
|
||||||
|
List<SysParams> sysParams = sysParamsMapper.selectSysParamsList(); |
||||||
|
if (!sysParams.isEmpty()) { |
||||||
|
bigScreenOverviewAndBasicDTO.setBuildingArea(new BigDecimal(sysParams.get(0).getBuildingArea())); |
||||||
|
// 计算单位面积能耗
|
||||||
|
// 用电转换,公式:单位面积能耗(kWh/m2)=用电量(kWh)➗建筑面积(m2)
|
||||||
|
bigScreenOverviewAndBasicDTO.setEleUnitArea(bigScreenOverviewAndBasicDTO.getTotalEle().divide(bigScreenOverviewAndBasicDTO.getBuildingArea())); |
||||||
|
// 用冷转换,公式:单位面积能耗(kWh/m2)=用冷量(kW)➗建筑面积(m2)
|
||||||
|
bigScreenOverviewAndBasicDTO.setColdUnitArea(bigScreenOverviewAndBasicDTO.getTotalCold().divide(bigScreenOverviewAndBasicDTO.getBuildingArea())); |
||||||
|
// 用水转换,公式:单位面积能耗(kWh/m2)=用水量(吨)➗建筑面积(m2)
|
||||||
|
bigScreenOverviewAndBasicDTO.setWaterUnitArea(bigScreenOverviewAndBasicDTO.getTotalWater().divide(bigScreenOverviewAndBasicDTO.getBuildingArea())); |
||||||
|
// 用气转换,公式:单位面积能耗(kWh/m2)=用蒸汽量(吨)➗建筑面积(m2)
|
||||||
|
bigScreenOverviewAndBasicDTO.setGasUnitArea(bigScreenOverviewAndBasicDTO.getTotalGas().divide(bigScreenOverviewAndBasicDTO.getBuildingArea())); |
||||||
|
} |
||||||
|
return List.of(bigScreenOverviewAndBasicDTO); |
||||||
|
} |
||||||
|
|
||||||
|
private int queryCollectionParams(String paramType, int grade) { |
||||||
|
QueryWrapper<CollectionParamsManage> queryWrapper = new QueryWrapper<>(); |
||||||
|
queryWrapper.eq("param_type", paramType) |
||||||
|
.eq("grade", grade); |
||||||
|
|
||||||
|
// 先查询总表
|
||||||
|
queryWrapper.eq("mt_is_sum", 0); |
||||||
|
Long count = collectionParamsManageMapper.selectCount(queryWrapper); |
||||||
|
if (count > 0) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
// 查询分表
|
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<?> subSystem(EnergyConsumptionVO vo) { |
||||||
|
// 判断时间类型
|
||||||
|
String tableName = getTableName(vo); |
||||||
|
// 查询总表的数据采集参数
|
||||||
|
String[] paramTypes = {"16", "17"}; |
||||||
|
if (vo.getSystemType().equals("1")) { |
||||||
|
paramTypes = new String[]{"16", "18"}; |
||||||
|
} |
||||||
|
HashMap<String, BigDecimal> mapData = new HashMap<>(); |
||||||
|
for (String paramType : paramTypes) { |
||||||
|
int mtIsSum = queryCollectionParams(paramType, 40); |
||||||
|
BigDecimal useValue = bigScreenMapper.selectOverviewData(tableName, paramType, vo.getStartTime(), vo.getEndTime(), mtIsSum, 40, vo.getSystemType()); |
||||||
|
switch (paramType) { |
||||||
|
case "16": |
||||||
|
mapData.put("totalEle", useValue); |
||||||
|
break; |
||||||
|
case "17": |
||||||
|
mapData.put("totalCold", useValue); |
||||||
|
break; |
||||||
|
case "18": |
||||||
|
mapData.put("totalWater", useValue); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
// 判断冷量为0或者电量为0,直接赋值0.00
|
||||||
|
if (vo.getSystemType().equals("0")) { |
||||||
|
if (mapData.get("totalCold").compareTo(BigDecimal.ZERO) == 0 || mapData.get("totalEle").compareTo(BigDecimal.ZERO) == 0) { |
||||||
|
mapData.put("eer", BigDecimal.ZERO); |
||||||
|
} else { |
||||||
|
mapData.put("eer", mapData.get("totalCold").divide(mapData.get("totalEle"), 2, BigDecimal.ROUND_HALF_UP)); |
||||||
|
} |
||||||
|
} else if (vo.getSystemType().equals("1")) { |
||||||
|
if (mapData.get("totalWater").compareTo(BigDecimal.ZERO) == 0 || mapData.get("totalEle").compareTo(BigDecimal.ZERO) == 0) { |
||||||
|
mapData.put("eer", BigDecimal.ZERO); |
||||||
|
} else { |
||||||
|
mapData.put("eer", mapData.get("totalEle").divide(mapData.get("totalWater"), 2, BigDecimal.ROUND_HALF_UP)); |
||||||
|
} |
||||||
|
} |
||||||
|
return List.of(mapData); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getTableName(EnergyConsumptionVO vo) { |
||||||
|
String tableName = "data_min" + vo.getStartTime().substring(0, 4); |
||||||
|
switch (vo.getTimeType()) { |
||||||
|
case "year": |
||||||
|
tableName = "data_year"; |
||||||
|
break; |
||||||
|
case "month": |
||||||
|
tableName = "data_month"; |
||||||
|
break; |
||||||
|
case "day": |
||||||
|
tableName = "data_min" + vo.getStartTime().substring(0, 4); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
return tableName; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<?> systemTrend(EnergyConsumptionVO vo) { |
||||||
|
String tableName = "data_hour" + vo.getStartTime().substring(0, 4); |
||||||
|
String dateFormat = "yyyy-MM-dd HH"; |
||||||
|
switch (vo.getTimeType()) { |
||||||
|
case "year": |
||||||
|
tableName = "data_month"; |
||||||
|
dateFormat = "yyyy-MM"; |
||||||
|
break; |
||||||
|
case "month": |
||||||
|
tableName = "data_day"; |
||||||
|
dateFormat = "yyyy-MM-dd"; |
||||||
|
break; |
||||||
|
case "day": |
||||||
|
tableName = "data_hour" + vo.getStartTime().substring(0, 4); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
String paramType = "16"; |
||||||
|
int mtIsSum = queryCollectionParams(paramType, 40); |
||||||
|
List<DataMonth> dataList = bigScreenMapper.selectDataByRangeTime(tableName, paramType, vo.getStartTime(), vo.getEndTime(), mtIsSum, 40, null); |
||||||
|
List<OverviewEnergyDTO> result = new ArrayList<>(); |
||||||
|
OverviewEnergyDTO ele = new OverviewEnergyDTO(); |
||||||
|
if (dataList == null || dataList.isEmpty()) { |
||||||
|
return List.of(result); |
||||||
|
} |
||||||
|
// dataList使用stream流根据时间分组排序,dataMonth.calcValue求和,并根据时间升序排序
|
||||||
|
String finalDateFormat = dateFormat; |
||||||
|
Map<String, List<DataMonth>> groupedData = dataList.stream() |
||||||
|
.collect(Collectors.groupingBy(val -> DateUtils.dateToString(val.getCurTime(), finalDateFormat))); |
||||||
|
// 根据时间分组,求和取总和,再根据时间升序排序
|
||||||
|
// 使用LinkedHashMap保持时间顺序
|
||||||
|
LinkedHashMap<String, Double> eleMap = dataList.stream() |
||||||
|
.sorted(Comparator.comparing(val->DateUtils.dateToString(val.getCurTime(), finalDateFormat))) // 按时间字段排序
|
||||||
|
.collect(Collectors.groupingBy( |
||||||
|
val->DateUtils.dateToString(val.getCurTime(), finalDateFormat), |
||||||
|
LinkedHashMap::new, |
||||||
|
Collectors.summingDouble(value -> |
||||||
|
value.getCalcValue().doubleValue()) |
||||||
|
)); |
||||||
|
|
||||||
|
// 提取时间序列和数值序列
|
||||||
|
String[] timeArray = eleMap.keySet().toArray(new String[0]); |
||||||
|
String[] valueArray = eleMap.values().stream() |
||||||
|
.map(d -> String.format("%.2f", d)) // 保留两位小数
|
||||||
|
.toArray(String[]::new); |
||||||
|
|
||||||
|
// 设置到对象中
|
||||||
|
ele.setName("耗电趋势"); |
||||||
|
ele.setUnit("kwh"); |
||||||
|
ele.setTimeStr(timeArray); |
||||||
|
ele.setData(valueArray); |
||||||
|
result.add(ele); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue