Browse Source

历史数据报表

wangyangyang 3 years ago
parent
commit
6cbb6a3744

+ 3 - 3
sms_water/src/main/java/com/huaxu/controller/DayMonthYearReportController.java

@@ -270,7 +270,7 @@ public class DayMonthYearReportController {
         if (CollectionUtil.isEmpty(list)){
             return new AjaxMessage<>(ResultStatus.OK);
         }
-        List<List<String>> reportTitle = ReportExcelUtil.toExcelTitleList(list.get(0).getReportTitle(), queryDto.getSceneType());
+        List<List<String>> reportTitle = ReportExcelUtil.toExcelTitleList(list.get(0).getReportTitle(), queryDto.getSceneType(),0);
         String filePath = ExcelUtil.writeSimpleExcelWithHeader(baseDir, SceneEnum.getMsg(queryDto.getSceneType()) +"报表", reportTitle, ReportExcelUtil.toReportExcelDto(list,queryDto.getSceneType()));
         return new AjaxMessage<>(ResultStatus.OK, filePath);
     }
@@ -292,8 +292,8 @@ public class DayMonthYearReportController {
         if (CollectionUtil.isEmpty(list)) {
             return new AjaxMessage<>(ResultStatus.OK);
         }
-        List<List<String>> reportTitle = ReportExcelUtil.toExcelTitleList(list.get(0).getReportTitle(), queryDto.getSceneType());
-        String filePath = ExcelUtil.writeSimpleExcelWithHeader(baseDir, SceneEnum.getMsg(queryDto.getSceneType()) + "报表", reportTitle, ReportExcelUtil.toReportExcelDto(list, queryDto.getSceneType()));
+        List<List<String>> reportTitle = ReportExcelUtil.toExcelTitleList(list.get(0).getReportTitle(), 4,1);
+        String filePath = ExcelUtil.writeSimpleExcelWithHeader(baseDir, SceneEnum.getMsg(queryDto.getSceneType()) + "报表", reportTitle, ReportExcelUtil.toHisoryDataReportExcelDto(list, queryDto.getSceneType()));
         return new AjaxMessage<>(ResultStatus.OK, filePath);
     }
 

+ 51 - 13
sms_water/src/main/java/com/huaxu/util/ReportExcelUtil.java

@@ -74,6 +74,42 @@ public class ReportExcelUtil {
         }
         return result;
     }
+    /**
+     * @Author lihui
+     * @Description 按顺序转换导出的数据
+     * @Date 17:10 2021/5/17
+     * @Param [list]
+     * @return java.util.List<java.util.List<java.lang.String>>
+     **/
+    public static List<List<String>> toHisoryDataReportExcelDto(List<ReportDto> list, int titleType){
+        int number = 1;
+        List<List<String>> result = new ArrayList<>();
+        if (CollectionUtil.isEmpty(list)){
+            return result;
+        }
+        for (ReportDto reportDto : list) {
+            List<String>  dataList = new ArrayList<>();
+            dataList.add((number++) +"");
+            dataList.add(reportDto.getParentSceneName());
+            dataList.add(reportDto.getCollectDate());
+            List<Map<String,Object>> childList = reportDto.getDataMapValues();
+            if (CollectionUtil.isEmpty(childList)) {
+                continue;
+            }
+            for (Map<String,Object> childMap: childList) {
+                int ok = 0;
+                for (Map.Entry<String,Object> entry : childMap.entrySet()) {
+                    if (ok == 0){
+                        ok++;
+                        continue;
+                    }
+                    dataList.add(entry.getValue() != null ? entry.getValue().toString() : "");
+                }
+            }
+            result.add(dataList);
+        }
+        return result;
+    }
 
 
 
@@ -85,8 +121,8 @@ public class ReportExcelUtil {
     * @Param [titleDtos, titleType]
     * @return java.util.List<java.util.List<java.lang.String>>
     **/
-    public static List<List<String>> toExcelTitleList(List<ReportTitleDto> titleDtos, int titleType){
-        List<List<String>> titleList = toTitleList(titleDtos);
+    public static List<List<String>> toExcelTitleList(List<ReportTitleDto> titleDtos, int titleType,int reportType){
+        List<List<String>> titleList = toTitleList(titleDtos,reportType);
         String[] shuZu  = TITLE_MAP.get(titleType);
         if (shuZu == null) {
             return titleList;
@@ -108,7 +144,7 @@ public class ReportExcelUtil {
         return result;
     }
 
-    private static List<List<String>> toTitleList(List<ReportTitleDto> list){
+    private static List<List<String>> toTitleList(List<ReportTitleDto> list,int reportType) {
         if (CollectionUtil.isEmpty(list)) {
             return null;
         }
@@ -117,24 +153,26 @@ public class ReportExcelUtil {
         String kongGe = " ";
         List<List<String>> result = new ArrayList<>();
         for (ReportTitleDto reportTitleDto : list) {
-            for (ReportTitleDto.DeviceChildren deviceChildren:reportTitleDto.getDeviceChildren()) {
-                for (ReportTitleDto.StatisticalDimension dimensionList:deviceChildren.getDimensionList()) {
+            for (ReportTitleDto.DeviceChildren deviceChildren : reportTitleDto.getDeviceChildren()) {
+                for (ReportTitleDto.StatisticalDimension dimensionList : deviceChildren.getDimensionList()) {
                     List<String> child = new ArrayList<>();
-                    child.add(reportTitleDto.getClassify().indexOf("isNull") != -1 ? deviceChildren.getName() :reportTitleDto.getClassify());
+                    child.add(reportTitleDto.getClassify().indexOf("isNull") != -1 ? deviceChildren.getName() : reportTitleDto.getClassify());
                     child.add(deviceChildren.getName());
-                    // 避免第三行,在邻列的情况下相同值被合并
-                    if (preDimensionName != null && preDimensionName.equals(dimensionList.getDimensionName())) {
-                        dimensionName = kongGe + dimensionList.getDimensionName();
-                    } else {
-                        dimensionName = dimensionList.getDimensionName();
+                    if (reportType == 0) {
+                        // 避免第三行,在邻列的情况下相同值被合并
+                        if (preDimensionName != null && preDimensionName.equals(dimensionList.getDimensionName())) {
+                            dimensionName = kongGe + dimensionList.getDimensionName();
+                        } else {
+                            dimensionName = dimensionList.getDimensionName();
+                        }
+                        child.add(dimensionName);
                     }
-                    child.add(dimensionName);
                     result.add(child);
                     preDimensionName = dimensionName;
                 }
             }
         }
-        return  result;
+        return result;
     }
 
     private static String doubleToString(Double doubleValue){