浏览代码

生成报告代码开发

lixing 3 年之前
父节点
当前提交
b28943b573
共有 26 个文件被更改,包括 1374 次插入287 次删除
  1. 47 0
      src/main/java/com/persagy/apm/energy/report/common/utils/DataUtils.java
  2. 120 0
      src/main/java/com/persagy/apm/energy/report/common/utils/DateUtils.java
  3. 11 0
      src/main/java/com/persagy/apm/energy/report/monthly/config/function/service/IFunctionService.java
  4. 32 0
      src/main/java/com/persagy/apm/energy/report/monthly/config/function/service/impl/FunctionServiceImpl.java
  5. 8 4
      src/main/java/com/persagy/apm/energy/report/monthly/config/statisticsitems/model/dto/QueryStatisticItemsDTO.java
  6. 8 8
      src/main/java/com/persagy/apm/energy/report/monthly/config/statisticsitems/service/impl/StatisticItemsServiceImpl.java
  7. 4 0
      src/main/java/com/persagy/apm/energy/report/monthly/config/type/service/impl/ReportTypeServiceImpl.java
  8. 1 2
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/ReportBusinessDetail.java
  9. 11 11
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/PowerItemVO.java
  10. 22 0
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/service/IReportBusinessDetailService.java
  11. 41 0
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/service/impl/ReportBusinessDetailServiceImpl.java
  12. 13 0
      src/main/java/com/persagy/apm/energy/report/monthly/functionvalue/service/IFunctionValueService.java
  13. 17 6
      src/main/java/com/persagy/apm/energy/report/monthly/functionvalue/service/impl/FunctionValueServiceImpl.java
  14. 100 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportCostInfoService.java
  15. 116 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportPowerInfoService.java
  16. 19 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IReportOutlineService.java
  17. 79 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessAreaReportGenerator.java
  18. 78 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessProjectReportGenerator.java
  19. 246 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportCostInfoServiceImpl.java
  20. 84 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportPlatformInfoServiceImpl.java
  21. 253 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportPowerInfoServiceImpl.java
  22. 8 249
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/GenerateReportThreadPool.java
  23. 31 6
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/ReportOutlineServiceImpl.java
  24. 10 0
      src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java
  25. 14 0
      src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java
  26. 1 1
      src/main/resources/mapper/ReportBusinessDetailMapper.xml

+ 47 - 0
src/main/java/com/persagy/apm/energy/report/common/utils/DataUtils.java

@@ -1,8 +1,11 @@
 package com.persagy.apm.energy.report.common.utils;
 
 import org.nfunk.jep.JEP;
+import org.springframework.util.CollectionUtils;
 
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.util.List;
 
 public class DataUtils {
     /**
@@ -50,4 +53,48 @@ public class DataUtils {
         return jep.getValue();
     }
 
+
+    /**
+     * 将一组对象中类型为double的属性求和
+     *
+     * @param objs 要求和的一组对象
+     * @param tClass 这组对象的类型
+     * @return 一个新的对象,将求和之后的属性赋值给它
+     * @author lixing
+     * @version V1.0 2021/5/30 10:44 上午
+     */
+    public static <T> T sumDoubleParams(List<T> objs, Class tClass) {
+        try {
+            T result = (T) tClass.newInstance();
+            if (CollectionUtils.isEmpty(objs)) {
+                return result;
+            }
+            Field[] declaredFields = tClass.getDeclaredFields();
+            for (Field declaredField : declaredFields) {
+                if (Double.class.equals(declaredField.getType())) {
+                    declaredField.set(result, objs.stream().filter(
+                            obj -> {
+                                try {
+                                    return declaredField.get(obj) != null;
+                                } catch (IllegalAccessException e) {
+                                    e.printStackTrace();
+                                    return false;
+                                }
+                            }).
+                            mapToDouble(obj -> {
+                                try {
+                                    return (Double) declaredField.get(obj);
+                                } catch (IllegalAccessException e) {
+                                    e.printStackTrace();
+                                    return 0d;
+                                }
+                            }).sum());
+                }
+            }
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
 }

+ 120 - 0
src/main/java/com/persagy/apm/energy/report/common/utils/DateUtils.java

@@ -1,9 +1,17 @@
 package com.persagy.apm.energy.report.common.utils;
 
+import org.assertj.core.util.Lists;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 public class DateUtils {
     public static final String SDFSECOND = "yyyyMMddHHmmss";
@@ -175,5 +183,117 @@ public class DateUtils {
         c.set(Calendar.MONTH, 0);
         return c.getTime();
     }
+    
+    /**
+     * 去年的第一天
+     *
+     * @param date 参照的日期
+     * @return 去年的第一天
+     * @author lixing
+     * @version V1.0 2021/5/30 11:43 上午
+     */
+    public static Date getFirstDayOfLastYear(Date date) {
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+
+        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
+        LocalDate lastYear = localDate.minusYears(1);
+        LocalDate lastYearFirstDay = LocalDate.of(lastYear.getYear(), 1, 1);
+        return Date.from(lastYearFirstDay.atStartOfDay(zoneId).toInstant());
+    }
+
+    /**
+     * 去年十二月第一天
+     *
+     * @param date 参照的日期
+     * @return 去年十二月第一天
+     * @author lixing
+     * @version V1.0 2021/5/30 11:43 上午
+     */
+    public static Date getDecemberFirstDayOfLastYear(Date date) {
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+
+        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
+        LocalDate lastYear = localDate.minusYears(1);
+        LocalDate lastYearFirstDay = LocalDate.of(lastYear.getYear(), 12, 1);
+        return Date.from(lastYearFirstDay.atStartOfDay(zoneId).toInstant());
+    }
+
+    /**
+     * 获取阶段内的每个月的第一天
+     *
+     * @param startDate 开始日期
+     * @param endDate 结束日期
+     * @return 阶段内的每个月的第一天
+     * @author lixing
+     * @version V1.0 2021/5/30 11:43 上午
+     */
+    public static List<Date> getFirstDayOfEveryMonth(Date startDate, Date endDate) {
+        if (startDate == null || endDate == null) {
+            return Lists.newArrayList();
+        }
+
+        ZoneId zoneId = ZoneId.systemDefault();
+        LocalDate startLocalDate = startDate.toInstant().atZone(zoneId).toLocalDate();
+        LocalDate endLocalDate = endDate.toInstant().atZone(zoneId).toLocalDate();
+
+        int startYear = startLocalDate.getYear();
+        int startYearMonth = startLocalDate.getMonthValue();
+        int endYear = endLocalDate.getYear();
+        int endYearMonth = endLocalDate.getMonthValue();
+        boolean startYearBigThanEndYear = startYear > endYear;
+        // 同一年,但开始月份大于结束月份
+        boolean startMonthBigThanEndMonth = startYear == endYear && startYearMonth > endYearMonth;
+
+        if (startYearBigThanEndYear || startMonthBigThanEndMonth) {
+            return Lists.newArrayList();
+        }
+
+        List<Date> result = new ArrayList<>();
+        for (int i = startYear; i <= endYear; i++) {
+            int startMonth = 1;
+            int endMonth = 12;
+            if (i == startYear) {
+                startMonth = startYearMonth;
+            }
+            if (i == endYear) {
+                endMonth = endYearMonth;
+            }
+
+            for (int j = startMonth; j <= endMonth; j++) {
+                LocalDate tmp = LocalDate.of(i, j, 1);
+                result.add(Date.from(tmp.atStartOfDay(zoneId).toInstant()));
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 上个月的第一天
+     *
+     * @param date 参照的日期
+     * @return 上个月的第一天
+     * @author lixing
+     * @version V1.0 2021/5/30 11:44 上午
+     */
+    public static Date getFirstDayOfLastMonth(Date date) {
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+
+        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
+        LocalDate lastMonth = localDate.minusMonths(1);
+        LocalDate lastMonthFirstDay = LocalDate.of(lastMonth.getYear(), lastMonth.getMonth(), 1);
+        return Date.from(lastMonthFirstDay.atStartOfDay(zoneId).toInstant());
+    }
+
+    public static void main(String[] args) {
+
+        // 2020-02-01
+        Date startDate = new Date(1580486400000L);
+        Date endDate = new Date();
+        System.out.println(getFirstDayOfEveryMonth(startDate, endDate));
+    }
 
 }

+ 11 - 0
src/main/java/com/persagy/apm/energy/report/monthly/config/function/service/IFunctionService.java

@@ -74,4 +74,15 @@ public interface IFunctionService {
      * @version V1.0 2021-05-20 19:05:33
      */
     IPage<Function> pageQueryFunction(PageQueryFunctionDTO pageQueryFunctionDTO);
+
+    /**
+     * 获取条目名称
+     *
+     * @param function  功能点信息
+     * @param projectId 项目id
+     * @return 条目名称
+     * @author lixing
+     * @version V1.0 2021/5/28 7:22 下午
+     */
+    String getItemName(Function function, String projectId);
 }

+ 32 - 0
src/main/java/com/persagy/apm/energy/report/monthly/config/function/service/impl/FunctionServiceImpl.java

@@ -1,9 +1,15 @@
 package com.persagy.apm.energy.report.monthly.config.function.service.impl;
 
 import com.persagy.apm.common.context.AppContext;
+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.monthly.config.function.dao.FunctionMapper;
 import com.persagy.apm.energy.report.monthly.config.function.service.IFunctionService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.persagy.apm.energy.report.saasweb.model.vo.SimpleProjectVO;
+import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
+import org.assertj.core.util.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.apache.commons.lang.StringUtils;
 import com.persagy.apm.common.constant.enums.ValidEnum;
@@ -12,6 +18,7 @@ import com.persagy.apm.energy.report.monthly.config.function.model.*;
 import com.persagy.apm.energy.report.monthly.config.function.model.dto.*;
 
 import java.util.List;
+import java.util.Map;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -28,6 +35,10 @@ import org.springframework.util.CollectionUtils;
 @Service
 public class FunctionServiceImpl extends ServiceImpl<FunctionMapper, Function>
         implements IFunctionService {
+    @Autowired
+    private ICenterMiddlewareWebService centerMiddlewareWebService;
+    @Autowired
+    private ISaasWebService saasWebService;
 
     /**
      * 创建能耗报告信息点
@@ -236,4 +247,25 @@ public class FunctionServiceImpl extends ServiceImpl<FunctionMapper, Function>
 
         return getBaseMapper().selectPage(pageParam, queryWrapper);
     }
+
+    @Override
+    public 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 "";
+    }
 }

+ 8 - 4
src/main/java/com/persagy/apm/energy/report/monthly/config/statisticsitems/model/dto/QueryStatisticItemsDTO.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * @author lixing
@@ -13,16 +14,19 @@ import java.util.Date;
 @Data
 @ApiModel(value = "查询统计条目入参")
 public class QueryStatisticItemsDTO {
-    @ApiModelProperty(value = "条目编码", required = true)
+    @ApiModelProperty(value = "统计条目id列表")
+    private List<String> statisticItemIdList;
+    
+    @ApiModelProperty(value = "条目编码")
     private String itemCode;
 
-    @ApiModelProperty(value = "条目来源", required = true)
+    @ApiModelProperty(value = "条目来源")
     private String itemSource;
 
-    @ApiModelProperty(value = "合格的标准", required = true)
+    @ApiModelProperty(value = "合格的标准")
     private String standardValue;
 
-    @ApiModelProperty(value = "合格的判断公式", required = true)
+    @ApiModelProperty(value = "合格的判断公式")
     private String qualifyFormula;
 
 }

+ 8 - 8
src/main/java/com/persagy/apm/energy/report/monthly/config/statisticsitems/service/impl/StatisticItemsServiceImpl.java

@@ -143,24 +143,24 @@ public class StatisticItemsServiceImpl extends ServiceImpl<StatisticItemsMapper,
 
         if (queryStatisticItemsDTO != null) {
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryStatisticItemsDTO.getItemCode())) {
-                queryWrapper.like(StatisticItems.PROP_ITEM_CODE, queryStatisticItemsDTO.getItemCode());
+                queryWrapper.eq(StatisticItems.PROP_ITEM_CODE, queryStatisticItemsDTO.getItemCode());
             }
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryStatisticItemsDTO.getItemSource())) {
-                queryWrapper.like(StatisticItems.PROP_ITEM_SOURCE, queryStatisticItemsDTO.getItemSource());
+                queryWrapper.eq(StatisticItems.PROP_ITEM_SOURCE, queryStatisticItemsDTO.getItemSource());
             }
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryStatisticItemsDTO.getStandardValue())) {
-                queryWrapper.like(StatisticItems.PROP_STANDARD_VALUE, queryStatisticItemsDTO.getStandardValue());
+                queryWrapper.eq(StatisticItems.PROP_STANDARD_VALUE, queryStatisticItemsDTO.getStandardValue());
             }
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryStatisticItemsDTO.getQualifyFormula())) {
-                queryWrapper.like(StatisticItems.PROP_QUALIFY_FORMULA, queryStatisticItemsDTO.getQualifyFormula());
+                queryWrapper.eq(StatisticItems.PROP_QUALIFY_FORMULA, queryStatisticItemsDTO.getQualifyFormula());
+            }
+
+            if (queryStatisticItemsDTO.getStatisticItemIdList() != null) {
+                queryWrapper.in(StatisticItems.PROP_ID, queryStatisticItemsDTO.getStatisticItemIdList());
             }
 
         }

+ 4 - 0
src/main/java/com/persagy/apm/energy/report/monthly/config/type/service/impl/ReportTypeServiceImpl.java

@@ -10,6 +10,7 @@ import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeEnum
 import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.apm.energy.report.saasweb.model.vo.PartitionVO;
+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 org.assertj.core.util.Lists;
@@ -21,7 +22,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.persagy.apm.energy.report.monthly.config.type.model.*;
 import com.persagy.apm.energy.report.monthly.config.type.model.dto.*;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -254,4 +257,5 @@ public class ReportTypeServiceImpl extends ServiceImpl<ReportTypeMapper, ReportT
 
         return result;
     }
+
 }

+ 1 - 2
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/ReportBusinessDetail.java

@@ -3,14 +3,13 @@ package com.persagy.apm.energy.report.monthly.detail.business.model;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
+import com.persagy.apm.common.model.entity.AuditableEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-import com.persagy.apm.common.model.entity.AuditableEntity;
 
 import java.io.Serializable;
-import java.util.Date;
 import java.util.List;
 
 /**

+ 11 - 11
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/PowerItemVO.java

@@ -12,36 +12,36 @@ import lombok.Data;
 @ApiModel(value = "用电量条目信息")
 public class PowerItemVO {
     @ApiModelProperty("条目名称")
-    private String name;
+    public String name;
 
     @ApiModelProperty("本月用电量")
-    private Double currentMonth;
+    public Double currentMonth;
 
     @ApiModelProperty("上月用电量")
-    private Double lastMonth;
+    public Double lastMonth;
 
     @ApiModelProperty("本年度累计用电量")
-    private Double yearCount;
+    public Double yearCount;
 
     @ApiModelProperty("去年同期累计用电量")
-    private Double lastYearCount;
+    public Double lastYearCount;
 
     @ApiModelProperty("环比增量")
-    private Double linkCount;
+    public Double linkCount;
 
     @ApiModelProperty("环比增幅")
-    private Double linkRange;
+    public Double linkRange;
 
     @ApiModelProperty("同比增量")
-    private Double sameCount;
+    public Double sameCount;
 
     @ApiModelProperty("同比增幅")
-    private Double sameRange;
+    public Double sameRange;
 
     @ApiModelProperty("本年单方用电量")
-    private Double yearPerCount;
+    public Double yearPerCount;
 
     @ApiModelProperty("去年单方用电量")
-    private Double lastYearPerCount;
+    public Double lastYearPerCount;
 
 }

+ 22 - 0
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/service/IReportBusinessDetailService.java

@@ -74,4 +74,26 @@ public interface IReportBusinessDetailService {
      * @version V1.0 2021-05-17 11:08:34
      */
     IPage<ReportBusinessDetail> pageQueryReportBusinessDetail(PageQueryReportBusinessDetailDTO pageQueryReportBusinessDetailDTO);
+
+    /**
+     * 根据段落获取报告类型关联的分组
+     *
+     * @param reportTypeId    报告类型
+     * @param belongParagraph 报告段落
+     * @return 报告段落包含的分组id列表
+     * @author lixing
+     * @version V1.0 2021/5/24 4:31 下午
+     */
+    List<String> getGroupsByParagraph(String reportTypeId, String belongParagraph);
+
+    /**
+     * 根据段落获取报告类型关联的信息点
+     *
+     * @param reportTypeId    报告类型
+     * @param belongParagraph 报告段落
+     * @return 报告段落包含的信息点id列表
+     * @author lixing
+     * @version V1.0 2021/5/24 4:31 下午
+     */
+    List<String> getFunctionsByParagraph(String reportTypeId, String belongParagraph);
 }

+ 41 - 0
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/service/impl/ReportBusinessDetailServiceImpl.java

@@ -12,6 +12,12 @@ import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.mod
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.AddReportDetailStatisticsItemRelDTO;
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.QueryReportDetailStatisticsItemRelDTO;
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.service.IReportDetailStatisticsItemRelService;
+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.detail.business.dao.ReportBusinessDetailMapper;
 import com.persagy.apm.energy.report.monthly.detail.business.model.ConvertReportBusinessDetailTool;
 import com.persagy.apm.energy.report.monthly.detail.business.model.ReportBusinessDetail;
@@ -21,12 +27,14 @@ import com.persagy.apm.energy.report.monthly.detail.business.model.dto.QueryRepo
 import com.persagy.apm.energy.report.monthly.detail.business.model.dto.UpdateReportBusinessDetailDTO;
 import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
 import org.apache.commons.lang.StringUtils;
+import org.assertj.core.util.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 报告详情(ReportBusinessDetail) service层
@@ -39,6 +47,10 @@ public class ReportBusinessDetailServiceImpl extends ServiceImpl<ReportBusinessD
         implements IReportBusinessDetailService {
     @Autowired
     IReportDetailStatisticsItemRelService reportDetailStatisticsItemRelService;
+    @Autowired
+    private IReportTypeFunctionRelService reportTypeFunctionRelService;
+    @Autowired
+    private IReportTypeFunctionGroupRelService reportTypeFunctionGroupRelService;
 
     /**
      * 创建报告详情
@@ -309,4 +321,33 @@ public class ReportBusinessDetailServiceImpl extends ServiceImpl<ReportBusinessD
 
         return getBaseMapper().selectPage(pageParam, queryWrapper);
     }
+
+    @Override
+    public 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;
+    }
+
+    @Override
+    public 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;
+    }
 }

+ 13 - 0
src/main/java/com/persagy/apm/energy/report/monthly/functionvalue/service/IFunctionValueService.java

@@ -3,6 +3,7 @@ package com.persagy.apm.energy.report.monthly.functionvalue.service;
 import com.persagy.apm.energy.report.monthly.functionvalue.model.*;
 import com.persagy.apm.energy.report.monthly.functionvalue.model.dto.*;
 
+import java.util.Date;
 import java.util.List;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -80,6 +81,18 @@ public interface IFunctionValueService {
     List<FunctionValue> queryFunctionValueList(QueryFunctionValueDTO queryFunctionValueDTO);
 
     /**
+     * 获取信息点取值
+     *
+     * @param functionId 功能点id
+     * @param dataTime 时间
+     * @param projectId 项目id
+     * @return 信息点的值
+     * @author lixing
+     * @version V1.0 2021/5/30 9:17 下午
+     */
+    String getFunctionValue(String functionId, Date dataTime, String projectId);
+
+    /**
      * 分页查询能耗报告信息点取值
      *
      * @param pageQueryFunctionValueDTO pageQueryDTO

+ 17 - 6
src/main/java/com/persagy/apm/energy/report/monthly/functionvalue/service/impl/FunctionValueServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -162,23 +163,20 @@ public class FunctionValueServiceImpl extends ServiceImpl<FunctionValueMapper, F
 
         if (queryFunctionValueDTO != null) {
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryFunctionValueDTO.getFunctionId())) {
-                queryWrapper.like(FunctionValue.PROP_FUNCTION_ID, queryFunctionValueDTO.getFunctionId());
+                queryWrapper.eq(FunctionValue.PROP_FUNCTION_ID, queryFunctionValueDTO.getFunctionId());
             }
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryFunctionValueDTO.getProjectId())) {
-                queryWrapper.like(FunctionValue.PROP_PROJECT_ID, queryFunctionValueDTO.getProjectId());
+                queryWrapper.eq(FunctionValue.PROP_PROJECT_ID, queryFunctionValueDTO.getProjectId());
             }
 
             if (queryFunctionValueDTO.getDataTime() != null) {
                 queryWrapper.eq(FunctionValue.PROP_DATA_TIME, queryFunctionValueDTO.getDataTime());
             }
 
-            // todo 需判断使用like还是eq
             if (StringUtils.isNotEmpty(queryFunctionValueDTO.getValue())) {
-                queryWrapper.like(FunctionValue.PROP_VALUE, queryFunctionValueDTO.getValue());
+                queryWrapper.eq(FunctionValue.PROP_VALUE, queryFunctionValueDTO.getValue());
             }
 
             if(!CollectionUtils.isEmpty(queryFunctionValueDTO.getFunctionIdList())){
@@ -198,6 +196,19 @@ public class FunctionValueServiceImpl extends ServiceImpl<FunctionValueMapper, F
         return list(queryWrapper);
     }
 
+    @Override
+    public String getFunctionValue(String functionId, Date dataTime, String projectId) {
+        QueryFunctionValueDTO queryFunctionValueDTO = new QueryFunctionValueDTO();
+        queryFunctionValueDTO.setFunctionId(functionId);
+        queryFunctionValueDTO.setDataTime(dataTime);
+        queryFunctionValueDTO.setProjectId(projectId);
+        List<FunctionValue> functionValues = queryFunctionValueList(queryFunctionValueDTO);
+        if (!CollectionUtils.isEmpty(functionValues)) {
+            return functionValues.get(0).getValue();
+        }
+        return null;
+    }
+
     /**
      * 分页查询能耗报告信息点取值
      *

+ 100 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportCostInfoService.java

@@ -0,0 +1,100 @@
+package com.persagy.apm.energy.report.monthly.outline.service;
+
+import com.persagy.apm.energy.report.monthly.config.function.model.Function;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostItemVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.GroupInfo;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 接口说明
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 10:26 下午
+ **/
+public interface IBusinessReportCostInfoService {
+    /**
+     * 获取费用信息
+     *
+     * @param reportOutline  报告outline对象
+     * @param groupIdList    费用信息点分组列表
+     * @param functionIdList 费用信息点列表
+     * @return 费用信息
+     * @author lixing
+     * @version V1.0 2021/5/24 4:14 下午
+     */
+    CostVO getOpenCost(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList);
+
+    /**
+     * 获取可同比费用信息
+     *
+     * @param reportOutline  报告outline对象
+     * @param groupIdList    费用信息点分组列表
+     * @param functionIdList 费用信息点列表
+     * @return 费用信息
+     * @author lixing
+     * @version V1.0 2021/5/24 4:14 下午
+     */
+    CostVO getCompareCost(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList);
+
+    /**
+     * 获取费用条目信息
+     *
+     * @param functionIdList 费用条目列表
+     * @param reportMonth    报告月份
+     * @return 费用条目列表
+     * @author lixing
+     * @version V1.0 2021/5/24 7:15 下午
+     */
+    List<CostItemVO> getCostItemInfos(List<String> functionIdList, Date reportMonth, List<String> projectIds);
+
+    /**
+     * 获取一组项目一个功能点的费用信息
+     *
+     * @param reportMonth 报告月份
+     * @param projectIds  一组项目id
+     * @param function    功能点(条目)
+     * @return 一组项目一个功能点的费用信息
+     * @author lixing
+     * @version V1.0 2021/5/30 5:55 下午
+     */
+    List<CostItemVO> getCostItemsByProjects(Date reportMonth, List<String> projectIds, Function function);
+
+    /**
+     * 获取一个条目的费用信息
+     *
+     * @param reportMonth       报告月份
+     * @param reportProjectInfo 报告项目信息
+     * @param functionId        功能点id
+     * @return 费用对象
+     * @author lixing
+     * @version V1.0 2021/5/30 5:54 下午
+     */
+    CostItemVO getCostItemInfo(Date reportMonth, ReportProjectVO reportProjectInfo, String functionId);
+
+    /**
+     * 求一组费用条目的统计值
+     *
+     * @param costItems 一组费用条目
+     * @return 一个新的费用条目对象,将统计值属性赋值给它
+     * @author lixing
+     * @version V1.0 2021/5/30 10:46 上午
+     */
+    CostItemVO getCostSum(List<CostItemVO> costItems);
+
+    /**
+     * 获取费用分组信息
+     *
+     * @param groupIdList 分组id列表
+     * @param reportMonth 报告月份
+     * @param projectIds  报告涉及的项目id列表
+     * @return 分组对象列表
+     * @author lixing
+     * @version V1.0 2021/5/24 7:12 下午
+     */
+    List<GroupInfo<CostItemVO>> getCostGroupInfos(List<String> groupIdList, Date reportMonth, List<String> projectIds);
+}

+ 116 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportPowerInfoService.java

@@ -0,0 +1,116 @@
+package com.persagy.apm.energy.report.monthly.outline.service;
+
+import com.persagy.apm.energy.report.monthly.config.function.model.Function;
+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.model.vo.PowerVO;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * 接口说明
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 10:25 下午
+ **/
+public interface IBusinessReportPowerInfoService {
+    /**
+     * 获取项目用电量
+     *
+     * @param reportOutline  报告outline对象
+     * @param groupIdList    用电量信息点分组列表
+     * @param functionIdList 用电量信息点列表
+     * @return 项目用电量
+     * @author lixing
+     * @version V1.0 2021/5/24 4:14 下午
+     */
+    PowerVO getPowerInfo(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList);
+
+    /**
+     * 获取可同比项目用电量
+     *
+     * @param reportOutline  报告outline对象
+     * @param groupIdList    用电量信息点分组列表
+     * @param functionIdList 用电量信息点列表
+     * @return 项目用电量
+     * @author lixing
+     * @version V1.0 2021/5/24 4:14 下午
+     */
+    PowerVO getComparePowerInfo(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList);
+
+    /**
+     * 获取用电量条目信息
+     *
+     * @param functionIdList 用电量条目列表
+     * @param reportMonth    报告月份
+     * @return 用电量条目列表
+     * @author lixing
+     * @version V1.0 2021/5/24 7:15 下午
+     */
+    List<PowerItemVO> getPowerItemInfos(List<String> functionIdList, Date reportMonth, List<String> projectIds);
+
+    /**
+     * 获取一组项目一个功能点的用电量信息
+     *
+     * @param reportMonth 报告月份
+     * @param projectIds  一组项目id
+     * @param function    功能点(条目)
+     * @return 一组项目一个功能点的用电量信息
+     * @author lixing
+     * @version V1.0 2021/5/30 5:55 下午
+     */
+    List<PowerItemVO> getPowerItemsByProjects(Date reportMonth, List<String> projectIds, Function function);
+
+    /**
+     * 获取一个条目的用电量信息
+     *
+     * @param reportMonth       报告月份
+     * @param reportProjectInfo 报告项目信息
+     * @param dateValueMap      日期 -> 用电量
+     * @return 用电量对象
+     * @author lixing
+     * @version V1.0 2021/5/30 5:54 下午
+     */
+    PowerItemVO getPowerItemInfo(Date reportMonth, Double reportProjectInfo, TreeMap<Date, Double> dateValueMap);
+
+    /**
+     * 获取条目能耗值map
+     *
+     * @param reportMonth    报告月份
+     * @param itemId         条目id
+     * @param modelCode      模型编码
+     * @param projectLocalId 项目本地编码
+     * @return 分项每月能耗信息{分项id:{时间(Date):数据(Double)}
+     * @author lixing
+     * @version V1.0 2021/5/30 11:39 上午
+     */
+    Map<String, TreeMap<Date, Double>> getItemEnergyDataMap(
+            Date reportMonth, String itemId, String modelCode, String projectLocalId);
+
+    /**
+     * 求一组用电量条目的统计值
+     *
+     * @param powerItems 一组用电量条目
+     * @return 一个新的用电量条目对象,将统计值属性赋值给它
+     * @author lixing
+     * @version V1.0 2021/5/30 10:46 上午
+     */
+    PowerItemVO getPowerSum(List<PowerItemVO> powerItems);
+
+    /**
+     * 获取用电量分组信息
+     *
+     * @param groupIdList 分组id列表
+     * @param reportMonth 报告月份
+     * @param projectIds  报告涉及的项目id列表
+     * @return 分组对象列表
+     * @author lixing
+     * @version V1.0 2021/5/24 7:12 下午
+     */
+    List<GroupInfo<PowerItemVO>> getPowerGroupInfos(List<String> groupIdList, Date reportMonth, List<String> projectIds);
+}

+ 19 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IReportOutlineService.java

@@ -47,6 +47,25 @@ public interface IReportOutlineService {
     void updateReportOutline(UpdateReportOutlineDTO updateReportOutlineDTO);
 
     /**
+     * 更新报告概要
+     *
+     * @param reportOutline 报告概要对象
+     * @author lixing
+     * @version V1.0 2021-05-17 11:09:37
+     */
+    void updateReportOutline(ReportOutline reportOutline);
+
+    /**
+     * 查询和报告类型相关的项目
+     *
+     * @param reportOutline 报告概要对象
+     * @return 项目id列表
+     * @author lixing
+     * @version V1.0 2021/5/30 8:48 下午
+     */
+    List<String> queryRelatedProjects(ReportOutline reportOutline);
+
+    /**
      * 批量删除报告概要
      *
      * @param ids 主键列表

+ 79 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessAreaReportGenerator.java

@@ -0,0 +1,79 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+import com.persagy.apm.energy.report.monthly.detail.business.model.*;
+import com.persagy.apm.energy.report.monthly.detail.business.model.dto.AddReportBusinessDetailDTO;
+import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
+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.monthly.outline.service.IBusinessReportCostInfoService;
+import com.persagy.apm.energy.report.monthly.outline.service.IBusinessReportPowerInfoService;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 商业项目报告生成类
+ *
+ * @author lixing
+ * @version V1.0 2021/5/12 2:53 下午
+ **/
+@Component
+@Slf4j
+public class BusinessAreaReportGenerator {
+    @Autowired
+    private IReportBusinessDetailService businessDetailService;
+    @Autowired
+    private IBusinessReportPowerInfoService businessReportPowerInfoService;
+    @Autowired
+    private IBusinessReportCostInfoService businessReportCostInfoService;
+    @Autowired
+    private BusinessReportPlatformInfoServiceImpl businessReportPlatformInfoService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+
+
+    /**
+     * 生成报告
+     *
+     * @param reportOutline 报告outline对象
+     * @author lixing
+     * @version V1.0 2021/5/24 4:09 下午
+     */
+    public void generateReport(ReportOutline reportOutline) {
+        try {
+            AddReportBusinessDetailDTO addReportBusinessDetailDTO = new AddReportBusinessDetailDTO();
+            // 获取在营项目用电量下拥有的信息点分组和信息点
+            List<String> powerGroupIdList = businessDetailService.getGroupsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+            List<String> powerFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+            OpenPower openPower = (OpenPower)businessReportPowerInfoService.getPowerInfo(reportOutline, powerGroupIdList, powerFunctionIdList);
+            ComparePower comparePower = (ComparePower)businessReportPowerInfoService.getComparePowerInfo(reportOutline, powerGroupIdList, powerFunctionIdList);
+            addReportBusinessDetailDTO.setOpenPower(openPower);
+            addReportBusinessDetailDTO.setComparePower(comparePower);
+
+            List<String> costGroupIdList = businessDetailService.getGroupsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+            List<String> costFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+            OpenCost openCost = (OpenCost)businessReportCostInfoService.getOpenCost(reportOutline, costGroupIdList, costFunctionIdList);
+            CompareCost compareCost = (CompareCost)businessReportCostInfoService.getCompareCost(reportOutline, costGroupIdList, costFunctionIdList);
+            addReportBusinessDetailDTO.setOpenCost(openCost);
+            addReportBusinessDetailDTO.setCompareCost(compareCost);
+
+            List<Platform> platforms = businessReportPlatformInfoService.getPlatforms(reportOutline);
+            addReportBusinessDetailDTO.setPlatform(platforms);
+
+            businessDetailService.createReportBusinessDetail(addReportBusinessDetailDTO);
+        } catch (Exception e) {
+            log.error("生成报告失败", e);
+            reportOutline.setStatus(ReportStateEnum.BUILD_FAILED.getType());
+            reportOutlineService.updateReportOutline(reportOutline);
+        }
+    }
+
+}

+ 78 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessProjectReportGenerator.java

@@ -0,0 +1,78 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+import com.persagy.apm.energy.report.monthly.detail.business.model.OpenCost;
+import com.persagy.apm.energy.report.monthly.detail.business.model.OpenPower;
+import com.persagy.apm.energy.report.monthly.detail.business.model.Platform;
+import com.persagy.apm.energy.report.monthly.detail.business.model.dto.AddReportBusinessDetailDTO;
+import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
+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.monthly.outline.service.IBusinessReportCostInfoService;
+import com.persagy.apm.energy.report.monthly.outline.service.IBusinessReportPowerInfoService;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 商业项目报告生成类
+ *
+ * @author lixing
+ * @version V1.0 2021/5/12 2:53 下午
+ **/
+@Component
+@Slf4j
+public class BusinessProjectReportGenerator {
+    @Autowired
+    private IReportBusinessDetailService businessDetailService;
+    @Autowired
+    private IBusinessReportPowerInfoService businessReportPowerInfoService;
+    @Autowired
+    private IBusinessReportCostInfoService businessReportCostInfoService;
+    @Autowired
+    private BusinessReportPlatformInfoServiceImpl businessReportPlatformInfoService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+
+
+    /**
+     * 生成报告
+     *
+     * @param reportOutline 报告outline对象
+     * @author lixing
+     * @version V1.0 2021/5/24 4:09 下午
+     */
+    public void generateReport(ReportOutline reportOutline) {
+        try {
+            AddReportBusinessDetailDTO addReportBusinessDetailDTO = new AddReportBusinessDetailDTO();
+            // 获取在营项目用电量下拥有的信息点分组和信息点
+            List<String> powerGroupIdList = businessDetailService.getGroupsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+            List<String> powerFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+            OpenPower openPower = (OpenPower)businessReportPowerInfoService.getPowerInfo(reportOutline, powerGroupIdList, powerFunctionIdList);
+            addReportBusinessDetailDTO.setOpenPower(openPower);
+
+            List<String> costGroupIdList = businessDetailService.getGroupsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+            List<String> costFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                    reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+            OpenCost openCost = (OpenCost)businessReportCostInfoService.getOpenCost(reportOutline, costGroupIdList, costFunctionIdList);
+            addReportBusinessDetailDTO.setOpenCost(openCost);
+
+            List<Platform> platforms = businessReportPlatformInfoService.getPlatforms(reportOutline);
+            addReportBusinessDetailDTO.setPlatform(platforms);
+
+            businessDetailService.createReportBusinessDetail(addReportBusinessDetailDTO);
+        } catch (Exception e) {
+            log.error("生成报告失败", e);
+            reportOutline.setStatus(ReportStateEnum.BUILD_FAILED.getType());
+            reportOutlineService.updateReportOutline(reportOutline);
+        }
+    }
+
+}

+ 246 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportCostInfoServiceImpl.java

@@ -0,0 +1,246 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+import com.persagy.apm.energy.report.common.utils.DataUtils;
+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.detail.business.model.vo.CostItemVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.GroupInfo;
+import com.persagy.apm.energy.report.monthly.functionvalue.service.IFunctionValueService;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
+import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
+import org.apache.commons.lang.StringUtils;
+import org.assertj.core.util.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 商业类报告费用service类
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 7:30 下午
+ **/
+@Service
+public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy.report.monthly.outline.service.IBusinessReportCostInfoService {
+    @Autowired
+    private IFunctionGroupService functionGroupService;
+    @Autowired
+    private IFunctionService functionService;
+    @Autowired
+    private IFunctionValueService functionValueService;
+    @Autowired
+    private ISaasWebService saasWebService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+
+    @Override
+    public CostVO getOpenCost(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList) {
+
+        Date reportMonth = reportOutline.getReportMonth();
+
+        List<String> projectIds = reportOutlineService.queryRelatedProjects(reportOutline);
+
+        return getCostInfoByProjectIds(groupIdList, functionIdList, reportMonth, projectIds);
+    }
+
+    @Override
+    public CostVO getCompareCost(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList) {
+
+        Date reportMonth = reportOutline.getReportMonth();
+
+        List<String> projectIds = reportOutlineService.queryRelatedProjects(reportOutline);
+
+        // TODO: 2021/5/30 过滤出去年一月份之前创建的项目
+        List<String> filteredProjectIds = new ArrayList<>();
+
+        return getCostInfoByProjectIds(groupIdList, functionIdList, reportMonth, filteredProjectIds);
+    }
+
+    /**
+     * 根据项目id获取费用信息
+     *
+     * @param groupIdList    费用信息点分组列表
+     * @param functionIdList 费用信息点列表
+     * @param reportMonth    报告月份
+     * @param projectIds     项目id列表
+     * @return 费用信息
+     * @author lixing
+     * @version V1.0 2021/5/30 11:41 下午
+     */
+    private CostVO getCostInfoByProjectIds(List<String> groupIdList, List<String> functionIdList, Date reportMonth, List<String> projectIds) {
+        CostVO costVO = new CostVO();
+        List<GroupInfo<CostItemVO>> costGroupInfos = getCostGroupInfos(groupIdList, reportMonth, projectIds);
+        costVO.setGroups(costGroupInfos);
+
+        List<CostItemVO> costItemInfos = getCostItemInfos(functionIdList, reportMonth, projectIds);
+        costVO.setItems(costItemInfos);
+
+        List<CostItemVO> paragraphSums = new ArrayList<>();
+
+        if (!CollectionUtils.isEmpty(costGroupInfos)) {
+            paragraphSums.addAll(
+                    costGroupInfos.stream().map(GroupInfo::getSummary).collect(Collectors.toList()));
+        }
+        if (!CollectionUtils.isEmpty(costItemInfos)) {
+            paragraphSums.addAll(costItemInfos);
+        }
+        costVO.setSummary(getCostSum(paragraphSums));
+        return costVO;
+    }
+
+
+    @Override
+    public List<CostItemVO> getCostItemInfos(List<String> functionIdList, Date reportMonth, List<String> projectIds) {
+        List<CostItemVO> costItemVOList = Lists.newArrayList();
+        if (CollectionUtils.isEmpty(functionIdList) || CollectionUtils.isEmpty(projectIds)) {
+            return costItemVOList;
+        }
+
+        for (String functionId : functionIdList) {
+            Function function = functionService.queryFunctionDetail(functionId);
+            String itemName = functionService.getItemName(function, projectIds.get(0));
+
+            List<CostItemVO> projectCostItems = getCostItemsByProjects(reportMonth, projectIds, function);
+            CostItemVO costSumByProjects = getCostSum(projectCostItems);
+            costSumByProjects.setName(itemName);
+            costItemVOList.add(costSumByProjects);
+        }
+        return costItemVOList;
+    }
+
+    @Override
+    public List<CostItemVO> getCostItemsByProjects(Date reportMonth, List<String> projectIds, Function function) {
+        List<CostItemVO> projectCostItems = Lists.newArrayList();
+        if (CollectionUtils.isEmpty(projectIds)) {
+            return projectCostItems;
+        }
+        for (String projectId : projectIds) {
+            // 获取项目信息
+            ReportProjectVO reportProjectInfo = saasWebService.getReportProjectInfo(projectId);
+            if (reportProjectInfo == null) {
+                continue;
+            }
+            CostItemVO costItemVO = getCostItemInfo(reportMonth, reportProjectInfo, function.getId());
+            projectCostItems.add(costItemVO);
+        }
+        return projectCostItems;
+    }
+
+    @Override
+    public CostItemVO getCostItemInfo(Date reportMonth, ReportProjectVO reportProjectInfo, String functionId) {
+        String projectId = reportProjectInfo.getProjectId();
+        CostItemVO costItemVO = new CostItemVO();
+        String currentMonthStr = functionValueService.getFunctionValue(functionId, reportMonth, projectId);
+        Double currentMonth = null;
+        if (StringUtils.isNotBlank(currentMonthStr)) {
+            currentMonth = Double.valueOf(currentMonthStr);
+            costItemVO.setCurrentMonth(currentMonth);
+        }
+        String lastMonthStr = functionValueService.getFunctionValue(
+                functionId, DateUtils.getFirstDayOfLastMonth(reportMonth), projectId);
+        Double lastMonth = null;
+        if (StringUtils.isNotBlank(lastMonthStr)) {
+            lastMonth = Double.valueOf(lastMonthStr);
+            costItemVO.setLastMonth(lastMonth);
+        }
+
+        // 统计去年的费用
+        Double lastYearCount = null;
+        List<Date> lastYearMonths = DateUtils.getFirstDayOfEveryMonth(
+                DateUtils.getFirstDayOfLastYear(reportMonth),
+                DateUtils.getDecemberFirstDayOfLastYear(reportMonth));
+        List<CostItemVO> lastYearItems = new ArrayList<>();
+        for (Date lastYearMonth : lastYearMonths) {
+            CostItemVO tmp = new CostItemVO();
+            String monthValue = functionValueService.getFunctionValue(functionId, lastYearMonth, projectId);
+            if (StringUtils.isNotBlank(monthValue)) {
+                tmp.setLastYearCount(Double.parseDouble(monthValue));
+                lastYearItems.add(tmp);
+            }
+        }
+        CostItemVO lastYearSumItem = getCostSum(lastYearItems);
+        if (lastYearSumItem != null) {
+            lastYearCount = lastYearSumItem.getLastYearCount();
+            costItemVO.setLastYearCount(lastYearCount);
+            if (StringUtils.isNotBlank(reportProjectInfo.getCommercialArea())) {
+                costItemVO.setLastYearPerCount(lastYearCount / Double.parseDouble(reportProjectInfo.getCommercialArea()));
+            }
+        }
+
+        // 统计今年的费用
+        Double yearCount = null;
+        List<Date> yearMonths = DateUtils.getFirstDayOfEveryMonth(
+                DateUtils.getFirstDayOfYear(reportMonth),
+                reportMonth);
+        List<CostItemVO> yearItems = new ArrayList<>();
+        for (Date yearMonth : yearMonths) {
+            CostItemVO tmp = new CostItemVO();
+            String monthValue = functionValueService.getFunctionValue(functionId, yearMonth, projectId);
+            if (StringUtils.isNotBlank(monthValue)) {
+                tmp.setYearCount(Double.parseDouble(monthValue));
+                lastYearItems.add(tmp);
+            }
+        }
+        CostItemVO yearSumItem = getCostSum(yearItems);
+        if (yearSumItem != null) {
+            yearCount = yearSumItem.getYearCount();
+            costItemVO.setYearCount(yearCount);
+            if (StringUtils.isNotBlank(reportProjectInfo.getCommercialArea())) {
+                costItemVO.setYearPerCount(yearCount / Double.parseDouble(reportProjectInfo.getCommercialArea()));
+            }
+        }
+
+        if (currentMonth != null && lastMonth != null) {
+            Double linkCount = currentMonth - lastMonth;
+            Double linkRange = linkCount / lastMonth;
+            costItemVO.setLinkCount(linkCount);
+            costItemVO.setLinkRange(linkRange);
+        }
+
+        if (lastYearCount != null && yearCount != null) {
+            double sameCount = yearCount - lastYearCount;
+            costItemVO.setSameCount(sameCount);
+            costItemVO.setSameRange(sameCount / lastYearCount);
+        }
+        return costItemVO;
+    }
+
+
+    @Override
+    public CostItemVO getCostSum(List<CostItemVO> costItems) {
+        return DataUtils.sumDoubleParams(costItems, CostItemVO.class);
+    }
+
+
+    @Override
+    public List<GroupInfo<CostItemVO>> getCostGroupInfos(List<String> groupIdList, Date reportMonth, List<String> projectIds) {
+        List<GroupInfo<CostItemVO>> groupInfoList = Lists.newArrayList();
+        if (CollectionUtils.isEmpty(groupIdList)) {
+            return groupInfoList;
+        }
+        for (String groupId : groupIdList) {
+            GroupInfo<CostItemVO> groupInfo = new GroupInfo<>();
+            FunctionGroup functionGroup = functionGroupService.queryFunctionGroupDetail(groupId);
+            groupInfo.setGroupName(functionGroup.getName());
+            // 获取组下的分组(本期不做)
+            // 获取组下的分项
+            String functionIdStr = functionGroup.getFunctionIds();
+            List<String> functionIds = Lists.newArrayList(functionIdStr.split(","));
+            List<CostItemVO> costItemInfos = getCostItemInfos(functionIds, reportMonth, projectIds);
+            groupInfo.setItems(costItemInfos);
+            groupInfo.setSummary(getCostSum(costItemInfos));
+        }
+        return groupInfoList;
+    }
+}

+ 84 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportPlatformInfoServiceImpl.java

@@ -0,0 +1,84 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+import com.persagy.apm.common.context.poems.PoemsContext;
+import com.persagy.apm.energy.report.common.dto.QueryAreaPlatformParamDTO;
+import com.persagy.apm.energy.report.common.service.CommonService;
+import com.persagy.apm.energy.report.monthly.config.rel.typestatisticsitem.model.ReportTypeStatisticsItemRel;
+import com.persagy.apm.energy.report.monthly.config.rel.typestatisticsitem.model.dto.QueryReportTypeStatisticsItemRelDTO;
+import com.persagy.apm.energy.report.monthly.config.rel.typestatisticsitem.service.IReportTypeStatisticsItemRelService;
+import com.persagy.apm.energy.report.monthly.config.statisticsitems.model.StatisticItems;
+import com.persagy.apm.energy.report.monthly.config.statisticsitems.model.dto.QueryStatisticItemsDTO;
+import com.persagy.apm.energy.report.monthly.config.statisticsitems.service.IStatisticItemsService;
+import com.persagy.apm.energy.report.monthly.detail.business.model.Platform;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import org.assertj.core.util.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 商业类报告平台运维信息service类
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 10:22 下午
+ **/
+public class BusinessReportPlatformInfoServiceImpl {
+    @Autowired
+    private IReportTypeStatisticsItemRelService reportTypeStatisticsItemRelService;
+    @Autowired
+    private IStatisticItemsService statisticItemsService;
+    @Autowired
+    private CommonService commonService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+
+    /**
+     * 获取报告平台运维信息
+     *
+     * @param reportOutline 报告概要
+     * @return 平台运维信息点信息列表
+     * @author lixing
+     * @version V1.0 2021/5/30 10:47 下午
+     */
+    public List<Platform> getPlatforms(ReportOutline reportOutline) {
+        // 查询报告类型关联的统计条目
+        QueryReportTypeStatisticsItemRelDTO queryReportTypeStatisticsItemRelDTO = new QueryReportTypeStatisticsItemRelDTO();
+        queryReportTypeStatisticsItemRelDTO.setReportTypeId(reportOutline.getReportTypeId());
+        List<ReportTypeStatisticsItemRel> reportTypeStatisticsItemRels = reportTypeStatisticsItemRelService.
+                queryReportTypeStatisticsItemRelList(queryReportTypeStatisticsItemRelDTO);
+        if (CollectionUtils.isEmpty(reportTypeStatisticsItemRels)) {
+            return Lists.newArrayList();
+        }
+        List<String> statisticItemIds = reportTypeStatisticsItemRels.stream().
+                map(ReportTypeStatisticsItemRel::getStatisticsItemId).
+                collect(Collectors.toList());
+
+        // 查询条目对象
+        QueryStatisticItemsDTO queryStatisticItemsDTO = new QueryStatisticItemsDTO();
+        queryStatisticItemsDTO.setStatisticItemIdList(statisticItemIds);
+        List<StatisticItems> statisticItemList = statisticItemsService.queryStatisticItemsList(queryStatisticItemsDTO);
+        if (CollectionUtils.isEmpty(statisticItemList)) {
+            return Lists.newArrayList();
+        }
+
+        // 获取报告关联的项目
+        List<String> projectIds = reportOutlineService.queryRelatedProjects(reportOutline);
+
+        // 拼装运维信息查询条件
+        QueryAreaPlatformParamDTO queryAreaPlatformParamDTO = new QueryAreaPlatformParamDTO();
+        queryAreaPlatformParamDTO.setReportDate(reportOutline.getReportMonth());
+        queryAreaPlatformParamDTO.setProjectIdList(projectIds);
+        queryAreaPlatformParamDTO.setUserId(PoemsContext.getContext().getUserId());
+
+        List<Platform> result = new ArrayList<>();
+        for (StatisticItems statisticItems : statisticItemList) {
+            result.add(commonService.getPlatform(statisticItems, queryAreaPlatformParamDTO));
+        }
+
+        return result;
+    }
+}

+ 253 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportPowerInfoServiceImpl.java

@@ -0,0 +1,253 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+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.service.ICenterMiddlewareWebService;
+import com.persagy.apm.energy.report.common.utils.DataUtils;
+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.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.model.vo.PowerVO;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
+import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
+import org.assertj.core.util.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 商业类报告用电量service类
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 7:30 下午
+ **/
+@Service
+public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energy.report.monthly.outline.service.IBusinessReportPowerInfoService {
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+    @Autowired
+    private IFunctionGroupService functionGroupService;
+    @Autowired
+    private IFunctionService functionService;
+    @Autowired
+    private ICenterMiddlewareWebService centerMiddlewareWebService;
+    @Autowired
+    private ISaasWebService saasWebService;
+
+    @Override
+    public PowerVO getPowerInfo(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList) {
+        Date reportMonth = reportOutline.getReportMonth();
+
+        List<String> projectIds = reportOutlineService.queryRelatedProjects(reportOutline);
+
+        return getPowerInfoByProjectIds(groupIdList, functionIdList, reportMonth, projectIds);
+    }
+
+    @Override
+    public PowerVO getComparePowerInfo(ReportOutline reportOutline, List<String> groupIdList, List<String> functionIdList) {
+        Date reportMonth = reportOutline.getReportMonth();
+
+        List<String> projectIds = reportOutlineService.queryRelatedProjects(reportOutline);
+
+        // TODO: 2021/5/30 过滤出去年一月份之前创建的项目
+        List<String> filteredProjectIds = new ArrayList<>();
+
+        return getPowerInfoByProjectIds(groupIdList, functionIdList, reportMonth, filteredProjectIds);
+    }
+
+    /**
+     * 根据项目id获取用电信息
+     *
+     * @param groupIdList    费用信息点分组列表
+     * @param functionIdList 费用信息点列表
+     * @param reportMonth    报告月份
+     * @param projectIds     项目id列表
+     * @return 用电信息
+     * @author lixing
+     * @version V1.0 2021/5/30 11:41 下午
+     */
+    private PowerVO getPowerInfoByProjectIds(
+            List<String> groupIdList, List<String> functionIdList,
+            Date reportMonth, List<String> projectIds) {
+        PowerVO powerVO = new PowerVO();
+        List<GroupInfo<PowerItemVO>> powerGroupInfos = getPowerGroupInfos(groupIdList, reportMonth, projectIds);
+        powerVO.setGroups(powerGroupInfos);
+
+        List<PowerItemVO> powerItemInfos = getPowerItemInfos(functionIdList, reportMonth, projectIds);
+        powerVO.setItems(powerItemInfos);
+
+        List<PowerItemVO> paragraphSums = new ArrayList<>();
+
+        if (!CollectionUtils.isEmpty(powerGroupInfos)) {
+            paragraphSums.addAll(
+                    powerGroupInfos.stream().map(GroupInfo::getSummary).collect(Collectors.toList()));
+        }
+        if (!CollectionUtils.isEmpty(powerItemInfos)) {
+            paragraphSums.addAll(powerItemInfos);
+        }
+        powerVO.setSummary(getPowerSum(paragraphSums));
+        return powerVO;
+    }
+
+    @Override
+    public 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 = functionService.getItemName(function, projectIds.get(0));
+
+            List<PowerItemVO> projectPowerItems = getPowerItemsByProjects(reportMonth, projectIds, function);
+            PowerItemVO powerSumByProjects = getPowerSum(projectPowerItems);
+            powerSumByProjects.setName(itemName);
+            powerItemVOList.add(powerSumByProjects);
+        }
+        return powerItemVOList;
+    }
+
+    @Override
+    public List<PowerItemVO> getPowerItemsByProjects(Date reportMonth, List<String> projectIds, Function function) {
+        List<PowerItemVO> projectPowerItems = Lists.newArrayList();
+        if (CollectionUtils.isEmpty(projectIds)) {
+            return projectPowerItems;
+        }
+
+        // 统计项目总的商业面积
+        Double totalCommercialArea = saasWebService.getTotalCommercialArea(projectIds);
+
+        for (String projectId : projectIds) {
+            // 获取项目信息
+            ReportProjectVO reportProjectInfo = saasWebService.getReportProjectInfo(projectId);
+            if (reportProjectInfo == null) {
+                continue;
+            }
+            Map<String, TreeMap<Date, Double>> itemEnergyDataMap = getItemEnergyDataMap(
+                    reportMonth, function.getItemId(), function.getModelCode(), reportProjectInfo.getProjectLocalID());
+            TreeMap<Date, Double> dateValueMap = itemEnergyDataMap.get(function.getItemId());
+            if (dateValueMap != null) {
+                PowerItemVO powerItemInfo = getPowerItemInfo(reportMonth, totalCommercialArea, dateValueMap);
+                projectPowerItems.add(powerItemInfo);
+            }
+        }
+        return projectPowerItems;
+    }
+
+    @Override
+    public PowerItemVO getPowerItemInfo(Date reportMonth, Double totalCommercialArea, TreeMap<Date, Double> dateValueMap) {
+        PowerItemVO powerItemVO = new PowerItemVO();
+        Double currentMonth = dateValueMap.get(reportMonth);
+        powerItemVO.setCurrentMonth(currentMonth);
+        Double lastMonth = dateValueMap.get(DateUtils.getFirstDayOfLastMonth(reportMonth));
+        powerItemVO.setLastMonth(lastMonth);
+
+        // 统计去年的用电量
+        Double lastYearCount = null;
+        List<Date> lastYearMonths = DateUtils.getFirstDayOfEveryMonth(
+                DateUtils.getFirstDayOfLastYear(reportMonth),
+                DateUtils.getDecemberFirstDayOfLastYear(reportMonth));
+        List<PowerItemVO> lastYearItems = new ArrayList<>();
+        for (Date lastYearMonth : lastYearMonths) {
+            PowerItemVO tmp = new PowerItemVO();
+            tmp.setLastYearCount(dateValueMap.get(lastYearMonth));
+            lastYearItems.add(tmp);
+        }
+        PowerItemVO lastYearSumItem = getPowerSum(lastYearItems);
+        if (lastYearSumItem != null) {
+            lastYearCount = lastYearSumItem.getLastYearCount();
+            powerItemVO.setLastYearCount(lastYearCount);
+            if (totalCommercialArea != null) {
+                powerItemVO.setLastYearPerCount(lastYearCount / totalCommercialArea);
+            }
+        }
+
+        // 统计今年的用电量
+        Double yearCount = null;
+        List<Date> yearMonths = DateUtils.getFirstDayOfEveryMonth(
+                DateUtils.getFirstDayOfYear(reportMonth),
+                reportMonth);
+        List<PowerItemVO> yearItems = new ArrayList<>();
+        for (Date yearMonth : yearMonths) {
+            PowerItemVO tmp = new PowerItemVO();
+            tmp.setYearCount(dateValueMap.get(yearMonth));
+            yearItems.add(tmp);
+        }
+        PowerItemVO yearSumItem = getPowerSum(yearItems);
+        if (yearSumItem != null) {
+            yearCount = yearSumItem.getYearCount();
+            powerItemVO.setYearCount(yearCount);
+            if (totalCommercialArea != null) {
+                powerItemVO.setYearPerCount(yearCount / totalCommercialArea);
+            }
+        }
+
+        if (currentMonth != null && lastMonth != null) {
+            Double linkCount = currentMonth - lastMonth;
+            Double linkRange = linkCount / lastMonth;
+            powerItemVO.setLinkCount(linkCount);
+            powerItemVO.setLinkRange(linkRange);
+        }
+
+        if (lastYearCount != null && yearCount != null) {
+            double sameCount = yearCount - lastYearCount;
+            powerItemVO.setSameCount(sameCount);
+            powerItemVO.setSameRange(sameCount / lastYearCount);
+        }
+        return powerItemVO;
+    }
+
+    @Override
+    public Map<String, TreeMap<Date, Double>> getItemEnergyDataMap(
+            Date reportMonth, String itemId, String modelCode, String projectLocalId) {
+        QueryEnergyDataDTO queryEnergyDataDTO = new QueryEnergyDataDTO();
+        queryEnergyDataDTO.setProjectId(projectLocalId);
+        queryEnergyDataDTO.setBuildingId(projectLocalId);
+        queryEnergyDataDTO.setModelCode(modelCode);
+        // 去年一月
+        queryEnergyDataDTO.setStartDate(DateUtils.date2Str(
+                DateUtils.getFirstDayOfLastYear(reportMonth), DateUtils.SDF_SECOND));
+        queryEnergyDataDTO.setEndDate(DateUtils.date2Str(reportMonth, DateUtils.SDF_SECOND));
+        queryEnergyDataDTO.setItemIdList(Lists.newArrayList(itemId));
+        queryEnergyDataDTO.setTimeType(TimeTypeEnum.MONTH.getType());
+        return centerMiddlewareWebService.getItemEnergyDataMap(queryEnergyDataDTO);
+    }
+
+    @Override
+    public PowerItemVO getPowerSum(List<PowerItemVO> powerItems) {
+        return DataUtils.sumDoubleParams(powerItems, PowerItemVO.class);
+    }
+
+    @Override
+    public 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);
+            groupInfo.setSummary(getPowerSum(powerItemInfos));
+        }
+        return groupInfoList;
+    }
+
+
+}

+ 8 - 249
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/GenerateReportThreadPool.java

@@ -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;
-    }
-
-
 }

+ 31 - 6
src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/ReportOutlineServiceImpl.java

@@ -20,6 +20,7 @@ import com.persagy.apm.energy.report.monthly.outline.model.dto.PageQueryReportOu
 import com.persagy.apm.energy.report.monthly.outline.model.dto.QueryReportOutlineDTO;
 import com.persagy.apm.energy.report.monthly.outline.model.dto.UpdateReportOutlineDTO;
 import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import com.persagy.apm.energy.report.saasweb.model.vo.PoemsProjectVO;
 import com.persagy.apm.energy.report.saasweb.model.vo.ReportAreaVO;
 import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
 import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
@@ -29,8 +30,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 报告概要(ReportOutline) service层
@@ -117,12 +120,6 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
         return reportOutline;
     }
 
-    /**
-     * 更新报告概要
-     *
-     * @author lixing
-     * @version V1.0 2021-05-17 11:09:37
-     */
     @Override
     public void updateReportOutline(UpdateReportOutlineDTO updateReportOutlineDTO) {
         ReportOutline reportOutline = getById(updateReportOutlineDTO.getId());
@@ -131,6 +128,12 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
         updateById(reportOutline);
     }
 
+    @Override
+    public void updateReportOutline(ReportOutline reportOutline) {
+        reportOutline.setModifier(PoemsContext.getContext().getUserId());
+        updateById(reportOutline);
+    }
+
     /**
      * 校验报告概要是否可删除
      *
@@ -262,4 +265,26 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
 
         return getBaseMapper().selectPage(pageParam, queryWrapper);
     }
+
+    @Override
+    public List<String> queryRelatedProjects(ReportOutline reportOutline) {
+        String reportTypeId = reportOutline.getReportTypeId();
+
+        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()));
+            }
+        }
+        return projectIds;
+    }
 }

+ 10 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java

@@ -33,6 +33,16 @@ public interface ISaasWebService {
     ReportProjectVO getReportProjectInfo(String projectId);
 
     /**
+     * 获取一组项目的总的商业面值
+     *
+     * @param projectIds 一组项目id
+     * @return 这组项目总的商业面积
+     * @author lixing
+     * @version V1.0 2021/5/30 11:28 下午
+     */
+    Double getTotalCommercialArea(List<String> projectIds);
+
+    /**
      * 获取区域信息
      *
      * @param areaCode 区域编码

+ 14 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java

@@ -514,4 +514,18 @@ public class SaasWebServiceImpl implements ISaasWebService {
         return result;
     }
 
+    @Override
+    public Double getTotalCommercialArea(List<String> projectIds) {
+        if (CollectionUtils.isEmpty(projectIds)) {
+            return 0d;
+        }
+
+        BigDecimal result = new BigDecimal("0");
+        for (String projectId : projectIds) {
+            ReportProjectVO projectAreas = getProjectAreas(projectId);
+            String commercialArea = projectAreas.getCommercialArea();
+            result = result.add(new BigDecimal(commercialArea));
+        }
+        return result.doubleValue();
+    }
 }

+ 1 - 1
src/main/resources/mapper/ReportBusinessDetailMapper.xml

@@ -4,7 +4,7 @@
     <resultMap id="ReportBusinessDetailMap"
                type="com.persagy.apm.energy.report.monthly.detail.business.model.ReportBusinessDetail">
         <result column="id" property="id"/>
-        <result column="open_power" property="openPower"
+        <result column="open_power" property="powerVO"
                 typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
         <result column="open_power_explain" property="openPowerExplain"/>
         <result column="compare_power" property="comparePower"