zmy18710171902 4 rokov pred
rodič
commit
f8da008e4e

+ 61 - 4
src/main/java/com/minpay/common/util/ExportUtils.java

@@ -1,14 +1,16 @@
 package com.minpay.common.util;
 
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFColor;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xssf.usermodel.*;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 /**
  *
  */
 public class ExportUtils {
+    public final static String COLUMNS_SEPARATOR = "#";//分割符
     /**
      * 描述列样式
      * @param wb
@@ -85,4 +87,59 @@ public class ExportUtils {
         style2.setFont(font2);
         return style2;
     }
+
+    public static String[] autocomplete(String[] titleArray, int manyTitle) {
+        for(int i = 0; i< titleArray.length; i++) {
+            titleArray[i] = completeStr(titleArray[i], manyTitle - titleArray[i].split(COLUMNS_SEPARATOR).length);
+        }
+        return titleArray;
+    }
+    private static String completeStr(String col, int count) {
+        if (count == 0) {
+            return col;
+        }
+        col = col.split(COLUMNS_SEPARATOR)[0] + COLUMNS_SEPARATOR + col;
+        return completeStr(col, --count);
+    }
+
+    /**
+     * 表头数据合并
+     * @param sheet
+     * @param coltitleIndex 列数
+     * @param colTitles 标题行
+     * @param num 行索引
+     */
+    public static void titleMerge(XSSFSheet sheet, int coltitleIndex, String[] colTitles, int num) {
+        for(int i = 0; i < num; i++) {
+            String preVal = "";
+            int columnIndex = 0;
+            for(int j = 0; j < colTitles.length; j++) {
+                columnIndex++;
+                preVal = colTitles[j].split(COLUMNS_SEPARATOR)[i];
+                String columnVal = colTitles[j + 1].split(COLUMNS_SEPARATOR)[i];
+                if(!"".equals(columnVal) && !preVal.equals(columnVal)) {
+                    List<Integer> list = new ArrayList<Integer>();
+                    for(int m = j - columnIndex + 1; m <= j; m++) {
+                        int bottom = 0;
+                        for(int k = i + 1; k <= num; k++) {
+                            String nextRowVal = "";
+                            try {
+                                nextRowVal = colTitles[m].split(COLUMNS_SEPARATOR)[k];
+                            } catch (Exception e) {
+                                list.add(bottom);
+                            }
+                            if(!"".equals(nextRowVal) && !preVal.equals(nextRowVal)) {
+                                list.add(bottom);
+                                break;
+                            }
+                            bottom++;
+                        }
+                    }
+                    Collections.sort(list);    //从小到大
+                    columnIndex = 0;
+                }
+                preVal = columnVal;
+            }
+        }
+    }
 }

+ 29 - 13
src/main/java/com/minpay/reportManage/action/XlgzzReportAction.java

@@ -299,8 +299,8 @@ public class XlgzzReportAction implements IMINAction {
 
         //******************************************抢修类工单明细******************************************//
         String[] titleArray3 = new String[]{"客户总量(户)","平均到达现场时间(分)","工单处理平均时长(分)","到达现场超时数",
-                "工单时长超70分钟数","客户内部故障","低压故障","非电力故障","电能质量等故障"};
-        String[] fieldArray3 = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
+                "工单时长超70分钟数","故障类型#客户内部故障","故障类型#低压故障","故障类型#非电力故障","故障类型#电能质量等故障","疑似虚假回单","工单总数","万户报修率"};
+        String[] fieldArray3 = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","","","",""};
         index = this.XlzgzCreateSheet(wb,index,"抢修类工单报表明细",titleArray3,fieldArray3,"",new ArrayList<>(),new HashMap<String,String>());
         return wb;
     }
@@ -308,7 +308,7 @@ public class XlgzzReportAction implements IMINAction {
         XSSFSheet sheet = wb.createSheet(sheetName);
         int rowIndex = 0;
         String title = StringUtil.ObjectToString(map.get("title"));
-        if(!"".equals(title)){
+        if(!"".equals(title)){//标题行
             XSSFRow row0 = sheet.createRow((int) rowIndex);// 行数从0开始
             row0.setHeightInPoints(30);//设置行的高度
             XSSFCell celldesc = row0.createCell(0);
@@ -317,7 +317,7 @@ public class XlgzzReportAction implements IMINAction {
             celldesc.setCellStyle(ExportUtils.getDescCellStyle(wb));
             rowIndex ++;
         }
-        if(!"".equals(descStr)){
+        if(!"".equals(descStr)){//描述行
             //添加描述行
             XSSFRow row0 = sheet.createRow((int) rowIndex);// 行数从0开始
             row0.setHeightInPoints(30);//设置行的高度
@@ -327,17 +327,33 @@ public class XlgzzReportAction implements IMINAction {
             celldesc.setCellStyle(ExportUtils.getDescCellStyle(wb));
             rowIndex++;
         }
-        if(titleArray.length > 0){
-            // 添加标题行
-            XSSFRow row1 = sheet.createRow((int) rowIndex);
-            for (int i = 0; i < titleArray.length; i++) {
-                XSSFCell titleCell = row1.createCell(i );// 0号位被序号占用,所以需+1
-                titleCell.setCellValue(titleArray[i]);
-                titleCell.setCellStyle(ExportUtils.getTitleCellStyle(wb));
-                sheet.setColumnWidth(i, 30 * 256);
+        int manyTitle = rowIndex;
+        if(titleArray.length > 0){//标题行
+            if (titleArray != null && titleArray.length > 0){
+                for (int i = 0; i < titleArray.length; i++) {
+                    for (String col : titleArray) {
+                        String[] colTitles = col.split(ExportUtils.COLUMNS_SEPARATOR);
+                        manyTitle = Math.max(manyTitle,colTitles.length);
+                    }
+                }
+            }
+            //重新组装表头
+            titleArray = ExportUtils.autocomplete(titleArray, manyTitle);
+            for (int j = 0; j < manyTitle; j++) {
+                XSSFRow row1 = sheet.createRow((int) rowIndex);
+                //  表头数据填充
+                 for(int i = 0; i < titleArray.length; i++) {
+                    XSSFCell titleCell = row1.createCell(i );// 0号位被序号占用,所以需+1
+                    titleCell.setCellValue(titleArray[i].split("#")[j]);
+                    titleCell.setCellStyle(ExportUtils.getTitleCellStyle(wb));
+                    sheet.setColumnWidth(i, 30 * 256);
+                }
+                rowIndex ++;
             }
-            rowIndex ++;
         }
+        //合并表头
+        ExportUtils.titleMerge(sheet, fieldArray.length, titleArray, manyTitle);
+
         //数据列
         for (int i = 0; i < list.size(); i++) {
             //创建行