8 changed files with 450 additions and 1 deletions
@ -0,0 +1,58 @@
|
||||
package com.mh.web.controller.comprehensive; |
||||
|
||||
import com.mh.common.core.controller.BaseController; |
||||
import com.mh.common.core.page.TableDataInfo; |
||||
import com.mh.system.service.ISysParamsService; |
||||
import com.mh.system.service.overview.IProOverviewService; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 项目总览 |
||||
* @date 2025-03-19 11:08:41 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/pro/overview") |
||||
public class ProOverviewController extends BaseController { |
||||
|
||||
private final ISysParamsService sysParamsService; |
||||
|
||||
private final IProOverviewService proOverviewService; |
||||
|
||||
public ProOverviewController(ISysParamsService sysParamsService, IProOverviewService proOverviewService) { |
||||
this.sysParamsService = sysParamsService; |
||||
this.proOverviewService = proOverviewService; |
||||
} |
||||
|
||||
/** |
||||
* 获取项目简介 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/introduction") |
||||
public TableDataInfo introduction() { |
||||
return getDataTable(sysParamsService.queryList()); |
||||
} |
||||
|
||||
/** |
||||
* 获取项目概况 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/profile") |
||||
public TableDataInfo profile() { |
||||
return getDataTable(proOverviewService.getProProfile()); |
||||
} |
||||
|
||||
/** |
||||
* 获取能耗分析:查询最近12个月的能耗数据 |
||||
* @return |
||||
*/ |
||||
@GetMapping("energyAnalysis") |
||||
public TableDataInfo energyAnalysis() { |
||||
return getDataTable(proOverviewService.energyAnalysis()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.mh.common.core.domain.dto; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 项目总览能耗分析 |
||||
* @date 2025-03-19 17:43:24 |
||||
*/ |
||||
@Setter |
||||
@Getter |
||||
public class OverviewEnergyDTO { |
||||
|
||||
private String name; |
||||
|
||||
private String[] data; |
||||
|
||||
private String[] timeStr; |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("name", name) |
||||
.append("data", data) |
||||
.append("timeStr", timeStr) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,86 @@
|
||||
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-19 11:43:26 |
||||
*/ |
||||
@Setter |
||||
@Getter |
||||
public class ProProfileDTO { |
||||
|
||||
/** |
||||
* 总耗电量 |
||||
*/ |
||||
private BigDecimal totalEle; |
||||
|
||||
/** |
||||
* 总冷量 |
||||
*/ |
||||
private BigDecimal totalCold; |
||||
|
||||
/** |
||||
* z总用水量 |
||||
*/ |
||||
private BigDecimal totalWater; |
||||
|
||||
/** |
||||
* 总用气量 |
||||
*/ |
||||
private BigDecimal totalGas; |
||||
|
||||
/** |
||||
* 年耗电量 |
||||
*/ |
||||
private BigDecimal yearEle; |
||||
|
||||
/** |
||||
* 总冷量 |
||||
*/ |
||||
private BigDecimal yearCold; |
||||
|
||||
/** |
||||
* 年用水量 |
||||
*/ |
||||
private BigDecimal yearWater; |
||||
|
||||
/** |
||||
* 年用气量 |
||||
*/ |
||||
private BigDecimal yearGas; |
||||
|
||||
public ProProfileDTO() { |
||||
} |
||||
|
||||
public ProProfileDTO(BigDecimal totalEle, BigDecimal totalCold, BigDecimal totalWater, BigDecimal totalGas, BigDecimal yearEle, BigDecimal yearCold, BigDecimal yearWater, BigDecimal yearGas) { |
||||
this.totalEle = totalEle.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.totalCold = totalCold.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.totalWater = totalWater.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.totalGas = totalGas.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.yearEle = yearEle.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.yearCold = yearCold.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.yearWater = yearWater.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
this.yearGas = yearGas.setScale(2, BigDecimal.ROUND_HALF_UP); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("totalEle", totalEle) |
||||
.append("totalCold", totalCold) |
||||
.append("totalWater", totalWater) |
||||
.append("totalGas", totalGas) |
||||
.append("yearEle", yearEle) |
||||
.append("yearWater", yearWater) |
||||
.append("yearGas", yearGas) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.mh.system.mapper.energy; |
||||
|
||||
import com.mh.common.core.domain.entity.ChillersEntity; |
||||
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||
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 项目总览 |
||||
* @date 2025-03-19 16:37:22 |
||||
*/ |
||||
@Mapper |
||||
public interface OverviewMapper { |
||||
|
||||
@Select("<script>" + |
||||
"select sum(calc_value) as calc_value from data_year where " + |
||||
" cur_time >= DATE_TRUNC('year', CURRENT_DATE)" + |
||||
" AND cur_time < DATE_TRUNC('year', CURRENT_DATE) + INTERVAL '1 year'" + |
||||
" <if test='deviceNums != null and deviceNums.size() > 0'>" + |
||||
" AND device_num IN " + |
||||
" <foreach collection='deviceNums' item='item' open='(' separator=',' close=')'>" + |
||||
" #{item.deviceNum} " + |
||||
" </foreach>" + |
||||
" </if>" + |
||||
"</script>") |
||||
BigDecimal queryByDeviceNum(@Param("deviceNums") List<CollectionParamsManage> deviceNums); |
||||
|
||||
@Select("<script>" + |
||||
"WITH months AS ( " + |
||||
" SELECT " + |
||||
" to_char(generate_series( " + |
||||
" date_trunc('month', CURRENT_DATE) - INTERVAL '11 months', " + |
||||
" date_trunc('month', CURRENT_DATE), " + |
||||
" '1 month' " + |
||||
" ), 'YYYY-MM') AS month " + |
||||
") " + |
||||
"SELECT " + |
||||
" m.month, " + |
||||
" COALESCE(SUM(dm.calc_value), 0) AS calc_value_sum " + |
||||
"FROM months m " + |
||||
"LEFT JOIN data_month dm " + |
||||
" ON to_char(dm.cur_time, 'YYYY-MM') = m.month " + |
||||
" <if test='deviceNums != null and deviceNums.size() > 0'>" + |
||||
" AND dm.device_num IN " + |
||||
" <foreach collection='deviceNums' item='item' open='(' separator=',' close=')'>" + |
||||
" #{item.deviceNum} " + |
||||
" </foreach>" + |
||||
" </if>" + |
||||
" AND dm.cur_time >= date_trunc('month', CURRENT_DATE) - INTERVAL '11 months' " + |
||||
"WHERE m.month <= to_char(CURRENT_DATE, 'YYYY-MM') " + |
||||
"GROUP BY m.month " + |
||||
"ORDER BY m.month; " + |
||||
"</script>") |
||||
List<ChillersEntity> energyAnalysis(@Param("deviceNums") List<CollectionParamsManage> deviceNums); |
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.mh.system.service.overview; |
||||
|
||||
import com.mh.common.core.domain.dto.OverviewEnergyDTO; |
||||
import com.mh.common.core.domain.dto.ProProfileDTO; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 项目总览 |
||||
* @date 2025-03-19 11:40:47 |
||||
*/ |
||||
public interface IProOverviewService { |
||||
|
||||
List<ProProfileDTO> getProProfile(); |
||||
|
||||
List<OverviewEnergyDTO> energyAnalysis(); |
||||
} |
@ -0,0 +1,166 @@
|
||||
package com.mh.system.service.overview.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.mh.common.core.domain.dto.OverviewEnergyDTO; |
||||
import com.mh.common.core.domain.dto.ProProfileDTO; |
||||
import com.mh.common.core.domain.entity.ChillersEntity; |
||||
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||
import com.mh.common.core.domain.entity.SysDictData; |
||||
import com.mh.system.mapper.SysDictDataMapper; |
||||
import com.mh.system.mapper.device.CollectionParamsManageMapper; |
||||
import com.mh.system.mapper.energy.OverviewMapper; |
||||
import com.mh.system.service.overview.IProOverviewService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 项目总览服务实现类 |
||||
* @date 2025-03-19 15:44:31 |
||||
*/ |
||||
@Service |
||||
public class ProOverviewServiceImpl implements IProOverviewService { |
||||
|
||||
private final CollectionParamsManageMapper collectionParamsManageMapper; |
||||
|
||||
private final SysDictDataMapper sysDictDataMapper; |
||||
|
||||
private final OverviewMapper overviewMapper; |
||||
|
||||
public ProOverviewServiceImpl(CollectionParamsManageMapper collectionParamsManageMapper, SysDictDataMapper sysDictDataMapper, OverviewMapper overviewMapper) { |
||||
this.collectionParamsManageMapper = collectionParamsManageMapper; |
||||
this.sysDictDataMapper = sysDictDataMapper; |
||||
this.overviewMapper = overviewMapper; |
||||
} |
||||
|
||||
@Override |
||||
public List<OverviewEnergyDTO> energyAnalysis() { |
||||
List<ChillersEntity> dataList = overviewMapper.energyAnalysis(null); |
||||
return List.of(); |
||||
} |
||||
|
||||
@Override |
||||
public List<ProProfileDTO> getProProfile() { |
||||
// 请求各个系统中有没有对应的总表,如果有直接查询总表,没有就是各个分表之和
|
||||
List<SysDictData> sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type"); |
||||
// 查询采集参数是这几个的:
|
||||
// 耗电量 16
|
||||
// 产冷量 17
|
||||
// 用水量 18
|
||||
// 用气量 19
|
||||
BigDecimal totalEle = new BigDecimal(0); |
||||
BigDecimal totalCold = new BigDecimal(0); |
||||
BigDecimal totalWater = new BigDecimal(0); |
||||
BigDecimal totalGas = new BigDecimal(0); |
||||
|
||||
BigDecimal yearEle = new BigDecimal(0); |
||||
BigDecimal yearCold = new BigDecimal(0); |
||||
BigDecimal yearWater = new BigDecimal(0); |
||||
BigDecimal yearGas = new BigDecimal(0); |
||||
|
||||
for (SysDictData sysDictData : sysTypeData) { |
||||
String sysType = sysDictData.getDictValue(); |
||||
String[] paramTypes = {"16", "17", "18", "19"}; |
||||
for (String paramType : paramTypes) { |
||||
QueryWrapper<CollectionParamsManage> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("param_type", paramType); |
||||
queryWrapper.eq("system_type", sysType); |
||||
queryWrapper.eq("grade", 40); |
||||
queryWrapper.eq("mt_is_sum", 0); |
||||
Long count = collectionParamsManageMapper.selectCount(queryWrapper); |
||||
if (count > 0) { |
||||
// 查询总表
|
||||
getTotalData(paramType, queryWrapper, totalEle, |
||||
totalCold, |
||||
totalWater, |
||||
totalGas, |
||||
yearEle, |
||||
yearCold, |
||||
yearWater, |
||||
yearGas); |
||||
} else { |
||||
// 查询分表综合
|
||||
queryWrapper.eq("mt_is_sum", 1); |
||||
// 查询分表总和
|
||||
getTotalData(paramType, queryWrapper, |
||||
totalEle, |
||||
totalCold, |
||||
totalWater, |
||||
totalGas, |
||||
yearEle, |
||||
yearCold, |
||||
yearWater, |
||||
yearGas); |
||||
} |
||||
} |
||||
|
||||
} |
||||
ProProfileDTO proProfileDTO = new ProProfileDTO(totalEle, totalCold, totalWater, totalGas, yearEle, yearCold, yearWater, yearGas); |
||||
List<ProProfileDTO> proProfileDTOS = new ArrayList<>(); |
||||
proProfileDTOS.add(proProfileDTO); |
||||
return proProfileDTOS; |
||||
} |
||||
|
||||
private void getTotalData(String paramType, |
||||
QueryWrapper<CollectionParamsManage> queryWrapper, |
||||
BigDecimal totalEle, |
||||
BigDecimal totalCold, |
||||
BigDecimal totalWater, |
||||
BigDecimal totalGas, |
||||
BigDecimal yearEle, |
||||
BigDecimal yearCold, |
||||
BigDecimal yearWater, |
||||
BigDecimal yearGas) { |
||||
List<CollectionParamsManage> collectionParamsManages = collectionParamsManageMapper.selectList(queryWrapper); |
||||
// 遍历计算得出总用电量
|
||||
collectionParamsManages.forEach(collectionParamsManage -> { |
||||
// TODO
|
||||
switch (Integer.parseInt(paramType)) { |
||||
case 16: |
||||
totalEle.add((collectionParamsManage.getCurValue().subtract(collectionParamsManage.getMtInitValue())) |
||||
.multiply(new BigDecimal(collectionParamsManage.getMtRatio()))); |
||||
break; |
||||
case 17: |
||||
totalCold.add((collectionParamsManage.getCurValue().subtract(collectionParamsManage.getMtInitValue())) |
||||
.multiply(new BigDecimal(collectionParamsManage.getMtRatio()))); |
||||
break; |
||||
case 18: |
||||
totalWater.add((collectionParamsManage.getCurValue().subtract(collectionParamsManage.getMtInitValue())) |
||||
.multiply(new BigDecimal(collectionParamsManage.getMtRatio()))); |
||||
break; |
||||
case 19: |
||||
totalGas.add((collectionParamsManage.getCurValue().subtract(collectionParamsManage.getMtInitValue())) |
||||
.multiply(new BigDecimal(collectionParamsManage.getMtRatio()))); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
}); |
||||
// 计算得出今年的各个参数用量
|
||||
BigDecimal yearValue = overviewMapper.queryByDeviceNum(collectionParamsManages); |
||||
switch (Integer.parseInt(paramType)) { |
||||
case 16: |
||||
yearEle = yearValue; |
||||
break; |
||||
case 17: |
||||
yearCold = yearValue; |
||||
break; |
||||
case 18: |
||||
yearWater = yearValue; |
||||
break; |
||||
case 19: |
||||
yearGas = yearValue; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue