6 changed files with 410 additions and 3 deletions
			
			
		@ -0,0 +1,38 @@ | 
				
			|||||||
 | 
					package com.mh.web.controller.energy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.mh.common.core.controller.BaseController; | 
				
			||||||
 | 
					import com.mh.common.core.domain.vo.EnergyQueryVO; | 
				
			||||||
 | 
					import com.mh.common.core.page.TableDataInfo; | 
				
			||||||
 | 
					import com.mh.common.utils.DateUtils; | 
				
			||||||
 | 
					import com.mh.system.service.energy.IComprehensiveEnergyConsumptionService; | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PostMapping; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestBody; | 
				
			||||||
 | 
					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-24 15:53:13 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@RestController | 
				
			||||||
 | 
					@RequestMapping("/energy/cec") | 
				
			||||||
 | 
					public class ComprehensiveEnergyConsumptionController extends BaseController { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final IComprehensiveEnergyConsumptionService comprehensiveEnergyConsumptionService; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired | 
				
			||||||
 | 
					    public ComprehensiveEnergyConsumptionController(IComprehensiveEnergyConsumptionService comprehensiveEnergyConsumptionService) { | 
				
			||||||
 | 
					        this.comprehensiveEnergyConsumptionService = comprehensiveEnergyConsumptionService; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @PostMapping("/struct") | 
				
			||||||
 | 
					    public TableDataInfo structure(@RequestBody EnergyQueryVO vo) { | 
				
			||||||
 | 
					        DateUtils.sysEnergyDateChange(vo); | 
				
			||||||
 | 
					        return getDataTable(comprehensiveEnergyConsumptionService.structure(vo)); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,53 @@ | 
				
			|||||||
 | 
					package com.mh.common.core.domain.dto; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import lombok.Getter; | 
				
			||||||
 | 
					import lombok.Setter; | 
				
			||||||
 | 
					import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description 能源结构数据 | 
				
			||||||
 | 
					 * @date 2025-03-24 15:40:13 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Setter | 
				
			||||||
 | 
					@Getter | 
				
			||||||
 | 
					public class EnergyStructureDTO { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 名称 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    private String label; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 能耗值 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    private BigDecimal eng; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 同比 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    private BigDecimal yny; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 环比 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    private BigDecimal ono; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private List<?> children; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String toString() { | 
				
			||||||
 | 
					        return new ToStringBuilder(this) | 
				
			||||||
 | 
					                .append("label", label) | 
				
			||||||
 | 
					                .append("eng", eng) | 
				
			||||||
 | 
					                .append("yny", yny) | 
				
			||||||
 | 
					                .append("ono", ono) | 
				
			||||||
 | 
					                .append("children", children) | 
				
			||||||
 | 
					                .toString(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,101 @@ | 
				
			|||||||
 | 
					package com.mh.system.mapper.energy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Mapper; | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Param; | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Select; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					import java.util.Map; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description 综合能耗mapper | 
				
			||||||
 | 
					 * @date 2025-03-24 17:24:45 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Mapper | 
				
			||||||
 | 
					public interface ComprehensiveEnergyConsumptionMapper { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 查询单个表数据 | 
				
			||||||
 | 
					     * @param curTableName | 
				
			||||||
 | 
					     * @param isSum | 
				
			||||||
 | 
					     * @param startTime | 
				
			||||||
 | 
					     * @param endTime | 
				
			||||||
 | 
					     * @param paramType | 
				
			||||||
 | 
					     * @param systemType | 
				
			||||||
 | 
					     * @return | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    @Select("SELECT  " + | 
				
			||||||
 | 
					            "    cpm.terminal_device_type as \"deviceType\",  " + | 
				
			||||||
 | 
					            "    cpm.system_type as \"systemType\",  " + | 
				
			||||||
 | 
					            "    SUM(COALESCE(dd.calc_value, 0)) as \"calcValue\" " + | 
				
			||||||
 | 
					            "FROM  " + | 
				
			||||||
 | 
					            "    ${tableName} dd  " + | 
				
			||||||
 | 
					            "JOIN  " + | 
				
			||||||
 | 
					            "    collection_params_manage cpm  " + | 
				
			||||||
 | 
					            "ON  " + | 
				
			||||||
 | 
					            "    cpm.mt_num = dd.device_num  " + | 
				
			||||||
 | 
					            "WHERE  " + | 
				
			||||||
 | 
					            "    cpm.grade = #{grade}  " + | 
				
			||||||
 | 
					            "    AND cpm.mt_is_sum = #{isSum}  " + | 
				
			||||||
 | 
					            "    AND cpm.param_type = #{paramType}  " + | 
				
			||||||
 | 
					            "    AND cpm.system_type = #{systemType} " + | 
				
			||||||
 | 
					            "    AND dd.cur_time BETWEEN #{startTime}::timestamp AND #{endTime}::timestamp " + | 
				
			||||||
 | 
					            "GROUP BY  " + | 
				
			||||||
 | 
					            "    cpm.terminal_device_type,  " + | 
				
			||||||
 | 
					            "    cpm.system_type; ") | 
				
			||||||
 | 
					    List<Map<String, Object>> selectOneTableData(@Param("tableName") String curTableName, | 
				
			||||||
 | 
					                                                 @Param("isSum") int isSum, | 
				
			||||||
 | 
					                                                 @Param("startTime")String startTime, | 
				
			||||||
 | 
					                                                 @Param("endTime") String endTime, | 
				
			||||||
 | 
					                                                 @Param("paramType") String paramType, | 
				
			||||||
 | 
					                                                 @Param("systemType") String systemType, | 
				
			||||||
 | 
					                                                 @Param("grade") int grade); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 查询多个表数据 | 
				
			||||||
 | 
					     * @param curTableName | 
				
			||||||
 | 
					     * @param lastTableName | 
				
			||||||
 | 
					     * @param isSum | 
				
			||||||
 | 
					     * @param startTime | 
				
			||||||
 | 
					     * @param endTime | 
				
			||||||
 | 
					     * @param paramType | 
				
			||||||
 | 
					     * @param systemType | 
				
			||||||
 | 
					     * @return | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    @Select("SELECT  " + | 
				
			||||||
 | 
					            "    cpm.terminal_device_type as \"deviceType\",  " + | 
				
			||||||
 | 
					            "    cpm.system_type as \"systemType\",  " + | 
				
			||||||
 | 
					            "    SUM(COALESCE(dd.calc_value, 0)) as \"calcValue\" " + | 
				
			||||||
 | 
					            "FROM  " + | 
				
			||||||
 | 
					            "    ( " + | 
				
			||||||
 | 
					            "        SELECT device_num, calc_value, cur_time FROM ${curTableName} " + | 
				
			||||||
 | 
					            "           where cur_time BETWEEN #{startTime}::timestamp AND #{endTime}::timestamp  " + | 
				
			||||||
 | 
					            "        UNION ALL " + | 
				
			||||||
 | 
					            "        SELECT device_num, calc_value, cur_time FROM ${lastTableName} " + | 
				
			||||||
 | 
					            "           where cur_time BETWEEN #{startTime}::timestamp AND #{endTime}::timestamp  " + | 
				
			||||||
 | 
					            "    ) dd " + | 
				
			||||||
 | 
					            "JOIN  " + | 
				
			||||||
 | 
					            "    collection_params_manage cpm  " + | 
				
			||||||
 | 
					            "ON  " + | 
				
			||||||
 | 
					            "    cpm.mt_num = dd.device_num  " + | 
				
			||||||
 | 
					            "WHERE  " + | 
				
			||||||
 | 
					            "    cpm.grade = #{grade}  " + | 
				
			||||||
 | 
					            "    AND cpm.mt_is_sum = #{isSum}  " + | 
				
			||||||
 | 
					            "    AND cpm.param_type = #{paramType}  " + | 
				
			||||||
 | 
					            "    AND cpm.system_type = #{systemType} " + | 
				
			||||||
 | 
					            "    AND dd.cur_time BETWEEN #{startTime}::timestamp AND #{endTime}::timestamp " + | 
				
			||||||
 | 
					            "GROUP BY  " + | 
				
			||||||
 | 
					            "    cpm.terminal_device_type,  " + | 
				
			||||||
 | 
					            "    cpm.system_type;") | 
				
			||||||
 | 
					    List<Map<String, Object>> selectMultiTableData(@Param("curTableName") String curTableName, | 
				
			||||||
 | 
					                                                   @Param("lastTableName") String lastTableName, | 
				
			||||||
 | 
					                                                   @Param("isSum") int isSum, | 
				
			||||||
 | 
					                                                   @Param("startTime") String startTime, | 
				
			||||||
 | 
					                                                   @Param("endTime") String endTime, | 
				
			||||||
 | 
					                                                   @Param("paramType") String paramType, | 
				
			||||||
 | 
					                                                   @Param("systemType") String systemType, | 
				
			||||||
 | 
					                                                   @Param("grade") int grade); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,22 @@ | 
				
			|||||||
 | 
					package com.mh.system.service.energy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.mh.common.core.domain.vo.EnergyQueryVO; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description 综合能耗结构数据 | 
				
			||||||
 | 
					 * @date 2025-03-24 15:56:43 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface IComprehensiveEnergyConsumptionService { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 能耗结构图 | 
				
			||||||
 | 
					     * @param vo | 
				
			||||||
 | 
					     * @return | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    List<?> structure(EnergyQueryVO vo); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,185 @@ | 
				
			|||||||
 | 
					package com.mh.system.service.energy.impl; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
				
			||||||
 | 
					import com.mh.common.core.domain.dto.EnergyStructureDTO; | 
				
			||||||
 | 
					import com.mh.common.core.domain.entity.CollectionParamsManage; | 
				
			||||||
 | 
					import com.mh.common.core.domain.entity.SysDictData; | 
				
			||||||
 | 
					import com.mh.common.core.domain.entity.SysParams; | 
				
			||||||
 | 
					import com.mh.common.core.domain.vo.EnergyQueryVO; | 
				
			||||||
 | 
					import com.mh.common.utils.DateUtils; | 
				
			||||||
 | 
					import com.mh.system.mapper.SysDictDataMapper; | 
				
			||||||
 | 
					import com.mh.system.mapper.SysParamsMapper; | 
				
			||||||
 | 
					import com.mh.system.mapper.device.CollectionParamsManageMapper; | 
				
			||||||
 | 
					import com.mh.system.mapper.energy.ComprehensiveEnergyConsumptionMapper; | 
				
			||||||
 | 
					import com.mh.system.service.energy.IComprehensiveEnergyConsumptionService; | 
				
			||||||
 | 
					import org.springframework.stereotype.Service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal; | 
				
			||||||
 | 
					import java.util.ArrayList; | 
				
			||||||
 | 
					import java.util.HashMap; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					import java.util.Map; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description 综合能耗结构服务实现 | 
				
			||||||
 | 
					 * @date 2025-03-24 15:57:09 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Service | 
				
			||||||
 | 
					public class ComprehensiveEnergyConsumptionServiceImpl implements IComprehensiveEnergyConsumptionService { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final CollectionParamsManageMapper collectionParamsManageMapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final ComprehensiveEnergyConsumptionMapper comprehensiveEnergyConsumptionMapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final SysDictDataMapper sysDictDataMapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final SysParamsMapper sysParamsMapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ComprehensiveEnergyConsumptionServiceImpl(CollectionParamsManageMapper collectionParamsManageMapper, ComprehensiveEnergyConsumptionMapper comprehensiveEnergyConsumptionMapper, SysDictDataMapper sysDictDataMapper, SysParamsMapper sysParamsMapper) { | 
				
			||||||
 | 
					        this.collectionParamsManageMapper = collectionParamsManageMapper; | 
				
			||||||
 | 
					        this.comprehensiveEnergyConsumptionMapper = comprehensiveEnergyConsumptionMapper; | 
				
			||||||
 | 
					        this.sysDictDataMapper = sysDictDataMapper; | 
				
			||||||
 | 
					        this.sysParamsMapper = sysParamsMapper; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public List<?> structure(EnergyQueryVO vo) { | 
				
			||||||
 | 
					        // 查询各个系统的能耗结构
 | 
				
			||||||
 | 
					        // 查询系统类型数据
 | 
				
			||||||
 | 
					        List<SysDictData> sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type"); | 
				
			||||||
 | 
					        // 得出系统项目
 | 
				
			||||||
 | 
					        List<SysParams> sysParams = sysParamsMapper.selectSysParamsList(); | 
				
			||||||
 | 
					        EnergyStructureDTO result = new EnergyStructureDTO(); | 
				
			||||||
 | 
					        result.setLabel(sysParams.get(0).getProName()); | 
				
			||||||
 | 
					        List<EnergyStructureDTO> result1 = new ArrayList<>(); | 
				
			||||||
 | 
					        for (SysDictData dictData : sysTypeData) { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            EnergyStructureDTO energyStructureDTO = new EnergyStructureDTO(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            energyStructureDTO.setLabel(dictData.getDictLabel()); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 获取当前系统值
 | 
				
			||||||
 | 
					            List<Map<String, Object>> structData = getStructData(vo, dictData.getDictValue()); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 获取同比值
 | 
				
			||||||
 | 
					            String yoyStartTime = DateUtils.yoyDate(vo.getStartTime()); | 
				
			||||||
 | 
					            String yoyEndTime = DateUtils.yoyDate(vo.getEndTime()); | 
				
			||||||
 | 
					            EnergyQueryVO yoyVo = vo.clone(); | 
				
			||||||
 | 
					            yoyVo.setStartTime(yoyStartTime); | 
				
			||||||
 | 
					            yoyVo.setEndTime(yoyEndTime); | 
				
			||||||
 | 
					            List<Map<String, Object>> yoyStructData = getStructData(yoyVo, dictData.getDictValue()); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 获取环比值
 | 
				
			||||||
 | 
					            String hbyStartTime = DateUtils.momDate(vo.getStartTime(), vo.getTimeType(), "start"); | 
				
			||||||
 | 
					            String hbyEndTime = DateUtils.momDate(vo.getEndTime(), vo.getTimeType(), "end"); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            EnergyQueryVO momVo = vo.clone(); | 
				
			||||||
 | 
					            momVo.setStartTime(hbyStartTime); | 
				
			||||||
 | 
					            momVo.setEndTime(hbyEndTime); | 
				
			||||||
 | 
					            List<Map<String, Object>> hbyStructData = getStructData(momVo, dictData.getDictValue()); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 拼接数据
 | 
				
			||||||
 | 
					            // 流式拼接数据,根据map的deviceType,systemType两个分组拼接数据,得出deviceType, systemType, curValue, yoyValue, hbyValue
 | 
				
			||||||
 | 
					            // 得出新map,计算同比环比
 | 
				
			||||||
 | 
					            for (Map<String, Object> map : structData) { | 
				
			||||||
 | 
					                String deviceType = map.get("deviceType").toString(); | 
				
			||||||
 | 
					                String systemType = map.get("systemType").toString(); | 
				
			||||||
 | 
					                // 当前值
 | 
				
			||||||
 | 
					                map.put("curValue", map.get("calcValue") == null ? 0 : map.get("calcValue")); | 
				
			||||||
 | 
					                // 同比值
 | 
				
			||||||
 | 
					                map.put("yoyValue", yoyStructData.stream() | 
				
			||||||
 | 
					                        .filter(item -> item.get("deviceType").equals(deviceType) | 
				
			||||||
 | 
					                                && item.get("systemType").equals(systemType)) | 
				
			||||||
 | 
					                        .findFirst() | 
				
			||||||
 | 
					                        .map(item -> item.get("calcValue") == null ? 0 : item.get("calcValue")) | 
				
			||||||
 | 
					                        .orElse(0)); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 同比率计算
 | 
				
			||||||
 | 
					                BigDecimal curValue = new BigDecimal(String.valueOf(map.get("curValue"))); | 
				
			||||||
 | 
					                BigDecimal yoyValue = new BigDecimal(String.valueOf(map.get("yoyValue"))); | 
				
			||||||
 | 
					                map.put("yoyRate", curValue.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO | 
				
			||||||
 | 
					                        : yoyValue.divide(curValue, 2, BigDecimal.ROUND_HALF_UP)); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 环比值
 | 
				
			||||||
 | 
					                map.put("momValue", hbyStructData.stream() | 
				
			||||||
 | 
					                        .filter(item -> item.get("deviceType").equals(deviceType) | 
				
			||||||
 | 
					                                && item.get("systemType").equals(systemType)) | 
				
			||||||
 | 
					                        .findFirst() | 
				
			||||||
 | 
					                        .map(item -> item.get("calcValue") == null ? 0 : item.get("calcValue")) | 
				
			||||||
 | 
					                        .orElse(0)); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 环比率计算
 | 
				
			||||||
 | 
					                BigDecimal momValue = new BigDecimal(String.valueOf(map.get("momValue"))); | 
				
			||||||
 | 
					                map.put("momRate", curValue.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO | 
				
			||||||
 | 
					                        : momValue.divide(curValue, 2, BigDecimal.ROUND_HALF_UP)); | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            energyStructureDTO.setChildren(structData); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            result1.add(energyStructureDTO); | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        result.setChildren(result1); | 
				
			||||||
 | 
					        // 查询各个设备的能耗结构
 | 
				
			||||||
 | 
					        return List.of(result); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private List<Map<String, Object>> getStructData(EnergyQueryVO vo, String systemType) { | 
				
			||||||
 | 
					        String startTime = vo.getStartTime().substring(0, 4); | 
				
			||||||
 | 
					        String endTime = vo.getEndTime().substring(0, 4); | 
				
			||||||
 | 
					        String curTableName = "data_day"+startTime; | 
				
			||||||
 | 
					        String lastTableName = "data_day"+endTime; | 
				
			||||||
 | 
					        if (startTime.equals(endTime)) { | 
				
			||||||
 | 
					            // 查询一个表
 | 
				
			||||||
 | 
					            lastTableName = "data_day"+startTime; | 
				
			||||||
 | 
					        } else { | 
				
			||||||
 | 
					            // 查询多个表
 | 
				
			||||||
 | 
					            lastTableName = "data_day"+startTime; | 
				
			||||||
 | 
					            curTableName = "data_day"+endTime; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        int isSum = queryCollectionParams(systemType, vo.getParamType(), 40); | 
				
			||||||
 | 
					        // 根据时间范围查询
 | 
				
			||||||
 | 
					        if (lastTableName.equals(curTableName)) { | 
				
			||||||
 | 
					            // 查询一个表
 | 
				
			||||||
 | 
					            List<Map<String, Object>> map = comprehensiveEnergyConsumptionMapper.selectOneTableData(curTableName, | 
				
			||||||
 | 
					                    isSum, | 
				
			||||||
 | 
					                    vo.getStartTime(), | 
				
			||||||
 | 
					                    vo.getEndTime(), | 
				
			||||||
 | 
					                    vo.getParamType(), | 
				
			||||||
 | 
					                    systemType, | 
				
			||||||
 | 
					                    40); | 
				
			||||||
 | 
					            return map; | 
				
			||||||
 | 
					        } else { | 
				
			||||||
 | 
					            // 查询多个表
 | 
				
			||||||
 | 
					            List<Map<String, Object>> map = comprehensiveEnergyConsumptionMapper.selectMultiTableData(curTableName, | 
				
			||||||
 | 
					                    lastTableName, | 
				
			||||||
 | 
					                    isSum, | 
				
			||||||
 | 
					                    vo.getStartTime(), | 
				
			||||||
 | 
					                    vo.getEndTime(), | 
				
			||||||
 | 
					                    vo.getParamType(), | 
				
			||||||
 | 
					                    systemType, | 
				
			||||||
 | 
					                    40); | 
				
			||||||
 | 
					            return map; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int queryCollectionParams(String sysType, String paramType, int grade) { | 
				
			||||||
 | 
					        QueryWrapper<CollectionParamsManage> queryWrapper = new QueryWrapper<>(); | 
				
			||||||
 | 
					        queryWrapper.eq("param_type", paramType) | 
				
			||||||
 | 
					                .eq("system_type", sysType) | 
				
			||||||
 | 
					                .eq("grade", grade); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 先查询总表
 | 
				
			||||||
 | 
					        queryWrapper.eq("mt_is_sum", 0); | 
				
			||||||
 | 
					        Long count = collectionParamsManageMapper.selectCount(queryWrapper); | 
				
			||||||
 | 
					        if (count > 0) { | 
				
			||||||
 | 
					            return 0; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 查询分表
 | 
				
			||||||
 | 
					        return 1; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue