diff --git a/os-ems/src/main/java/com/os/ems/report/controller/EmsReportController.java b/os-ems/src/main/java/com/os/ems/report/controller/EmsReportController.java index 9ae33b2..802a5f3 100644 --- a/os-ems/src/main/java/com/os/ems/report/controller/EmsReportController.java +++ b/os-ems/src/main/java/com/os/ems/report/controller/EmsReportController.java @@ -19,7 +19,7 @@ import java.util.Map; /** - * import java.util.List;Controller + * 能源报表Controller * * @author Yinq * @date 2024-05-22 @@ -75,4 +75,17 @@ public class EmsReportController extends BaseController { util.exportExcel(response, list, "峰平谷耗量报表" ); } + /** + * 能源预览接口 + * @param hashMap + * @return + */ + @GetMapping("/energyPreviewReportList") + @ResponseBody + public AjaxResult energyPreviewReportList(@RequestParam(required = false) Map hashMap) { + List> list = emsReportService.energyPreviewReportList(hashMap); + return success(list); + } + + } diff --git a/os-ems/src/main/java/com/os/ems/report/mapper/EmsReportMapper.java b/os-ems/src/main/java/com/os/ems/report/mapper/EmsReportMapper.java index 448ee2c..7c87f69 100644 --- a/os-ems/src/main/java/com/os/ems/report/mapper/EmsReportMapper.java +++ b/os-ems/src/main/java/com/os/ems/report/mapper/EmsReportMapper.java @@ -17,11 +17,11 @@ public interface EmsReportMapper { /** - * 统计能耗报表 + * 统计能耗电报表 * @param hashMap * @return */ - List energyStatisticalReportList(Map hashMap); + List energyStatisticalDnbReportList(Map hashMap); /** * 峰平谷耗量报表 diff --git a/os-ems/src/main/java/com/os/ems/report/service/IEmsReportService.java b/os-ems/src/main/java/com/os/ems/report/service/IEmsReportService.java index 95bb856..ad091d0 100644 --- a/os-ems/src/main/java/com/os/ems/report/service/IEmsReportService.java +++ b/os-ems/src/main/java/com/os/ems/report/service/IEmsReportService.java @@ -28,4 +28,11 @@ public interface IEmsReportService { * @return */ List peaksValleysConsumptionReportList(Map hashMap); + + /** + * 能源预览接口 + * @param hashMap + * @return + */ + List> energyPreviewReportList(Map hashMap); } diff --git a/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java b/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java index 7f33b1f..2835032 100644 --- a/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java @@ -1,5 +1,10 @@ package com.os.ems.report.service.impl; +import com.os.common.utils.StringUtils; +import com.os.ems.base.domain.EmsBaseMonitorWorkUnit; +import com.os.ems.base.domain.EmsBaseWorkUnit; +import com.os.ems.base.mapper.EmsBaseMonitorWorkUnitMapper; +import com.os.ems.base.mapper.EmsBaseWorkUnitMapper; import com.os.ems.report.domain.EnergyStatisticalReport; import com.os.ems.report.domain.PeaksValleysConsumptionReport; import com.os.ems.report.mapper.EmsReportMapper; @@ -7,8 +12,9 @@ import com.os.ems.report.service.IEmsReportService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; /** @@ -22,28 +28,84 @@ public class EmsReportServiceImpl implements IEmsReportService { @Autowired private EmsReportMapper emsReportMapper; + @Autowired + private EmsBaseMonitorWorkUnitMapper emsBaseMonitorWorkUnitMapper; + + @Autowired + private EmsBaseWorkUnitMapper emsBaseWorkUnitMapper; + /** * 统计能耗报表 + * * @param hashMap * @return */ @Override public List energyStatisticalReportList(Map hashMap) { - if (!hashMap.containsKey("dateType")){ + if (!hashMap.containsKey("dateType") && !hashMap.containsKey("energyType")) { return null; } hashMap.put("timeSub", Integer.parseInt(String.valueOf(hashMap.get("dateType")))); - return emsReportMapper.energyStatisticalReportList(hashMap); + List reportList = new ArrayList<>(); + + if (Objects.equals(String.valueOf(hashMap.get("energyType")), "2")){ + reportList = emsReportMapper.energyStatisticalDnbReportList(hashMap); + } + return reportList; } /** * 峰平谷耗量报表 + * * @param hashMap * @return */ @Override public List peaksValleysConsumptionReportList(Map hashMap) { + if (!hashMap.containsKey("dateType")) { + return null; + } return emsReportMapper.peaksValleysConsumptionReportList(hashMap); } + + /** + * 能源预览接口 + * + * @param hashMap + * @return + */ + @Override + public List> energyPreviewReportList(Map hashMap) { + List> resultList = new ArrayList<>(); + if (!hashMap.containsKey("startTime") || !hashMap.containsKey("endTime")) { + return resultList; + } + + EmsBaseWorkUnit workUnit = new EmsBaseWorkUnit(); + List workUnits = emsBaseWorkUnitMapper.selectEmsBaseWorkUnitList(workUnit); + + HashMap selectMap = new HashMap<>(); + selectMap.put("dateType", String.valueOf(hashMap.get("dateType"))); + selectMap.put("energyType", String.valueOf(hashMap.get("energyType"))); + selectMap.put("beginCollectTime", String.valueOf(hashMap.get("startTime"))); + selectMap.put("endCollectTime", String.valueOf(hashMap.get("endTime"))); + + for (EmsBaseWorkUnit unit : workUnits) { + HashMap typeResultMap = new HashMap<>(); + typeResultMap.put("unitName", unit.getWorkUnitName()); + selectMap.put("workUnitCode", unit.getWorkUnitCode()); + List reportList = this.energyStatisticalReportList(selectMap); + BigDecimal expendSum = new BigDecimal(0); + for (EnergyStatisticalReport report : reportList) { + typeResultMap.put("expend" + report.getBeginTime(), report.getExpend()); + expendSum = expendSum.add(report.getExpend()); + } + typeResultMap.put("expendSum", expendSum.toPlainString()); + resultList.add(typeResultMap); + } + + return resultList; + } + } diff --git a/os-ems/src/main/resources/mapper/ems/base/EmsBaseMonitorWorkUnitMapper.xml b/os-ems/src/main/resources/mapper/ems/base/EmsBaseMonitorWorkUnitMapper.xml index 05f7a5d..2ec3147 100644 --- a/os-ems/src/main/resources/mapper/ems/base/EmsBaseMonitorWorkUnitMapper.xml +++ b/os-ems/src/main/resources/mapper/ems/base/EmsBaseMonitorWorkUnitMapper.xml @@ -59,6 +59,7 @@ and ebmwu.updated_by = #{updatedBy} and ebmwu.updated_time = #{updatedTime} + order by ebwu.work_unit_type, ebmwu.work_unit_code, ebmwu.monitor_code - - and work_unit_code = #{workUnitCode} - and parent_id = #{parentId} - and work_unit_name like concat('%', #{workUnitName}, '%') - and work_unit_address = #{workUnitAddress} - and ancestors = #{ancestors} - and work_unit_sort = #{workUnitSort} - and product_line_code = #{productLineCode} - and work_unit_type = #{workUnitType} - and is_flag = #{isFlag} - and created_by = #{createdBy} - and created_time = #{createdTime} - and updated_by = #{updatedBy} - and updated_time = #{updatedTime} + + and work_unit_code = #{workUnitCode} + and parent_id = #{parentId} + and work_unit_name like concat('%', #{workUnitName}, + '%') + + and work_unit_address = #{workUnitAddress} + + and ancestors = #{ancestors} + and work_unit_sort = #{workUnitSort} + and product_line_code = #{productLineCode} + + and work_unit_type = #{workUnitType} + and is_flag = #{isFlag} + and created_by = #{createdBy} + and created_time = #{createdTime} + and updated_by = #{updatedBy} + and updated_time = #{updatedTime} + order by work_unit_type, work_unit_code - + - + insert into ems_base_work_unit @@ -65,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" created_time, updated_by, updated_time, - + #{workUnitCode}, #{parentId}, @@ -80,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createdTime}, #{updatedBy}, #{updatedTime}, - + @@ -104,11 +123,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from ems_base_work_unit where obj_id = #{objId} + delete + from ems_base_work_unit + where obj_id = #{objId} - delete from ems_base_work_unit where obj_id in + delete from ems_base_work_unit where obj_id in #{objId} diff --git a/os-ems/src/main/resources/mapper/ems/report/EmsReportMapper.xml b/os-ems/src/main/resources/mapper/ems/report/EmsReportMapper.xml index 2bba69b..639ebec 100644 --- a/os-ems/src/main/resources/mapper/ems/report/EmsReportMapper.xml +++ b/os-ems/src/main/resources/mapper/ems/report/EmsReportMapper.xml @@ -5,7 +5,7 @@ -