|
@@ -1,48 +1,19 @@
|
|
|
package com.persagy.apm.energy.report.monthly.outline.service.impl;
|
|
|
|
|
|
import cn.hutool.core.thread.ExecutorBuilder;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.constant.enums.TimeTypeEnum;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.dto.QueryEnergyDataDTO;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.dto.QueryItemInfoDTO;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.service.ICenterMiddlewareWebService;
|
|
|
-import com.persagy.apm.energy.report.common.utils.DateUtils;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.function.model.Function;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.function.service.IFunctionService;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.functiongroup.model.FunctionGroup;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.functiongroup.service.IFunctionGroupService;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunction.model.ReportTypeFunctionRel;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunction.model.dto.QueryReportTypeFunctionRelDTO;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunction.service.IReportTypeFunctionRelService;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunctiongroup.model.ReportTypeFunctionGroupRel;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunctiongroup.model.dto.QueryReportTypeFunctionGroupRelDTO;
|
|
|
-import com.persagy.apm.energy.report.monthly.config.rel.typefunctiongroup.service.IReportTypeFunctionGroupRelService;
|
|
|
import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
|
|
|
import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BuildingTypeEnum;
|
|
|
import com.persagy.apm.energy.report.monthly.config.type.model.ReportType;
|
|
|
import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeService;
|
|
|
-import com.persagy.apm.energy.report.monthly.detail.business.model.OpenPower;
|
|
|
-import com.persagy.apm.energy.report.monthly.detail.business.model.dto.AddReportBusinessDetailDTO;
|
|
|
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.GroupInfo;
|
|
|
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerItemVO;
|
|
|
-import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
|
|
|
-import com.persagy.apm.energy.report.monthly.functionvalue.service.IFunctionValueService;
|
|
|
-import com.persagy.apm.energy.report.monthly.outline.constants.BusinessReportParagraphs;
|
|
|
import com.persagy.apm.energy.report.monthly.outline.constants.enums.ReportStateEnum;
|
|
|
import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
|
|
|
-import com.persagy.apm.energy.report.saasweb.model.vo.PoemsProjectVO;
|
|
|
-import com.persagy.apm.energy.report.saasweb.model.vo.SimpleProjectVO;
|
|
|
-import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.assertj.core.util.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 消费消息线程池
|
|
@@ -54,23 +25,11 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class GenerateReportThreadPool {
|
|
|
@Autowired
|
|
|
- private IReportBusinessDetailService businessDetailService;
|
|
|
+ private BusinessProjectReportGenerator businessProjectReportGenerator;
|
|
|
@Autowired
|
|
|
- private IReportTypeService reportTypeService;
|
|
|
- @Autowired
|
|
|
- private IReportTypeFunctionGroupRelService reportTypeFunctionGroupRelService;
|
|
|
- @Autowired
|
|
|
- private IReportTypeFunctionRelService reportTypeFunctionRelService;
|
|
|
- @Autowired
|
|
|
- private IFunctionGroupService functionGroupService;
|
|
|
+ private BusinessAreaReportGenerator businessAreaReportGenerator;
|
|
|
@Autowired
|
|
|
- private IFunctionService functionService;
|
|
|
- @Autowired
|
|
|
- private IFunctionValueService functionValueService;
|
|
|
- @Autowired
|
|
|
- private ICenterMiddlewareWebService centerMiddlewareWebService;
|
|
|
- @Autowired
|
|
|
- private ISaasWebService saasWebService;
|
|
|
+ private IReportTypeService reportTypeService;
|
|
|
|
|
|
private final ExecutorService es;
|
|
|
|
|
@@ -97,11 +56,11 @@ public class GenerateReportThreadPool {
|
|
|
String reportTypeId = reportOutline.getReportTypeId();
|
|
|
ReportType reportType = reportTypeService.queryReportTypeDetail(reportTypeId);
|
|
|
if (BuildingTypeEnum.BUSINESS.getType().equals(reportType.getBuildingType())) {
|
|
|
- AddReportBusinessDetailDTO addReportBusinessDetailDTO = new AddReportBusinessDetailDTO();
|
|
|
- OpenPower openPower = getOpenPower(reportOutline);
|
|
|
- // TODO: 2021/5/24 给其他属性赋值
|
|
|
- addReportBusinessDetailDTO.setOpenPower(openPower);
|
|
|
- businessDetailService.createReportBusinessDetail(addReportBusinessDetailDTO);
|
|
|
+ if (BelongTypeEnum.PROJECT.getType().equals(reportType.getBelongType())) {
|
|
|
+ businessProjectReportGenerator.generateReport(reportOutline);
|
|
|
+ } else {
|
|
|
+ businessAreaReportGenerator.generateReport(reportOutline);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("生成报告失败", e);
|
|
@@ -109,204 +68,4 @@ public class GenerateReportThreadPool {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取在营项目用电量
|
|
|
- *
|
|
|
- * @param reportOutline 报告outline对象
|
|
|
- * @return 在营项目用电量
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/24 4:14 下午
|
|
|
- */
|
|
|
- private OpenPower getOpenPower(ReportOutline reportOutline) {
|
|
|
- OpenPower openPower = new OpenPower();
|
|
|
- String reportTypeId = reportOutline.getReportTypeId();
|
|
|
- Date reportMonth = reportOutline.getReportMonth();
|
|
|
-
|
|
|
- ReportType reportType = reportTypeService.queryReportTypeDetail(reportTypeId);
|
|
|
- String belongType = reportType.getBelongType();
|
|
|
-
|
|
|
- List<String> projectIds = new ArrayList<>();
|
|
|
- if (BelongTypeEnum.PROJECT.getType().equals(belongType)) {
|
|
|
- projectIds.add(reportOutline.getBelong());
|
|
|
- } else {
|
|
|
- String areaId = reportOutline.getBelong();
|
|
|
- // 获取区域下的项目
|
|
|
- List<PoemsProjectVO> projectsByArea = saasWebService.getProjectsByArea(areaId);
|
|
|
- if (!CollectionUtils.isEmpty(projectsByArea)) {
|
|
|
- projectIds.addAll(projectsByArea.stream().map(
|
|
|
- PoemsProjectVO::getProjectId).collect(Collectors.toList()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取在营项目用电量下拥有的信息点分组和信息点
|
|
|
- List<String> groupIdList = getGroupsByParagraph(
|
|
|
- reportTypeId, BusinessReportParagraphs.OPEN_POWER);
|
|
|
-
|
|
|
- openPower.setGroups(getPowerGroupInfos(groupIdList, reportMonth, projectIds));
|
|
|
-
|
|
|
- List<String> functionIdList = getFunctionsByParagraph(
|
|
|
- reportTypeId, BusinessReportParagraphs.OPEN_POWER);
|
|
|
- openPower.setItems(getPowerItemInfos(functionIdList, reportMonth, projectIds));
|
|
|
- // TODO: 2021/5/24 计算统计值
|
|
|
- // openPower.setSummary();
|
|
|
- return openPower;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取用电量条目信息
|
|
|
- *
|
|
|
- * @param functionIdList 用电量条目列表
|
|
|
- * @param reportMonth 报告月份
|
|
|
- * @return 用电量条目列表
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/24 7:15 下午
|
|
|
- */
|
|
|
- private List<PowerItemVO> getPowerItemInfos(List<String> functionIdList, Date reportMonth, List<String> projectIds) {
|
|
|
- List<PowerItemVO> powerItemVOList = Lists.newArrayList();
|
|
|
- if (CollectionUtils.isEmpty(functionIdList) || CollectionUtils.isEmpty(projectIds)) {
|
|
|
- return powerItemVOList;
|
|
|
- }
|
|
|
-
|
|
|
- for (String functionId : functionIdList) {
|
|
|
- Function function = functionService.queryFunctionDetail(functionId);
|
|
|
- String itemName = getItemName(function, projectIds.get(0));
|
|
|
- PowerItemVO powerItemVO = new PowerItemVO();
|
|
|
- powerItemVO.setName(itemName);
|
|
|
- for (String projectId : projectIds) {
|
|
|
- QueryEnergyDataDTO queryEnergyDataDTO = new QueryEnergyDataDTO();
|
|
|
- // 获取项目信息
|
|
|
- SimpleProjectVO simpleProjectInfo = saasWebService.getSimpleProjectInfo(projectId);
|
|
|
- if (simpleProjectInfo == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- queryEnergyDataDTO.setProjectId(simpleProjectInfo.getProjectLocalID());
|
|
|
- queryEnergyDataDTO.setBuildingId(simpleProjectInfo.getProjectLocalID());
|
|
|
- queryEnergyDataDTO.setModelCode(function.getModelCode());
|
|
|
- // 去年一月
|
|
|
- queryEnergyDataDTO.setStartDate();
|
|
|
- queryEnergyDataDTO.setEndDate(DateUtils.date2Str(reportMonth, DateUtils.SDF_SECOND));
|
|
|
- queryEnergyDataDTO.setItemIdList(Lists.newArrayList(function.getItemId()));
|
|
|
- queryEnergyDataDTO.setTimeType(TimeTypeEnum.MONTH.getType());
|
|
|
- Map<String, TreeMap<Date, Double>> itemEnergyDataMap = centerMiddlewareWebService.getItemEnergyDataMap(queryEnergyDataDTO);
|
|
|
- }
|
|
|
-
|
|
|
- // TODO: 2021/5/24 获取值
|
|
|
-
|
|
|
- // powerItemVO.setCurrentMonth();
|
|
|
- // ...
|
|
|
- powerItemVOList.add(powerItemVO);
|
|
|
- }
|
|
|
- return powerItemVOList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取条目名称
|
|
|
- *
|
|
|
- * @param function 功能点信息
|
|
|
- * @param projectId 项目id
|
|
|
- * @return 条目名称
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/28 7:22 下午
|
|
|
- */
|
|
|
- private String getItemName(Function function, String projectId) {
|
|
|
- // 获取项目信息
|
|
|
- SimpleProjectVO simpleProjectInfo = saasWebService.getSimpleProjectInfo(projectId);
|
|
|
-
|
|
|
- if (simpleProjectInfo == null) {
|
|
|
- return "";
|
|
|
- }
|
|
|
- QueryItemInfoDTO queryItemInfoDTO = new QueryItemInfoDTO();
|
|
|
- // 注意这里应该传入项目本地编码
|
|
|
- queryItemInfoDTO.setProjectId(simpleProjectInfo.getProjectLocalID());
|
|
|
- queryItemInfoDTO.setBuildingId(simpleProjectInfo.getProjectLocalID());
|
|
|
- queryItemInfoDTO.setModelCode(function.getModelCode());
|
|
|
- queryItemInfoDTO.setItemIdList(Lists.newArrayList(function.getItemId()));
|
|
|
- Map<String, String> itemNameMap = centerMiddlewareWebService.getItemNameMap(queryItemInfoDTO);
|
|
|
- if (itemNameMap != null) {
|
|
|
- return itemNameMap.get(function.getItemId());
|
|
|
- }
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取用电量分组信息
|
|
|
- *
|
|
|
- * @param groupIdList 分组id列表
|
|
|
- * @param reportMonth 报告月份
|
|
|
- * @param projectIds 报告涉及的项目id列表
|
|
|
- * @return 分组对象列表
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/24 7:12 下午
|
|
|
- */
|
|
|
- private List<GroupInfo<PowerItemVO>> getPowerGroupInfos(List<String> groupIdList, Date reportMonth, List<String> projectIds) {
|
|
|
- List<GroupInfo<PowerItemVO>> groupInfoList = Lists.newArrayList();
|
|
|
- if (CollectionUtils.isEmpty(groupIdList)) {
|
|
|
- return groupInfoList;
|
|
|
- }
|
|
|
- for (String groupId : groupIdList) {
|
|
|
- GroupInfo<PowerItemVO> groupInfo = new GroupInfo<>();
|
|
|
- FunctionGroup functionGroup = functionGroupService.queryFunctionGroupDetail(groupId);
|
|
|
- groupInfo.setGroupName(functionGroup.getName());
|
|
|
- // 获取组下的分组(本期不做)
|
|
|
- // 获取组下的分项
|
|
|
- String functionIdStr = functionGroup.getFunctionIds();
|
|
|
- List<String> functionIds = Lists.newArrayList(functionIdStr.split(","));
|
|
|
- List<PowerItemVO> powerItemInfos = getPowerItemInfos(functionIds, reportMonth, projectIds);
|
|
|
- groupInfo.setItems(powerItemInfos);
|
|
|
- // TODO: 2021/5/24 计算统计值
|
|
|
- // groupInfo.setSummary();
|
|
|
- }
|
|
|
- return groupInfoList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据段落获取报告类型关联的分组
|
|
|
- *
|
|
|
- * @param reportTypeId 报告类型
|
|
|
- * @param belongParagraph 报告段落
|
|
|
- * @return 报告段落包含的分组id列表
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/24 4:31 下午
|
|
|
- */
|
|
|
- private List<String> getGroupsByParagraph(String reportTypeId, String belongParagraph) {
|
|
|
- List<String> groupIdList = Lists.newArrayList();
|
|
|
- QueryReportTypeFunctionGroupRelDTO queryReportTypeFunctionGroupRelDTO = new QueryReportTypeFunctionGroupRelDTO();
|
|
|
- queryReportTypeFunctionGroupRelDTO.setReportTypeId(reportTypeId);
|
|
|
- queryReportTypeFunctionGroupRelDTO.setBelongParagraph(belongParagraph);
|
|
|
- List<ReportTypeFunctionGroupRel> reportTypeFunctionGroupRels = reportTypeFunctionGroupRelService.
|
|
|
- queryReportTypeFunctionGroupRelList(queryReportTypeFunctionGroupRelDTO);
|
|
|
- if (!CollectionUtils.isEmpty(reportTypeFunctionGroupRels)) {
|
|
|
- groupIdList = reportTypeFunctionGroupRels.stream().
|
|
|
- map(ReportTypeFunctionGroupRel::getFunctionGroupId).collect(Collectors.toList());
|
|
|
- }
|
|
|
- return groupIdList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据段落获取报告类型关联的信息点
|
|
|
- *
|
|
|
- * @param reportTypeId 报告类型
|
|
|
- * @param belongParagraph 报告段落
|
|
|
- * @return 报告段落包含的信息点id列表
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/5/24 4:31 下午
|
|
|
- */
|
|
|
- private List<String> getFunctionsByParagraph(String reportTypeId, String belongParagraph) {
|
|
|
- List<String> functionIdList = Lists.newArrayList();
|
|
|
- QueryReportTypeFunctionRelDTO queryReportTypeFunctionRelDTO = new QueryReportTypeFunctionRelDTO();
|
|
|
- queryReportTypeFunctionRelDTO.setReportTypeId(reportTypeId);
|
|
|
- queryReportTypeFunctionRelDTO.setBelongParagraph(belongParagraph);
|
|
|
- List<ReportTypeFunctionRel> reportTypeFunctionRels = reportTypeFunctionRelService.queryReportTypeFunctionRelList(queryReportTypeFunctionRelDTO);
|
|
|
- if (!CollectionUtils.isEmpty(reportTypeFunctionRels)) {
|
|
|
- functionIdList = reportTypeFunctionRels.stream().
|
|
|
- map(ReportTypeFunctionRel::getFunctionId).collect(Collectors.toList());
|
|
|
- }
|
|
|
- return functionIdList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|