浏览代码

生成报告代码开发

lixing 3 年之前
父节点
当前提交
144c81cac9
共有 34 个文件被更改,包括 585 次插入307 次删除
  1. 0 4
      src/main/java/com/persagy/apm/energy/report/monthly/config/functiongroup/model/FunctionGroup.java
  2. 0 8
      src/main/java/com/persagy/apm/energy/report/monthly/config/functiongroup/service/impl/FunctionGroupServiceImpl.java
  3. 4 20
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/controller/ReportBusinessDetailController.java
  4. 0 17
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/CompareCost.java
  5. 0 16
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/ComparePower.java
  6. 0 16
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/OpenCost.java
  7. 0 16
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/OpenPower.java
  8. 6 4
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/ReportBusinessDetail.java
  9. 8 5
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/AddReportBusinessDetailDTO.java
  10. 3 7
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/GetReportBusinessDetailDTO.java
  11. 8 10
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/UpdateReportBusinessDetailDTO.java
  12. 10 10
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/CostItemVO.java
  13. 5 4
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/ResponseReportBusinessDetailItemVO.java
  14. 14 9
      src/main/java/com/persagy/apm/energy/report/monthly/detail/business/service/impl/ReportBusinessDetailServiceImpl.java
  15. 25 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/constants/enums/ReportStateEnum.java
  16. 32 1
      src/main/java/com/persagy/apm/energy/report/monthly/outline/controller/ReportOutlineController.java
  17. 0 2
      src/main/java/com/persagy/apm/energy/report/monthly/outline/model/dto/PageQueryReportOutlineDTO.java
  18. 4 1
      src/main/java/com/persagy/apm/energy/report/monthly/outline/model/vo/ResponseReportOutlineListItemVO.java
  19. 107 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportBuilder.java
  20. 8 5
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IBusinessReportCostInfoService.java
  21. 11 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/IReportOutlineService.java
  22. 5 52
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessAreaReportGenerator.java
  23. 11 49
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessProjectReportGenerator.java
  24. 132 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportBuilder.java
  25. 16 8
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportCostInfoServiceImpl.java
  26. 14 10
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/BusinessReportPowerInfoServiceImpl.java
  27. 5 0
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/GenerateReportThreadPool.java
  28. 60 5
      src/main/java/com/persagy/apm/energy/report/monthly/outline/service/impl/ReportOutlineServiceImpl.java
  29. 2 0
      src/main/java/com/persagy/apm/energy/report/saasweb/model/vo/PoemsProjectVO.java
  30. 2 0
      src/main/java/com/persagy/apm/energy/report/saasweb/model/vo/SimpleProjectVO.java
  31. 16 3
      src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java
  32. 76 23
      src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java
  33. 0 1
      src/main/resources/mapper/FunctionGroupMapper.xml
  34. 1 1
      src/main/resources/mapper/FunctionValueMapper.xml

+ 0 - 4
src/main/java/com/persagy/apm/energy/report/monthly/config/functiongroup/model/FunctionGroup.java

@@ -30,13 +30,9 @@ public class FunctionGroup extends AuditableEntity<FunctionGroup> implements Ser
     @ApiModelProperty("包含的信息点id")
     private String functionIds;
 
-    @ApiModelProperty("所属段落(如果不直属段落,这里不填)")
-    private String belongParagraph;
-
 
     public static String PROP_NAME = "name";
     public static String PROP_GROUP_IDS = "group_ids";
     public static String PROP_FUNCTION_IDS = "function_ids";
-    public static String PROP_BELONG_PARAGRAPH = "belong_paragraph";
 
 }

+ 0 - 8
src/main/java/com/persagy/apm/energy/report/monthly/config/functiongroup/service/impl/FunctionGroupServiceImpl.java

@@ -158,10 +158,6 @@ public class FunctionGroupServiceImpl extends ServiceImpl<FunctionGroupMapper, F
                 queryWrapper.like(FunctionGroup.PROP_FUNCTION_IDS, queryFunctionGroupDTO.getFunctionIds());
             }
 
-            // todo 需判断使用like还是eq
-            if (StringUtils.isNotEmpty(queryFunctionGroupDTO.getBelongParagraph())) {
-                queryWrapper.like(FunctionGroup.PROP_BELONG_PARAGRAPH, queryFunctionGroupDTO.getBelongParagraph());
-            }
 
         }
 
@@ -209,10 +205,6 @@ public class FunctionGroupServiceImpl extends ServiceImpl<FunctionGroupMapper, F
             queryWrapper.like(FunctionGroup.PROP_FUNCTION_IDS, pageQueryFunctionGroupDTO.getFunctionIds());
         }
 
-        // todo 需判断使用like还是eq
-        if (StringUtils.isNotEmpty(pageQueryFunctionGroupDTO.getBelongParagraph())) {
-            queryWrapper.like(FunctionGroup.PROP_BELONG_PARAGRAPH, pageQueryFunctionGroupDTO.getBelongParagraph());
-        }
 
         return getBaseMapper().selectPage(pageParam, queryWrapper);
     }

+ 4 - 20
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/controller/ReportBusinessDetailController.java

@@ -8,6 +8,9 @@ import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.mod
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.QueryReportDetailStatisticsItemRelDTO;
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.vo.ResponseReportDetailStatisticsItemRelListItemVO;
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.service.IReportDetailStatisticsItemRelService;
+import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
+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.ConvertReportBusinessDetailTool;
 import com.persagy.apm.energy.report.monthly.detail.business.model.ReportBusinessDetail;
 import com.persagy.apm.energy.report.monthly.detail.business.model.dto.GetReportBusinessDetailDTO;
@@ -39,8 +42,6 @@ import java.util.List;
 public class ReportBusinessDetailController {
     @Autowired
     private IReportBusinessDetailService reportBusinessDetailService;
-    @Autowired
-    private IReportDetailStatisticsItemRelService reportDetailStatisticsItemRelService;
 
     //    @ApiOperation(value = "创建报告详情")
     //    @PostMapping("/create")
@@ -50,30 +51,13 @@ public class ReportBusinessDetailController {
     //        return ResultHelper.single(new ApmResponseUpsertVO(id));
     //    }
 
-    @ApiOperation(value = "查看报告详情")
-    @PostMapping("/get")
-    public CommonResult<ResponseReportBusinessDetailItemVO> getReportBusinessDetail(
-            @Valid @RequestBody GetReportBusinessDetailDTO getReportBusinessDetailDTO) {
-        ReportBusinessDetail reportBusinessDetail = reportBusinessDetailService.getReportBusinessDetail(getReportBusinessDetailDTO.getId());
-        ResponseReportBusinessDetailItemVO responseReportBusinessDetailItemVO = ConvertReportBusinessDetailTool.INSTANCE.convert2ResponseItemDTO(reportBusinessDetail);
-        // 查询统计条目补充信息
-        QueryReportDetailStatisticsItemRelDTO queryReportDetailStatisticsItemRelDTO = new QueryReportDetailStatisticsItemRelDTO();
-        queryReportDetailStatisticsItemRelDTO.setReportDetailId(getReportBusinessDetailDTO.getId());
-        queryReportDetailStatisticsItemRelDTO.setReportTypeId(getReportBusinessDetailDTO.getReportTypeId());
-        List<ReportDetailStatisticsItemRel> reportDetailStatisticsItemRels = reportDetailStatisticsItemRelService.queryReportDetailStatisticsItemRelList(queryReportDetailStatisticsItemRelDTO);
-        List<ResponseReportDetailStatisticsItemRelListItemVO> responseReportDetailStatisticsItemRelListItemVOList = ConvertReportDetailStatisticsItemRelTool.INSTANCE.convert2List(reportDetailStatisticsItemRels);
-        responseReportBusinessDetailItemVO.setStatisticItemsSupplements(responseReportDetailStatisticsItemRelListItemVOList);
-
-        return ResultHelper.single(responseReportBusinessDetailItemVO);
-    }
-
 
     @ApiOperation(value = "更新报告详情")
     @PostMapping("/update")
     public CommonResult<ApmResponseUpsertVO> updateReportBusinessDetail(
             @Valid @RequestBody UpdateReportBusinessDetailDTO updateReportBusinessDetailDTO) {
         reportBusinessDetailService.updateReportBusinessDetail(updateReportBusinessDetailDTO);
-        return ResultHelper.single(new ApmResponseUpsertVO(updateReportBusinessDetailDTO.getId()));
+        return ResultHelper.single(new ApmResponseUpsertVO(updateReportBusinessDetailDTO.getReportOutlineId()));
     }
 
 

+ 0 - 17
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/CompareCost.java

@@ -1,17 +0,0 @@
-package com.persagy.apm.energy.report.monthly.detail.business.model;
-
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * @author lixing
- * @version V1.0 2021/5/17 3:15 下午
- **/
-@EqualsAndHashCode(callSuper = true)
-@Data
-@ApiModel(value = "可同比项目能源费")
-public class CompareCost extends CostVO {
-}

+ 0 - 16
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/ComparePower.java

@@ -1,16 +0,0 @@
-package com.persagy.apm.energy.report.monthly.detail.business.model;
-
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
-import io.swagger.annotations.ApiModel;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * @author lixing
- * @version V1.0 2021/5/17 3:15 下午
- **/
-@EqualsAndHashCode(callSuper = true)
-@Data
-@ApiModel(value = "可同比项目用电量")
-public class ComparePower extends PowerVO {
-}

+ 0 - 16
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/OpenCost.java

@@ -1,16 +0,0 @@
-package com.persagy.apm.energy.report.monthly.detail.business.model;
-
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
-import io.swagger.annotations.ApiModel;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * @author lixing
- * @version V1.0 2021/5/17 3:15 下午
- **/
-@EqualsAndHashCode(callSuper = true)
-@Data
-@ApiModel(value = "在营项目能源费")
-public class OpenCost extends CostVO {
-}

+ 0 - 16
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/OpenPower.java

@@ -1,16 +0,0 @@
-package com.persagy.apm.energy.report.monthly.detail.business.model;
-
-import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
-import io.swagger.annotations.ApiModel;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * @author lixing
- * @version V1.0 2021/5/17 3:15 下午
- **/
-@EqualsAndHashCode(callSuper = true)
-@Data
-@ApiModel(value = "在营项目用电量")
-public class OpenPower extends PowerVO {
-}

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

@@ -4,6 +4,8 @@ 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 com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -27,28 +29,28 @@ public class ReportBusinessDetail extends AuditableEntity<ReportBusinessDetail>
 
     @ApiModelProperty("在营项目用电量数据对象信息,项目月报使用此字段")
     @TableField(typeHandler = FastjsonTypeHandler.class)
-    private OpenPower openPower;
+    private PowerVO openPower;
 
     @ApiModelProperty("在营项目用电情况说明")
     private String openPowerExplain;
 
     @ApiModelProperty("可同比项目用电量数据对象信息")
     @TableField(typeHandler = FastjsonTypeHandler.class)
-    private ComparePower comparePower;
+    private PowerVO comparePower;
 
     @ApiModelProperty("可同比项目用电情况说明")
     private String comparePowerExplain;
 
     @ApiModelProperty("在营项目能源费数据对象信息,项目月报使用此字段")
     @TableField(typeHandler = FastjsonTypeHandler.class)
-    private OpenCost openCost;
+    private CostVO openCost;
 
     @ApiModelProperty("在营项目费用说明")
     private String openCostExplain;
 
     @ApiModelProperty("可同比项目能源费数据对象信息")
     @TableField(typeHandler = FastjsonTypeHandler.class)
-    private CompareCost compareCost;
+    private CostVO compareCost;
 
     @ApiModelProperty("可同比项目费用说明")
     private String compareCostExplain;

+ 8 - 5
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/AddReportBusinessDetailDTO.java

@@ -1,7 +1,10 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.dto;
 
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.AddReportDetailStatisticsItemRelDTO;
-import com.persagy.apm.energy.report.monthly.detail.business.model.*;
+import com.persagy.apm.energy.report.monthly.detail.business.model.Job;
+import com.persagy.apm.energy.report.monthly.detail.business.model.Platform;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -16,25 +19,25 @@ import java.util.List;
 @ApiModel(value = "创建报告详情入参")
 public class AddReportBusinessDetailDTO {
     @ApiModelProperty(value = "在营项目用电量数据对象信息,项目月报使用此字段")
-    private OpenPower openPower;
+    private PowerVO openPower;
 
     @ApiModelProperty(value = "在营项目用电情况说明")
     private String openPowerExplain;
 
     @ApiModelProperty(value = "可同比项目用电量数据对象信息")
-    private ComparePower comparePower;
+    private PowerVO comparePower;
 
     @ApiModelProperty(value = "可同比项目用电情况说明")
     private String comparePowerExplain;
 
     @ApiModelProperty(value = "在营项目能源费数据对象信息,项目月报使用此字段")
-    private OpenCost openCost;
+    private CostVO openCost;
 
     @ApiModelProperty(value = "在营项目费用说明")
     private String openCostExplain;
 
     @ApiModelProperty(value = "可同比项目能源费数据对象信息")
-    private CompareCost compareCost;
+    private CostVO compareCost;
 
     @ApiModelProperty(value = "可同比项目费用说明")
     private String compareCostExplain;

+ 3 - 7
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/GetReportBusinessDetailDTO.java

@@ -13,11 +13,7 @@ import javax.validation.constraints.NotNull;
 @Data
 @ApiModel(value = "获取报告详情详情入参")
 public class GetReportBusinessDetailDTO {
-    @NotNull(message = "主键不能为空")
-    @ApiModelProperty(value = "主键", required = true)
-    private String id;
-
-    @NotNull(message = "报告类型id不能为空")
-    @ApiModelProperty(value = "报告类型id", required = true)
-    private String reportTypeId;
+    @NotNull(message = "报告主键不能为空")
+    @ApiModelProperty(value = "报告主键", required = true)
+    private String reportOutlineId;
 }

+ 8 - 10
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/dto/UpdateReportBusinessDetailDTO.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.dto;
 
+import com.fasterxml.jackson.annotation.JsonAlias;
 import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.AddReportDetailStatisticsItemRelDTO;
 import com.persagy.apm.energy.report.monthly.detail.business.model.Job;
 import io.swagger.annotations.ApiModel;
@@ -17,13 +18,9 @@ import java.util.List;
 @Data
 @ApiModel(value = "更新报告详情入参")
 public class UpdateReportBusinessDetailDTO {
-    @ApiModelProperty(value = "主键", required = true)
-    @NotBlank(message = "主键不能为空")
-    private String id;
-
-    @ApiModelProperty(value = "报告类型id", required = true)
-    @NotNull(message = "报告类型id不能为空")
-    private String reportTypeId;
+    @ApiModelProperty(value = "报告主键", required = true)
+    @NotBlank(message = "报告主键不能为空")
+    private String reportOutlineId;
 
     @ApiModelProperty(value = "在营项目用电情况说明")
     private String openPowerExplain;
@@ -38,13 +35,14 @@ public class UpdateReportBusinessDetailDTO {
     private String compareCostExplain;
 
     @ApiModelProperty(value = "能耗管理工作开展对象信息")
-    private List<Job> jobs;
+    private List<Job> job;
 
     @ApiModelProperty(value = "能耗管理工作备注")
-    private String jobRemark;
+    private String remark;
 
     @ApiModelProperty(value = "平台其他事项说明")
-    private String platformSupplement;
+    private String itemExplain;
+
 
     @ApiModelProperty(value = "统计条目补充说明")
     private List<AddReportDetailStatisticsItemRelDTO> statisticItemsSupplements;

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

@@ -15,33 +15,33 @@ public class CostItemVO {
     private 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;
 
 }

+ 5 - 4
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/ResponseReportBusinessDetailItemVO.java

@@ -8,6 +8,7 @@ import com.persagy.apm.energy.report.saasweb.model.vo.ReportProjectVO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.nfunk.jep.function.Power;
 
 import java.util.List;
 
@@ -32,25 +33,25 @@ public class ResponseReportBusinessDetailItemVO {
     private ReportAreaVO compareAreaInfo;
 
     @ApiModelProperty("在营项目用电量数据对象信息,项目月报使用此字段")
-    private OpenPower openPower;
+    private PowerVO openPower;
 
     @ApiModelProperty("在营项目用电情况说明")
     private String openPowerExplain;
 
     @ApiModelProperty("可同比项目用电量数据对象信息")
-    private ComparePower comparePower;
+    private PowerVO comparePower;
 
     @ApiModelProperty("可同比项目用电情况说明")
     private String comparePowerExplain;
 
     @ApiModelProperty("在营项目能源费数据对象信息,项目月报使用此字段")
-    private OpenCost openCost;
+    private CostVO openCost;
 
     @ApiModelProperty("在营项目费用说明")
     private String openCostExplain;
 
     @ApiModelProperty("可同比项目能源费数据对象信息")
-    private CompareCost compareCost;
+    private CostVO compareCost;
 
     @ApiModelProperty("可同比项目费用说明")
     private String compareCostExplain;

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

@@ -25,7 +25,10 @@ import com.persagy.apm.energy.report.monthly.detail.business.model.dto.AddReport
 import com.persagy.apm.energy.report.monthly.detail.business.model.dto.PageQueryReportBusinessDetailDTO;
 import com.persagy.apm.energy.report.monthly.detail.business.model.dto.QueryReportBusinessDetailDTO;
 import com.persagy.apm.energy.report.monthly.detail.business.model.dto.UpdateReportBusinessDetailDTO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.ResponseReportBusinessDetailItemVO;
 import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
 import org.apache.commons.lang.StringUtils;
 import org.assertj.core.util.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,6 +54,8 @@ public class ReportBusinessDetailServiceImpl extends ServiceImpl<ReportBusinessD
     private IReportTypeFunctionRelService reportTypeFunctionRelService;
     @Autowired
     private IReportTypeFunctionGroupRelService reportTypeFunctionGroupRelService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
 
     /**
      * 创建报告详情
@@ -97,16 +102,18 @@ public class ReportBusinessDetailServiceImpl extends ServiceImpl<ReportBusinessD
      * @version V1.0 2021-05-17 11:08:34
      */
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public void updateReportBusinessDetail(UpdateReportBusinessDetailDTO updateReportBusinessDetailDTO) {
-        ReportBusinessDetail reportBusinessDetail = getById(updateReportBusinessDetailDTO.getId());
+        String reportOutlineId = updateReportBusinessDetailDTO.getReportOutlineId();
+        ReportOutline reportOutline = reportOutlineService.queryReportOutlineDetail(reportOutlineId);
+        ReportBusinessDetail reportBusinessDetail = getById(reportOutline.getDetailId());
         reportBusinessDetail = ConvertReportBusinessDetailTool.INSTANCE.convertUpdateDto2Entity(reportBusinessDetail, updateReportBusinessDetailDTO);
         reportBusinessDetail.setModifier(PoemsContext.getContext().getUserId());
         updateById(reportBusinessDetail);
         // 更新统计条目信息,先删后加
         QueryReportDetailStatisticsItemRelDTO queryReportDetailStatisticsItemRelDTO = new QueryReportDetailStatisticsItemRelDTO();
-        queryReportDetailStatisticsItemRelDTO.setReportDetailId(updateReportBusinessDetailDTO.getId());
-        queryReportDetailStatisticsItemRelDTO.setReportTypeId(updateReportBusinessDetailDTO.getReportTypeId());
+        queryReportDetailStatisticsItemRelDTO.setReportDetailId(reportOutline.getDetailId());
+        queryReportDetailStatisticsItemRelDTO.setReportTypeId(reportOutline.getReportTypeId());
         List<ReportDetailStatisticsItemRel> reportDetailStatisticsItemRels = reportDetailStatisticsItemRelService.queryReportDetailStatisticsItemRelList(queryReportDetailStatisticsItemRelDTO);
         for (ReportDetailStatisticsItemRel reportDetailStatisticsItemRel : reportDetailStatisticsItemRels) {
             reportDetailStatisticsItemRelService.deleteReportDetailStatisticsItemRel(reportDetailStatisticsItemRel.getId());
@@ -149,11 +156,9 @@ public class ReportBusinessDetailServiceImpl extends ServiceImpl<ReportBusinessD
      */
     @Override
     public void deleteReportBusinessDetail(String id) {
-        // 校验是否可删除
-        ReportBusinessDetail reportBusinessDetail = checkDeletable(id);
-
-        reportBusinessDetail.setValid(ValidEnum.FALSE.getType());
-        updateById(reportBusinessDetail);
+        if (StringUtils.isNotBlank(id)) {
+            removeById(id);
+        }
     }
 
     /**

+ 25 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/constants/enums/ReportStateEnum.java

@@ -3,6 +3,10 @@ package com.persagy.apm.energy.report.monthly.outline.constants.enums;
 import com.persagy.apm.common.model.annotation.SwaggerDisplayEnum;
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * 报告状态
@@ -30,4 +34,25 @@ public enum ReportStateEnum {
         this.type = type;
         this.desc = desc;
     }
+
+    /**
+     * 根据type获取到枚举对象
+     *
+     * @param type 报告状态编码
+     * @return 报告状态枚举对象
+     * @author lixing
+     * @version V1.0 2021/5/31 4:06 下午
+     */
+    public static ReportStateEnum getByType(String type) {
+        if (StringUtils.isBlank(type)) {
+            return null;
+        }
+        ReportStateEnum[] reportStateEnums = ReportStateEnum.values();
+        for (ReportStateEnum reportStateEnum : reportStateEnums) {
+            if (type.equals(reportStateEnum.getType())) {
+                return reportStateEnum;
+            }
+        }
+        return null;
+    }
 }

+ 32 - 1
src/main/java/com/persagy/apm/energy/report/monthly/outline/controller/ReportOutlineController.java

@@ -6,8 +6,21 @@ import com.persagy.apm.common.response.ApmResponseUpsertVO;
 import com.persagy.apm.common.response.CommonResult;
 import com.persagy.apm.common.response.PageList;
 import com.persagy.apm.common.utils.ResultHelper;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.ConvertReportDetailStatisticsItemRelTool;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.ReportDetailStatisticsItemRel;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.QueryReportDetailStatisticsItemRelDTO;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.vo.ResponseReportDetailStatisticsItemRelListItemVO;
+import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
+import com.persagy.apm.energy.report.monthly.config.type.model.ConvertReportTypeTool;
+import com.persagy.apm.energy.report.monthly.config.type.model.ReportType;
+import com.persagy.apm.energy.report.monthly.config.type.model.vo.ResponseReportTypeItemVO;
 import com.persagy.apm.energy.report.monthly.config.type.model.vo.ResponseReportTypeListItemVO;
 import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeService;
+import com.persagy.apm.energy.report.monthly.detail.business.model.ConvertReportBusinessDetailTool;
+import com.persagy.apm.energy.report.monthly.detail.business.model.ReportBusinessDetail;
+import com.persagy.apm.energy.report.monthly.detail.business.model.dto.GetReportBusinessDetailDTO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.ResponseReportBusinessDetailItemVO;
+import com.persagy.apm.energy.report.monthly.outline.constants.enums.ReportStateEnum;
 import com.persagy.apm.energy.report.monthly.outline.model.ConvertReportOutlineTool;
 import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
 import com.persagy.apm.energy.report.monthly.outline.model.dto.*;
@@ -78,7 +91,16 @@ public class ReportOutlineController {
         IPage<ReportOutline> pagedList = reportOutlineService.pageQueryReportOutline(pageQueryReportOutlineDTO);
         IPage<ResponseReportOutlineListItemVO> pagedResultList = pagedList.convert(item -> {
             try {
-                return ConvertReportOutlineTool.INSTANCE.convert2ResponseListItemDTO(item);
+
+                ResponseReportOutlineListItemVO responseReportOutlineListItemVO = ConvertReportOutlineTool.INSTANCE.convert2ResponseListItemDTO(item);
+                ReportType reportType = reportTypeService.queryReportTypeDetail(item.getReportTypeId());
+                ResponseReportTypeItemVO responseReportTypeItemVO = ConvertReportTypeTool.INSTANCE.convert2ResponseItemDTO(reportType);
+                responseReportOutlineListItemVO.setReportType(responseReportTypeItemVO);
+                ReportStateEnum reportStateEnum = ReportStateEnum.getByType(item.getStatus());
+                if (reportStateEnum != null) {
+                    responseReportOutlineListItemVO.setStatusName(reportStateEnum.getDesc());
+                }
+                return responseReportOutlineListItemVO;
             } catch (Exception e) {
                 throw new IllegalArgumentException("分页查询,ReportOutline实体类转换为列表对象发生异常", e);
             }
@@ -114,5 +136,14 @@ public class ReportOutlineController {
         IPage<ResponseReportTypeListItemVO> resultList = reportTypeService.queryAvailableReportTypes();
         return ResultHelper.multi(resultList);
     }
+
+    @ApiOperation(value = "查看报告详情")
+    @PostMapping("/get")
+    public CommonResult<ResponseReportBusinessDetailItemVO> getReportBusinessDetail(
+            @Valid @RequestBody GetReportBusinessDetailDTO getReportBusinessDetailDTO) {
+        ResponseReportBusinessDetailItemVO reportDetailInfo = reportOutlineService.getReportDetailInfo(
+                getReportBusinessDetailDTO.getReportOutlineId());
+        return ResultHelper.single(reportDetailInfo);
+    }
 }
 

+ 0 - 2
src/main/java/com/persagy/apm/energy/report/monthly/outline/model/dto/PageQueryReportOutlineDTO.java

@@ -24,11 +24,9 @@ public class PageQueryReportOutlineDTO extends PageDTO {
     private String name;
 
     @ApiModelProperty(value = "报告开始日期")
-    @NotNull(message = "报告开始日期不能为空")
     private Date startDate;
 
     @ApiModelProperty(value = "报告结束日期")
-    @NotNull(message = "报告结束日期不能为空")
     private Date endDate;
 
     @ApiModelProperty(value = "报告状态")

+ 4 - 1
src/main/java/com/persagy/apm/energy/report/monthly/outline/model/vo/ResponseReportOutlineListItemVO.java

@@ -36,9 +36,12 @@ public class ResponseReportOutlineListItemVO {
     @ApiModelProperty("报告详情id")
     private String detailId;
 
-    @ApiModelProperty("报告状态")
+    @ApiModelProperty("报告状态编码")
     private String status;
 
+    @ApiModelProperty("报告状态名称")
+    private String statusName;
+
     @ApiModelProperty("备注")
     private ReportOutlineRemark remark;
 }

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

@@ -0,0 +1,107 @@
+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.Platform;
+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.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;
+
+/**
+ * 生成商业报告建造者接口
+ *
+ * @author lixing
+ * @version V1.0 2021/5/30 10:26 下午
+ **/
+public interface IBusinessReportBuilder {
+    /**
+     * 生成报告
+     *
+     * @param reportOutline 报告outline对象
+     * @author lixing
+     * @version V1.0 2021/5/24 4:09 下午
+     */
+    void generateReport(ReportOutline reportOutline);
+
+    /**
+     * 删除之前的报告详情信息
+     *
+     * @param detailId 报告详情id
+     * @author lixing
+     * @version V1.0 2021/5/31 4:19
+     */
+    void deletePreviousReportDetail(String detailId);
+
+    /**
+     * 在营项目用电量信息
+     *
+     * @param reportOutline 报告outline对象
+     * @return 在营项目用电量信息
+     * @author lixing
+     * @version V1.0 2021/5/31 4:21 下午
+     */
+    PowerVO getOpenPowerInfo(ReportOutline reportOutline);
+
+    /**
+     * 可同比项目用电量信息
+     *
+     * @param reportOutline 报告outline对象
+     * @return 可同比项目用电量信息
+     * @author lixing
+     * @version V1.0 2021/5/31 4:21 下午
+     */
+    PowerVO getComparePowerInfo(ReportOutline reportOutline);
+
+    /**
+     * 在营项目费用信息
+     *
+     * @param reportOutline 报告outline对象
+     * @return 在营项目费用信息
+     * @author lixing
+     * @version V1.0 2021/5/31 4:21 下午
+     */
+    CostVO getOpenCostInfo(ReportOutline reportOutline);
+
+    /**
+     * 可同比项目费用信息
+     *
+     * @param reportOutline 报告outline对象
+     * @return 在营项目费用信息
+     * @author lixing
+     * @version V1.0 2021/5/31 4:21 下午
+     */
+    CostVO getCompareCostInfo(ReportOutline reportOutline);
+
+    /**
+     * 可同比项目费用信息
+     *
+     * @param reportOutline 报告outline对象
+     * @return 在营项目费用信息
+     * @author lixing
+     * @version V1.0 2021/5/31 4:21 下午
+     */
+    List<Platform> getPlatforms(ReportOutline reportOutline);
+
+    /**
+     * 成功时更新报告概要
+     *
+     * @param reportOutline 需要更新的报告概要
+     * @author lixing
+     * @version V1.0 2021/5/31 4:26 下午
+     */
+    void updateReportOutlineInfoWhenSuccess(ReportOutline reportOutline);
+
+    /**
+     * 失败时更新报告概要
+     *
+     * @param reportOutline 需要更新的报告概要
+     * @author lixing
+     * @version V1.0 2021/5/31 4:26 下午
+     */
+    void updateReportOutlineInfoWhenFailure(ReportOutline reportOutline);
+}

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

@@ -11,7 +11,7 @@ import java.util.Date;
 import java.util.List;
 
 /**
- * 接口说明
+ * 商业报告费用信息service接口
  *
  * @author lixing
  * @version V1.0 2021/5/30 10:26 下午
@@ -67,14 +67,17 @@ public interface IBusinessReportCostInfoService {
     /**
      * 获取一个条目的费用信息
      *
-     * @param reportMonth       报告月份
-     * @param reportProjectInfo 报告项目信息
-     * @param functionId        功能点id
+     * @param reportMonth         报告月份
+     * @param reportProjectInfo   报告项目信息
+     * @param totalCommercialArea 区域项目总面积
+     * @param functionId          功能点id
      * @return 费用对象
      * @author lixing
      * @version V1.0 2021/5/30 5:54 下午
      */
-    CostItemVO getCostItemInfo(Date reportMonth, ReportProjectVO reportProjectInfo, String functionId);
+    CostItemVO getCostItemInfo(
+            Date reportMonth, ReportProjectVO reportProjectInfo,
+            Double totalCommercialArea, String functionId);
 
     /**
      * 求一组费用条目的统计值

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

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.outline.service;
 
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.ResponseReportBusinessDetailItemVO;
 import com.persagy.apm.energy.report.monthly.outline.model.*;
 import com.persagy.apm.energy.report.monthly.outline.model.dto.*;
 
@@ -38,6 +39,16 @@ public interface IReportOutlineService {
     ReportOutline queryReportOutlineDetail(String id);
 
     /**
+     * 获取报告详情信息
+     *
+     * @param reportOutlineId 主键
+     * @return 报告详情信息
+     * @author lixing
+     * @version V1.0 2021/5/31 6:24 下午
+     */
+    ResponseReportBusinessDetailItemVO getReportDetailInfo(String reportOutlineId);
+
+    /**
      * 更新报告概要
      *
      * @param updateReportOutlineDTO updateDTO

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

@@ -2,6 +2,8 @@ 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.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
 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;
@@ -13,6 +15,8 @@ import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineServi
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.util.List;
 
@@ -24,57 +28,6 @@ import java.util.List;
  **/
 @Component
 @Slf4j
-public class BusinessAreaReportGenerator {
-    @Autowired
-    private IReportBusinessDetailService businessDetailService;
-    @Autowired
-    private IBusinessReportPowerInfoService businessReportPowerInfoService;
-    @Autowired
-    private IBusinessReportCostInfoService businessReportCostInfoService;
-    @Autowired
-    private IBusinessReportPlatformInfoService 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);
-        }
-    }
+public class BusinessAreaReportGenerator extends BusinessReportBuilder{
 
 }

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

@@ -1,9 +1,9 @@
 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.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
 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;
@@ -15,6 +15,7 @@ import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineServi
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -26,53 +27,14 @@ import java.util.List;
  **/
 @Component
 @Slf4j
-public class BusinessProjectReportGenerator {
-    @Autowired
-    private IReportBusinessDetailService businessDetailService;
-    @Autowired
-    private IBusinessReportPowerInfoService businessReportPowerInfoService;
-    @Autowired
-    private IBusinessReportCostInfoService businessReportCostInfoService;
-    @Autowired
-    private IBusinessReportPlatformInfoService 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);
-        }
+public class BusinessProjectReportGenerator extends BusinessReportBuilder {
+    @Override
+    public PowerVO getComparePowerInfo(ReportOutline reportOutline) {
+        return null;
     }
 
+    @Override
+    public CostVO getCompareCostInfo(ReportOutline reportOutline) {
+        return null;
+    }
 }

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

@@ -0,0 +1,132 @@
+package com.persagy.apm.energy.report.monthly.outline.service.impl;
+
+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.model.vo.CostVO;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.PowerVO;
+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.*;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+import java.util.List;
+
+/**
+ * 商业项目报告建造者
+ *
+ * @author lixing
+ * @version V1.0 2021/5/12 2:53 下午
+ **/
+@Component
+@Slf4j
+public class BusinessReportBuilder implements IBusinessReportBuilder {
+    @Autowired
+    private IReportBusinessDetailService businessDetailService;
+    @Autowired
+    private IBusinessReportPowerInfoService businessReportPowerInfoService;
+    @Autowired
+    private IBusinessReportCostInfoService businessReportCostInfoService;
+    @Autowired
+    private IBusinessReportPlatformInfoService businessReportPlatformInfoService;
+    @Autowired
+    private IReportOutlineService reportOutlineService;
+
+    /**
+     * 生成报告
+     *
+     * @param reportOutline 报告outline对象
+     * @author lixing
+     * @version V1.0 2021/5/24 4:09 下午
+     */
+    @Transactional(rollbackFor=Exception.class)
+    @Override
+    public void generateReport(ReportOutline reportOutline) {
+        try {
+            // 删除之前关联的报告信息
+            deletePreviousReportDetail(reportOutline.getDetailId());
+
+            AddReportBusinessDetailDTO addReportBusinessDetailDTO = new AddReportBusinessDetailDTO();
+            // 获取项目用电量信息
+            addReportBusinessDetailDTO.setOpenPower(getOpenPowerInfo(reportOutline));
+            addReportBusinessDetailDTO.setComparePower(getComparePowerInfo(reportOutline));
+            // 获取项目费用信息
+            addReportBusinessDetailDTO.setOpenCost(getOpenCostInfo(reportOutline));
+            addReportBusinessDetailDTO.setCompareCost(getCompareCostInfo(reportOutline));
+
+            // 获取项目平台运维信息
+            addReportBusinessDetailDTO.setPlatform(getPlatforms(reportOutline));
+
+            String detailId = businessDetailService.createReportBusinessDetail(addReportBusinessDetailDTO);
+            reportOutline.setDetailId(detailId);
+            updateReportOutlineInfoWhenSuccess(reportOutline);
+        } catch (Exception e) {
+            log.error("生成报告失败", e);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            updateReportOutlineInfoWhenFailure(reportOutline);
+        }
+    }
+
+    @Override
+    public void deletePreviousReportDetail(String detailId) {
+        businessDetailService.deleteReportBusinessDetail(detailId);
+    }
+
+    @Override
+    public PowerVO getOpenPowerInfo(ReportOutline reportOutline) {
+        List<String> powerGroupIdList = businessDetailService.getGroupsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+        List<String> powerFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+        return businessReportPowerInfoService.getPowerInfo(reportOutline, powerGroupIdList, powerFunctionIdList);
+    }
+
+    @Override
+    public PowerVO getComparePowerInfo(ReportOutline reportOutline) {
+        List<String> powerGroupIdList = businessDetailService.getGroupsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+        List<String> powerFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_POWER);
+        return businessReportPowerInfoService.getComparePowerInfo(reportOutline, powerGroupIdList, powerFunctionIdList);
+    }
+
+    @Override
+    public CostVO getOpenCostInfo(ReportOutline reportOutline) {
+        List<String> costGroupIdList = businessDetailService.getGroupsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+        List<String> costFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+        return businessReportCostInfoService.getOpenCost(reportOutline, costGroupIdList, costFunctionIdList);
+    }
+
+    @Override
+    public CostVO getCompareCostInfo(ReportOutline reportOutline) {
+        List<String> costGroupIdList = businessDetailService.getGroupsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+        List<String> costFunctionIdList = businessDetailService.getFunctionsByParagraph(
+                reportOutline.getReportTypeId(), BusinessReportParagraphs.OPEN_COST);
+        return businessReportCostInfoService.getCompareCost(reportOutline, costGroupIdList, costFunctionIdList);
+    }
+
+    @Override
+    public List<Platform> getPlatforms(ReportOutline reportOutline) {
+        return businessReportPlatformInfoService.getPlatforms(reportOutline);
+    }
+
+    @Override
+    public void updateReportOutlineInfoWhenSuccess(ReportOutline reportOutline) {
+        reportOutline.setStatus(ReportStateEnum.GENERATED.getType());
+        reportOutlineService.updateReportOutline(reportOutline);
+    }
+
+    @Override
+    public void updateReportOutlineInfoWhenFailure(ReportOutline reportOutline) {
+        reportOutline.setStatus(ReportStateEnum.BUILD_FAILED.getType());
+        reportOutlineService.updateReportOutline(reportOutline);
+    }
+}

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

@@ -108,7 +108,9 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
 
         for (String functionId : functionIdList) {
             Function function = functionService.queryFunctionDetail(functionId);
-            String itemName = functionService.getItemName(function, projectIds.get(0));
+            // TODO: 2021/5/31 移除注释
+            //            String itemName = functionService.getItemName(function, projectIds.get(0));
+            String itemName = "test";
 
             List<CostItemVO> projectCostItems = getCostItemsByProjects(reportMonth, projectIds, function);
             CostItemVO costSumByProjects = getCostSum(projectCostItems);
@@ -124,20 +126,25 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
         if (CollectionUtils.isEmpty(projectIds)) {
             return projectCostItems;
         }
+        // 统计项目总的商业面积
+        Double totalCommercialArea = saasWebService.getTotalCommercialArea(projectIds);
+
         for (String projectId : projectIds) {
             // 获取项目信息
             ReportProjectVO reportProjectInfo = saasWebService.getReportProjectInfo(projectId);
             if (reportProjectInfo == null) {
                 continue;
             }
-            CostItemVO costItemVO = getCostItemInfo(reportMonth, reportProjectInfo, function.getId());
+            CostItemVO costItemVO = getCostItemInfo(reportMonth, reportProjectInfo, totalCommercialArea, function.getId());
             projectCostItems.add(costItemVO);
         }
         return projectCostItems;
     }
 
     @Override
-    public CostItemVO getCostItemInfo(Date reportMonth, ReportProjectVO reportProjectInfo, String functionId) {
+    public CostItemVO getCostItemInfo(
+            Date reportMonth, ReportProjectVO reportProjectInfo,
+            Double totalCommercialArea, String functionId) {
         String projectId = reportProjectInfo.getProjectId();
         CostItemVO costItemVO = new CostItemVO();
         String currentMonthStr = functionValueService.getFunctionValue(functionId, reportMonth, projectId);
@@ -172,8 +179,8 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
         if (lastYearSumItem != null) {
             lastYearCount = lastYearSumItem.getLastYearCount();
             costItemVO.setLastYearCount(lastYearCount);
-            if (StringUtils.isNotBlank(reportProjectInfo.getCommercialArea())) {
-                costItemVO.setLastYearPerCount(lastYearCount / Double.parseDouble(reportProjectInfo.getCommercialArea()));
+            if (totalCommercialArea != null && lastYearCount != null) {
+                costItemVO.setLastYearPerCount(lastYearCount / totalCommercialArea);
             }
         }
 
@@ -188,15 +195,15 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
             String monthValue = functionValueService.getFunctionValue(functionId, yearMonth, projectId);
             if (StringUtils.isNotBlank(monthValue)) {
                 tmp.setYearCount(Double.parseDouble(monthValue));
-                lastYearItems.add(tmp);
+                yearItems.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 (totalCommercialArea != null && yearCount != null) {
+                costItemVO.setYearPerCount(yearCount / totalCommercialArea);
             }
         }
 
@@ -239,6 +246,7 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
             List<CostItemVO> costItemInfos = getCostItemInfos(functionIds, reportMonth, projectIds);
             groupInfo.setItems(costItemInfos);
             groupInfo.setSummary(getCostSum(costItemInfos));
+            groupInfoList.add(groupInfo);
         }
         return groupInfoList;
     }

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

@@ -106,7 +106,9 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
 
         for (String functionId : functionIdList) {
             Function function = functionService.queryFunctionDetail(functionId);
-            String itemName = functionService.getItemName(function, projectIds.get(0));
+            // TODO: 2021/5/31 解除注释
+//            String itemName = functionService.getItemName(function, projectIds.get(0));
+            String itemName = "test";
 
             List<PowerItemVO> projectPowerItems = getPowerItemsByProjects(reportMonth, projectIds, function);
             PowerItemVO powerSumByProjects = getPowerSum(projectPowerItems);
@@ -132,13 +134,14 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
             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);
-            }
+            // TODO: 2021/5/31 解除注释
+//            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;
     }
@@ -166,7 +169,7 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
         if (lastYearSumItem != null) {
             lastYearCount = lastYearSumItem.getLastYearCount();
             powerItemVO.setLastYearCount(lastYearCount);
-            if (totalCommercialArea != null) {
+            if (totalCommercialArea != null && lastYearCount != null) {
                 powerItemVO.setLastYearPerCount(lastYearCount / totalCommercialArea);
             }
         }
@@ -186,7 +189,7 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
         if (yearSumItem != null) {
             yearCount = yearSumItem.getYearCount();
             powerItemVO.setYearCount(yearCount);
-            if (totalCommercialArea != null) {
+            if (totalCommercialArea != null && yearCount != null) {
                 powerItemVO.setYearPerCount(yearCount / totalCommercialArea);
             }
         }
@@ -244,6 +247,7 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
             List<PowerItemVO> powerItemInfos = getPowerItemInfos(functionIds, reportMonth, projectIds);
             groupInfo.setItems(powerItemInfos);
             groupInfo.setSummary(getPowerSum(powerItemInfos));
+            groupInfoList.add(groupInfo);
         }
         return groupInfoList;
     }

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

@@ -1,6 +1,7 @@
 package com.persagy.apm.energy.report.monthly.outline.service.impl;
 
 import cn.hutool.core.thread.ExecutorBuilder;
+import com.persagy.apm.common.context.poems.PoemsContext;
 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;
@@ -51,8 +52,12 @@ public class GenerateReportThreadPool {
      * @version V1.0 2021/5/24 4:09 下午
      */
     public void generateReport(ReportOutline reportOutline) {
+        String userId = PoemsContext.getContext().getUserId();
+        String pd = PoemsContext.getContext().getPd();
+        String loginDevice = PoemsContext.getContext().getLoginDevice();
         es.execute(() -> {
             try {
+                PoemsContext.setContext(userId, loginDevice, pd);
                 String reportTypeId = reportOutline.getReportTypeId();
                 ReportType reportType = reportTypeService.queryReportTypeDetail(reportTypeId);
                 if (BuildingTypeEnum.BUSINESS.getType().equals(reportType.getBuildingType())) {

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

@@ -8,9 +8,18 @@ import com.google.common.base.CaseFormat;
 import com.persagy.apm.common.constant.enums.ValidEnum;
 import com.persagy.apm.common.context.poems.PoemsContext;
 import com.persagy.apm.common.model.dto.Sort;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.ConvertReportDetailStatisticsItemRelTool;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.ReportDetailStatisticsItemRel;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.dto.QueryReportDetailStatisticsItemRelDTO;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.model.vo.ResponseReportDetailStatisticsItemRelListItemVO;
+import com.persagy.apm.energy.report.monthly.config.rel.detailstatisticsitem.service.IReportDetailStatisticsItemRelService;
 import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
 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.ConvertReportBusinessDetailTool;
+import com.persagy.apm.energy.report.monthly.detail.business.model.ReportBusinessDetail;
+import com.persagy.apm.energy.report.monthly.detail.business.model.vo.ResponseReportBusinessDetailItemVO;
+import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
 import com.persagy.apm.energy.report.monthly.outline.constants.enums.ReportStateEnum;
 import com.persagy.apm.energy.report.monthly.outline.dao.ReportOutlineMapper;
 import com.persagy.apm.energy.report.monthly.outline.model.ConvertReportOutlineTool;
@@ -47,6 +56,10 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
     ISaasWebService saasWebService;
     @Autowired
     GenerateReportThreadPool generateReportThreadPool;
+    @Autowired
+    IReportBusinessDetailService reportBusinessDetailService;
+    @Autowired
+    IReportDetailStatisticsItemRelService reportDetailStatisticsItemRelService;
 
 
     /**
@@ -59,14 +72,27 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
     @Override
     public String createReportOutline(AddReportOutlineDTO addReportOutlineDTO) {
         ReportOutline reportOutline = ConvertReportOutlineTool.INSTANCE.convertAddDto2Entity(addReportOutlineDTO);
+        return generateReport(reportOutline);
+    }
+
+    /**
+     * 生成报告
+     *
+     * @param reportOutline 报告概要对象
+     * @return 报告概要id
+     * @author lixing
+     * @version V1.0 2021/5/31 11:09 上午
+     */
+    private String generateReport(ReportOutline reportOutline) {
         // 设置默认值
         setDefaultValue(reportOutline);
-        save(reportOutline);
+        saveOrUpdate(reportOutline);
         // 后台生成报告
         generateReportThreadPool.generateReport(reportOutline);
         return reportOutline.getId();
     }
 
+
     /**
      * 如果某些字段没有赋值,使用默认的值
      *
@@ -88,7 +114,7 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
             belongName = reportProjectInfo.getProjectName();
         }
         if (BelongTypeEnum.AREA.getType().equals(reportType.getBelongType())) {
-            ReportAreaVO reportAreaInfo = saasWebService.getReportAreaInfo(reportOutline.getBelong());
+            ReportAreaVO reportAreaInfo = saasWebService.getReportAreaInfo(reportOutline.getBelong(), reportType.getBuildingType());
             belongName = reportAreaInfo.getAreaName();
         }
 
@@ -118,6 +144,37 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
     }
 
     @Override
+    public ResponseReportBusinessDetailItemVO getReportDetailInfo(String reportOutlineId) {
+        ReportOutline reportOutline = queryReportOutlineDetail(reportOutlineId);
+
+        ReportBusinessDetail reportBusinessDetail = reportBusinessDetailService.getReportBusinessDetail(reportOutline.getDetailId());
+        ResponseReportBusinessDetailItemVO responseReportBusinessDetailItemVO = ConvertReportBusinessDetailTool.INSTANCE.convert2ResponseItemDTO(reportBusinessDetail);
+
+        ReportType reportType = reportTypeService.queryReportTypeDetail(reportOutline.getReportTypeId());
+        if (BelongTypeEnum.PROJECT.getType().equals(reportType.getBelongType())) {
+            ReportProjectVO reportProjectInfo = saasWebService.getReportProjectInfo(reportOutline.getBelong());
+            responseReportBusinessDetailItemVO.setProjectInfo(reportProjectInfo);
+        } else {
+            ReportAreaVO openReportAreaInfo = saasWebService.getReportAreaInfo(reportOutline.getBelong(), reportType.getBuildingType());
+            responseReportBusinessDetailItemVO.setOpenAreaInfo(openReportAreaInfo);
+
+            ReportAreaVO compareReportAreaInfo = saasWebService.getCompareReportAreaInfo(
+                    reportOutline.getBelong(), reportType.getBuildingType(), reportOutline.getReportMonth());
+            responseReportBusinessDetailItemVO.setCompareAreaInfo(compareReportAreaInfo);
+        }
+
+
+        // 查询统计条目补充信息
+        QueryReportDetailStatisticsItemRelDTO queryReportDetailStatisticsItemRelDTO = new QueryReportDetailStatisticsItemRelDTO();
+        queryReportDetailStatisticsItemRelDTO.setReportDetailId(reportOutline.getDetailId());
+        queryReportDetailStatisticsItemRelDTO.setReportTypeId(reportOutline.getReportTypeId());
+        List<ReportDetailStatisticsItemRel> reportDetailStatisticsItemRels = reportDetailStatisticsItemRelService.queryReportDetailStatisticsItemRelList(queryReportDetailStatisticsItemRelDTO);
+        List<ResponseReportDetailStatisticsItemRelListItemVO> responseReportDetailStatisticsItemRelListItemVOList = ConvertReportDetailStatisticsItemRelTool.INSTANCE.convert2List(reportDetailStatisticsItemRels);
+        responseReportBusinessDetailItemVO.setStatisticItemsSupplements(responseReportDetailStatisticsItemRelListItemVOList);
+        return responseReportBusinessDetailItemVO;
+    }
+
+    @Override
     public void updateReportOutline(UpdateReportOutlineDTO updateReportOutlineDTO) {
         ReportOutline reportOutline = getById(updateReportOutlineDTO.getId());
         reportOutline = ConvertReportOutlineTool.INSTANCE.convertUpdateDto2Entity(reportOutline, updateReportOutlineDTO);
@@ -311,8 +368,6 @@ public class ReportOutlineServiceImpl extends ServiceImpl<ReportOutlineMapper, R
     public String recreateReportOutline(RecreateReportOutlineDTO recreateReportOutlineDTO) {
         String id = recreateReportOutlineDTO.getId();
         ReportOutline reportOutline = checkExists(id);
-        // 后台生成报告
-        generateReportThreadPool.generateReport(reportOutline);
-        return reportOutline.getId();
+        return generateReport(reportOutline);
     }
 }

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/model/vo/PoemsProjectVO.java

@@ -23,4 +23,6 @@ public class PoemsProjectVO {
     private String functionType;
     @ApiModelProperty(value = "项目功能类型名称")
     private String functionTypeName;
+    @ApiModelProperty(value = "项目开业时间")
+    private String businessOpeningTime;
 }

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/model/vo/SimpleProjectVO.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.saasweb.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonAlias;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -14,6 +15,7 @@ public class SimpleProjectVO {
     @ApiModelProperty(value = "项目id")
     private String projectId;
     @ApiModelProperty(value = "项目名称")
+    @JsonAlias("projectLocalName")
     private String projectName;
     @ApiModelProperty(value = "项目功能类型")
     private String functionType;

+ 16 - 3
src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java

@@ -44,14 +44,27 @@ public interface ISaasWebService {
     Double getTotalCommercialArea(List<String> projectIds);
 
     /**
+     * 获取区域可同比项目信息
+     *
+     * @param areaCode     区域编码
+     * @param buildingType 建筑类型
+     * @param reportMonth  报告月份
+     * @return 区域可同比项目信息
+     * @author lixing
+     * @version V1.0 2021/5/30 11:28 下午
+     */
+    ReportAreaVO getCompareReportAreaInfo(String areaCode, String buildingType, Date reportMonth);
+
+    /**
      * 获取区域信息
      *
-     * @param areaCode 区域编码
+     * @param areaCode     区域编码
+     * @param buildingType 建筑类型
      * @return 区域信息
      * @author lixing
      * @version V1.0 2021/5/19 4:04 下午
      */
-    ReportAreaVO getReportAreaInfo(String areaCode);
+    ReportAreaVO getReportAreaInfo(String areaCode, String buildingType);
 
     /**
      * 获取分区下所有的项目
@@ -87,7 +100,7 @@ public interface ISaasWebService {
      * 获取可同比项目(开业时间在指定月份的上一年1月1日之前)
      *
      * @param projectIds 要筛选的项目集
-     * @param month 月份
+     * @param month      月份
      * @return 可同比项目id列表
      * @author lixing
      * @version V1.0 2021/5/31 10:49 上午

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

@@ -107,26 +107,32 @@ public class SaasWebServiceImpl implements ISaasWebService {
     }
 
     @Override
-    public ReportAreaVO getReportAreaInfo(String areaCode) {
-        ReportAreaVO reportAreaVO = new ReportAreaVO();
-        // 查询管理分区信息
-        QueryPartitionDTO queryPartitionDTO = new QueryPartitionDTO();
-        queryPartitionDTO.setManagePartitionIds(Lists.newArrayList(areaCode));
-        PoemsFeignResponse<PoemsPartitionVO> partitionsResponse = saasWebClientWrapper.queryPartitionsByIds(queryPartitionDTO);
-        List<PoemsPartitionVO> partitionVOList = partitionsResponse.getContent();
-        if (!CollectionUtils.isEmpty(partitionVOList)) {
-            PoemsPartitionVO poemsPartitionVO = partitionVOList.get(0);
-            reportAreaVO.setAreaId(areaCode);
-            reportAreaVO.setAreaName(poemsPartitionVO.getManagePartitionName());
-        }
+    public ReportAreaVO getReportAreaInfo(String areaCode, String buildingType) {
+        ReportAreaVO reportAreaVO = getReportAreaBaseInfo(areaCode);
+
+        List<PoemsProjectVO> projectsByAreaAndBuildingType = getProjectsByAreaAndBuildingType(areaCode, buildingType);
 
-        List<PoemsProjectVO> projectVOList = getProjectsByArea(areaCode);
+        ReportAreaVO reportAreaAreaInfo = getReportAreaAreaInfo(projectsByAreaAndBuildingType);
+        reportAreaVO.setUndergroundGarageArea(reportAreaAreaInfo.getUndergroundGarageArea());
+        reportAreaVO.setCommercialArea(reportAreaAreaInfo.getCommercialArea());
+        return reportAreaVO;
+    }
 
+    /**
+     * 获取分区的面积信息
+     *
+     * @param projects 分区下要统计的项目
+     * @return 这些项目的面积信息
+     * @author lixing
+     * @version V1.0 2021/5/31 6:19 下午
+     */
+    private ReportAreaVO getReportAreaAreaInfo(List<PoemsProjectVO> projects) {
+        ReportAreaVO reportAreaVO = new ReportAreaVO();
         // 统计分区下总的商业面积,地下停车场面积
         BigDecimal totalCommercialArea = new BigDecimal("0");
         BigDecimal totalUndergroundGarageArea = new BigDecimal("0");
-        if (!CollectionUtils.isEmpty(projectVOList)) {
-            for (PoemsProjectVO poemsProjectVO : projectVOList) {
+        if (!CollectionUtils.isEmpty(projects)) {
+            for (PoemsProjectVO poemsProjectVO : projects) {
                 // 获取项目下建筑的面积总和
                 ReportProjectVO projectAreas = getProjectAreas(poemsProjectVO.getProjectId());
                 if (StringUtils.isNotBlank(projectAreas.getCommercialArea())) {
@@ -142,6 +148,29 @@ public class SaasWebServiceImpl implements ISaasWebService {
         return reportAreaVO;
     }
 
+    /**
+     * 获取区域的基本信息
+     *
+     * @param areaCode 区域编码
+     * @return 区域的基本信息
+     * @author lixing
+     * @version V1.0 2021/5/31 6:04 下午
+     */
+    private ReportAreaVO getReportAreaBaseInfo(String areaCode) {
+        ReportAreaVO reportAreaVO = new ReportAreaVO();
+        // 查询管理分区信息
+        QueryPartitionDTO queryPartitionDTO = new QueryPartitionDTO();
+        queryPartitionDTO.setManagePartitionIds(Lists.newArrayList(areaCode));
+        PoemsFeignResponse<PoemsPartitionVO> partitionsResponse = saasWebClientWrapper.queryPartitionsByIds(queryPartitionDTO);
+        List<PoemsPartitionVO> partitionVOList = partitionsResponse.getContent();
+        if (!CollectionUtils.isEmpty(partitionVOList)) {
+            PoemsPartitionVO poemsPartitionVO = partitionVOList.get(0);
+            reportAreaVO.setAreaId(areaCode);
+            reportAreaVO.setAreaName(poemsPartitionVO.getManagePartitionName());
+        }
+        return reportAreaVO;
+    }
+
     @Override
     public List<PoemsProjectVO> getProjectsByArea(String areaCode) {
         // 获取管理分区下的项目
@@ -160,7 +189,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
      * @author lixing
      * @version V1.0 2021/5/24 6:01 下午
      */
-    private List<SimpleProjectVO> getProjectsByAreaAndBuildingType(String areaCode, String buildingType) {
+    private List<PoemsProjectVO> getProjectsByAreaAndBuildingType(String areaCode, String buildingType) {
         if (StringUtils.isBlank(areaCode) || StringUtils.isBlank(areaCode)) {
             return Lists.newArrayList();
         }
@@ -173,11 +202,11 @@ public class SaasWebServiceImpl implements ISaasWebService {
         if (CollectionUtils.isEmpty(buildingTypes)) {
             return Lists.newArrayList();
         }
-        return projectsByArea.stream().filter(
-                poemsProjectVO -> StringUtils.isNotBlank(poemsProjectVO.getFunctionType()) &&
-                        buildingTypes.contains(poemsProjectVO.getFunctionType())).map(
-                ConvertSaasWebTool.INSTANCE::convert2SimpleProjectVO
-        ).collect(Collectors.toList());
+        return projectsByArea.stream().
+                filter(
+                        poemsProjectVO -> StringUtils.isNotBlank(poemsProjectVO.getFunctionType()) &&
+                                buildingTypes.contains(poemsProjectVO.getFunctionType())).
+                collect(Collectors.toList());
     }
 
     @Override
@@ -501,9 +530,9 @@ public class SaasWebServiceImpl implements ISaasWebService {
             // 取用户可选项目和分区下项目的交集,projectIds会被更新为两个集合的交集
             availableProjectIds.retainAll(projectIds);
             // 根据业态和分区过滤项目
-            List<SimpleProjectVO> projectsByAreaAndBuildingType = getProjectsByAreaAndBuildingType(partition.getAreaId(), buildingType);
+            List<PoemsProjectVO> projectsByAreaAndBuildingType = getProjectsByAreaAndBuildingType(partition.getAreaId(), buildingType);
             Set<String> projectIdsByAreaAndBuildingType = projectsByAreaAndBuildingType.stream().
-                    map(SimpleProjectVO::getProjectId).collect(Collectors.toSet());
+                    map(PoemsProjectVO::getProjectId).collect(Collectors.toSet());
             availableProjectIds.retainAll(projectIdsByAreaAndBuildingType);
             if (CollectionUtils.isEmpty(projectIds) || projectIdsByAreaAndBuildingType.size() != projectIds.size()) {
                 continue;
@@ -555,4 +584,28 @@ public class SaasWebServiceImpl implements ISaasWebService {
         return result;
     }
 
+    @Override
+    public ReportAreaVO getCompareReportAreaInfo(String areaCode, String buildingType, Date reportMonth) {
+        ReportAreaVO reportAreaVO = getReportAreaBaseInfo(areaCode);
+        List<PoemsProjectVO> projectsByAreaAndBuildingType = getProjectsByAreaAndBuildingType(areaCode, buildingType);
+        if (CollectionUtils.isEmpty(projectsByAreaAndBuildingType)) {
+            return reportAreaVO;
+        }
+        List<PoemsProjectVO> comparableProjects = projectsByAreaAndBuildingType.stream().filter(poemsProjectVO -> {
+            String businessOpeningTime = poemsProjectVO.getBusinessOpeningTime();
+            try {
+                Date openDate = DateUtils.str2Date(businessOpeningTime, DateUtils.SDFSECOND);
+                Date firstDayOfLastYear = DateUtils.getFirstDayOfLastYear(reportMonth);
+                // 如果开业时间早于去年,添加到结果集
+                return DateUtils.compareDate(openDate, firstDayOfLastYear);
+            } catch (Exception e) {
+                log.error("时间转换异常", e);
+                return false;
+            }
+        }).collect(Collectors.toList());
+        ReportAreaVO reportAreaAreaInfo = getReportAreaAreaInfo(comparableProjects);
+        reportAreaVO.setUndergroundGarageArea(reportAreaAreaInfo.getUndergroundGarageArea());
+        reportAreaVO.setCommercialArea(reportAreaAreaInfo.getCommercialArea());
+        return reportAreaVO;
+    }
 }

+ 0 - 1
src/main/resources/mapper/FunctionGroupMapper.xml

@@ -7,7 +7,6 @@
         <result column="name" property="name"/>
         <result column="group_ids" property="groupIds"/>
         <result column="function_ids" property="functionIds"/>
-        <result column="belong_paragraph" property="belongParagraph"/>
         <result column="ts" property="ts"/>
         <result column="creator" property="creator"/>
         <result column="creation_time" property="creationTime"/>

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

@@ -5,7 +5,7 @@
         <result column="id" property="id"/>
         <result column="function_id" property="functionId"/>
         <result column="project_id" property="projectId"/>
-        <result column="data_time" property="dataTime"/>
+        <result column="data_time" property="dataTime" jdbcType="TIMESTAMP"/>
         <result column="value" property="value"/>
         <result column="ts" property="ts"/>
         <result column="creator" property="creator"/>