浏览代码

修复生成报告代码bug

lixing 3 年之前
父节点
当前提交
a1a25ba2d8

+ 1 - 1
src/main/java/com/persagy/apm/energy/report/centermiddleware/constant/enums/TimeTypeEnum.java

@@ -17,7 +17,7 @@ public enum TimeTypeEnum {
      */
     HOUR(1, "时"),
     DAY(2, "天"),
-    MONTH(3, "月");
+    MONTH(4, "月");
 
     @Setter
     @Getter

+ 21 - 13
src/main/java/com/persagy/apm/energy/report/common/utils/DataUtils.java

@@ -6,6 +6,7 @@ import org.springframework.util.CollectionUtils;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.stream.Collectors;
 
 public class DataUtils {
     /**
@@ -39,9 +40,9 @@ public class DataUtils {
     /**
      * 按规则进行计算
      *
-     * @param standardValue 规则值
+     * @param standardValue  规则值
      * @param qualifyFormula 规则
-     * @param data 要进行规则校验的数据
+     * @param data           要进行规则校验的数据
      * @return
      */
     public static Double getQualifyResult(Double standardValue, String qualifyFormula, Double data) {
@@ -60,7 +61,7 @@ public class DataUtils {
     /**
      * 将一组对象中类型为double的属性求和
      *
-     * @param objs 要求和的一组对象
+     * @param objs   要求和的一组对象
      * @param tClass 这组对象的类型
      * @return 一个新的对象,将求和之后的属性赋值给它
      * @author lixing
@@ -74,18 +75,24 @@ public class DataUtils {
             }
             Field[] declaredFields = tClass.getDeclaredFields();
             for (Field declaredField : declaredFields) {
-                if (Double.class.equals(declaredField.getType())) {
-                    declaredField.set(result, objs.stream().filter(
+                if (!Double.class.equals(declaredField.getType())) {
+                    continue;
+                }
+                List<T> notNullList = objs.stream().filter(
+                        obj -> {
+                            try {
+                                return declaredField.get(obj) != null;
+                            } catch (IllegalAccessException e) {
+                                e.printStackTrace();
+                                return false;
+                            }
+                        }).collect(Collectors.toList());
+                if (CollectionUtils.isEmpty(notNullList)) {
+                    declaredField.set(result, null);
+                } else {
+                    declaredField.set(result, notNullList.stream().mapToDouble(
                             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();
@@ -93,6 +100,7 @@ public class DataUtils {
                                 }
                             }).sum());
                 }
+
             }
             return result;
         } catch (Exception e) {

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

@@ -262,7 +262,7 @@ public class FunctionServiceImpl extends ServiceImpl<FunctionMapper, Function>
         queryItemInfoDTO.setBuildingId(simpleProjectInfo.getProjectLocalID());
         queryItemInfoDTO.setModelCode(function.getModelCode());
         queryItemInfoDTO.setItemIdList(Lists.newArrayList(function.getItemId()));
-        Map<String, String> itemNameMap = centerMiddlewareWebService.getItemNameMap(queryItemInfoDTO);
+        Map<String, String> itemNameMap = centerMiddlewareWebService.   getItemNameMap(queryItemInfoDTO);
         if (itemNameMap != null) {
             return itemNameMap.get(function.getItemId());
         }

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

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -10,6 +11,7 @@ import lombok.Data;
  **/
 @Data
 @ApiModel(value = "费用条目")
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class CostItemVO {
     @ApiModelProperty("条目名称")
     private String name;

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/CostVO.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -12,6 +13,7 @@ import java.util.List;
  **/
 @Data
 @ApiModel(value = "费用")
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class CostVO {
     @ApiModelProperty(value = "分组信息")
     private List<GroupInfo<CostItemVO>> groups;

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/GroupInfo.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -12,6 +13,7 @@ import java.util.List;
  **/
 @ApiModel
 @Data
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class GroupInfo<T> {
     @ApiModelProperty("分组名称")
     private String groupName;

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

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -10,6 +11,7 @@ import lombok.Data;
  **/
 @Data
 @ApiModel(value = "用电量条目信息")
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class PowerItemVO {
     @ApiModelProperty("条目名称")
     public String name;

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/monthly/detail/business/model/vo/PowerVO.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energy.report.monthly.detail.business.model.vo;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -12,6 +13,7 @@ import java.util.List;
  **/
 @Data
 @ApiModel(value = "用电量")
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class PowerVO {
     @ApiModelProperty(value = "分组信息")
     private List<GroupInfo<PowerItemVO>> groups;

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

@@ -173,11 +173,12 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
                 lastYearItems.add(tmp);
             }
         }
+        Double zero = 0d;
         CostItemVO lastYearSumItem = getCostSum(lastYearItems);
         if (lastYearSumItem != null) {
             lastYearCount = lastYearSumItem.getLastYearCount();
             costItemVO.setLastYearCount(lastYearCount);
-            if (totalCommercialArea != null && lastYearCount != null) {
+            if (totalCommercialArea != null && !totalCommercialArea.equals(zero) && lastYearCount != null) {
                 costItemVO.setLastYearPerCount(lastYearCount / totalCommercialArea);
             }
         }
@@ -196,11 +197,12 @@ public class BusinessReportCostInfoServiceImpl implements com.persagy.apm.energy
                 yearItems.add(tmp);
             }
         }
+
         CostItemVO yearSumItem = getCostSum(yearItems);
         if (yearSumItem != null) {
             yearCount = yearSumItem.getYearCount();
             costItemVO.setYearCount(yearCount);
-            if (totalCommercialArea != null && yearCount != null) {
+            if (totalCommercialArea != null && !totalCommercialArea.equals(zero) && yearCount != null) {
                 costItemVO.setYearPerCount(yearCount / totalCommercialArea);
             }
         }

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

@@ -162,11 +162,12 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
             tmp.setLastYearCount(dateValueMap.get(lastYearMonth));
             lastYearItems.add(tmp);
         }
+        Double zero = 0d;
         PowerItemVO lastYearSumItem = getPowerSum(lastYearItems);
         if (lastYearSumItem != null) {
             lastYearCount = lastYearSumItem.getLastYearCount();
             powerItemVO.setLastYearCount(lastYearCount);
-            if (totalCommercialArea != null && lastYearCount != null) {
+            if (totalCommercialArea != null && !totalCommercialArea.equals(zero) && lastYearCount != null) {
                 powerItemVO.setLastYearPerCount(lastYearCount / totalCommercialArea);
             }
         }
@@ -182,11 +183,12 @@ public class BusinessReportPowerInfoServiceImpl implements com.persagy.apm.energ
             tmp.setYearCount(dateValueMap.get(yearMonth));
             yearItems.add(tmp);
         }
+
         PowerItemVO yearSumItem = getPowerSum(yearItems);
         if (yearSumItem != null) {
             yearCount = yearSumItem.getYearCount();
             powerItemVO.setYearCount(yearCount);
-            if (totalCommercialArea != null && yearCount != null) {
+            if (totalCommercialArea != null && !totalCommercialArea.equals(zero) && yearCount != null) {
                 powerItemVO.setYearPerCount(yearCount / totalCommercialArea);
             }
         }