Răsfoiți Sursa

用地统计导出功能

huZhiHao 6 ani în urmă
părinte
comite
79ebf560ac

+ 20 - 25
pom.xml

@@ -21,7 +21,7 @@
         <thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
         <thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
         <shiro.version>1.3.2</shiro.version>
-        <poi.version>3.9</poi.version>
+<!--        <poi.version>3.9</poi.version>-->
         <thymeleaf-shiro.version>2.0.0</thymeleaf-shiro.version>
         <hutool.version>2.16.0</hutool.version>
         <commons-io.version>2.4</commons-io.version>
@@ -244,21 +244,21 @@
             <version>1.2.44</version>
         </dependency>
         <!-- poi office -->
-        <dependency>
-            <groupId>org.apache.poi</groupId>
-            <artifactId>poi</artifactId>
-            <version>${poi.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.poi</groupId>
-            <artifactId>poi-ooxml</artifactId>
-            <version>${poi.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.poi</groupId>
-            <artifactId>poi-ooxml-schemas</artifactId>
-            <version>${poi.version}</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>poi</artifactId>-->
+<!--            <version>${poi.version}</version>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>poi-ooxml</artifactId>-->
+<!--            <version>${poi.version}</version>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>poi-ooxml-schemas</artifactId>-->
+<!--            <version>${poi.version}</version>-->
+<!--        </dependency>-->
 
         <dependency>
             <groupId>org.projectlombok</groupId>
@@ -358,16 +358,11 @@
             <artifactId>jxls</artifactId>
             <version>2.4.7</version>
         </dependency>
-        <!-- https://mvnrepository.com/artifact/org.jxls/jxls-poi -->
-        <dependency>
-            <groupId>org.jxls</groupId>
-            <artifactId>jxls-poi</artifactId>
-            <version>1.0.12</version>
-        </dependency>
+
         <dependency>
-            <groupId>org.jxls</groupId>
-            <artifactId>jxls-jexcel</artifactId>
-            <version>1.0.6</version>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>2.1.6</version>
         </dependency>
     </dependencies>
 

+ 437 - 421
src/main/java/platform/common/util/ExportExcel.java

@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@@ -23,430 +24,445 @@ import java.net.URLEncoder;
 import java.util.*;
 
 public class ExportExcel {
-	
-	private static Logger log = LoggerFactory.getLogger(ExportExcel.class);
-			
-	/**
-	 * 工作薄对象
-	 */
-	private SXSSFWorkbook wb;
-	
-	/**
-	 * 工作表对象
-	 */
-	private Sheet sheet;
-	
-	/**
-	 * 样式列表
-	 */
-	private Map<String, CellStyle> styles;
-	
-	/**
-	 * 当前行号
-	 */
-	private int rownum;
-	
-	/**
-	 * 注解列表(Object[]{ ExcelField, Field/Method })
-	 */
-	List<Object[]> annotationList = Lists.newArrayList();
-	
-	/**
-	 * 构造函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param cls 实体对象,通过annotation.ExportField获取标题
-	 */
-	public ExportExcel(String title, Class<?> cls){
-		this(title, cls, 1);
-	}
-	
-	/**
-	 * 构造函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param cls 实体对象,通过annotation.ExportField获取标题
-	 * @param type 导出类型(1:导出数据;2:导出模板)
-	 * @param groups 导入分组
-	 */
-	public ExportExcel(String title, Class<?> cls, int type, int... groups){
-		// Get annotation field 
-		Field[] fs = cls.getDeclaredFields();
-		for (Field f : fs){
-			ExcelField ef = f.getAnnotation(ExcelField.class);
-			if (ef != null && (ef.type()==0 || ef.type()==type)){
-				if (groups!=null && groups.length>0){
-					boolean inGroup = false;
-					for (int g : groups){
-						if (inGroup){
-							break;
-						}
-						for (int efg : ef.groups()){
-							if (g == efg){
-								inGroup = true;
-								annotationList.add(new Object[]{ef, f});
-								break;
-							}
-						}
-					}
-				}else{
-					annotationList.add(new Object[]{ef, f});
-				}
-			}
-		}
-		// Get annotation method
-		Method[] ms = cls.getDeclaredMethods();
-		for (Method m : ms){
-			ExcelField ef = m.getAnnotation(ExcelField.class);
-			if (ef != null && (ef.type()==0 || ef.type()==type)){
-				if (groups!=null && groups.length>0){
-					boolean inGroup = false;
-					for (int g : groups){
-						if (inGroup){
-							break;
-						}
-						for (int efg : ef.groups()){
-							if (g == efg){
-								inGroup = true;
-								annotationList.add(new Object[]{ef, m});
-								break;
-							}
-						}
-					}
-				}else{
-					annotationList.add(new Object[]{ef, m});
-				}
-			}
-		}
-		// Field sorting
-		Collections.sort(annotationList, new Comparator<Object[]>() {
-			public int compare(Object[] o1, Object[] o2) {
-				return new Integer(((ExcelField)o1[0]).sort()).compareTo(
-						new Integer(((ExcelField)o2[0]).sort()));
-			};
-		});
-		// Initialize
-		List<String> headerList = Lists.newArrayList();
-		for (Object[] os : annotationList){
-			String t = ((ExcelField)os[0]).title();
-			// 如果是导出,则去掉注释
-			if (type==1){
-				String[] ss = StringUtils.split(t, "**", 2);
-				if (ss.length==2){
-					t = ss[0];
-				}
-			}
-			headerList.add(t);
-		}
-		initialize(title, headerList);
-	}
-
-	/**
-	 * 构造函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param headerList 表头列表
-	 */
-	public ExportExcel(String title, List<String> headerList) {
-		initialize(title, headerList);
-	}
-	/**
-	 * 添加数据(通过annotation.ExportField添加数据)
-	 * @return list 数据列表
-	 */
-	public <E> ExportExcel setDataList(List<E> list){
-		for (E e : list){
-			int colunm = 0;
-			Row row = this.addRow();
-			StringBuilder sb = new StringBuilder();
-			for (Object[] os : annotationList){
-				ExcelField ef = (ExcelField)os[0];
-				Object val = null;
-				// Get entity value
-				try{
-					if (StringUtils.isNotBlank(ef.value())){
-						val = Reflections.invokeGetter(e, ef.value());
-					}else{
-						if (os[1] instanceof Field){
-							val = Reflections.invokeGetter(e, ((Field)os[1]).getName());
-						}else if (os[1] instanceof Method){
-							val = Reflections.invokeMethod(e, ((Method)os[1]).getName(), new Class[] {}, new Object[] {});
-						}
-					}
-				}catch(Exception ex) {
-					// Failure to ignore
-					log.info(ex.toString());
-					val = "";
-				}
-				this.addCell(row, colunm++, val, ef.align(), ef.fieldType());
-				sb.append(val + ", ");
-			}
-			log.debug("Write success: ["+row.getRowNum()+"] "+sb.toString());
-		}
-		return this;
-	}
-
-	/**
-	 * 初始化函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param headerList 表头列表
-	 */
-	private void initialize(String title, List<String> headerList) {
-		this.wb = new SXSSFWorkbook(500);
-		this.sheet = wb.createSheet("Export");
-		this.styles = createStyles(wb);
-		// Create title
-		if (StringUtils.isNotBlank(title)){
-			Row titleRow = sheet.createRow(rownum++);
-			titleRow.setHeightInPoints(30);
-			Cell titleCell = titleRow.createCell(0);
-			titleCell.setCellStyle(styles.get("title"));
-			titleCell.setCellValue(title);
-			sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
-					titleRow.getRowNum(), titleRow.getRowNum(), headerList.size()-1));
-		}
-		// Create header
-		if (headerList == null){
-			throw new RuntimeException("headerList not null!");
-		}
-		Row headerRow = sheet.createRow(rownum++);
-		headerRow.setHeightInPoints(16);
-		for (int i = 0; i < headerList.size(); i++) {
-			Cell cell = headerRow.createCell(i);
-			cell.setCellStyle(styles.get("header"));
-			String[] ss = StringUtils.split(headerList.get(i), "**", 2);
-			if (ss.length==2){
-				cell.setCellValue(ss[0]);
-				Comment comment = this.sheet.createDrawingPatriarch().createCellComment(
-						new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
-				comment.setString(new XSSFRichTextString(ss[1]));
-				cell.setCellComment(comment);
-			}else{
-				cell.setCellValue(headerList.get(i));
-			}
-			sheet.autoSizeColumn(i);
-		}
-		for (int i = 0; i < headerList.size(); i++) {  
-			int colWidth = sheet.getColumnWidth(i)*2;
-	        sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);  
-		}
-		log.debug("Initialize success.");
-	}
-	
-	/**
-	 * 创建表格样式
-	 * @param wb 工作薄对象
-	 * @return 样式列表
-	 */
-	private Map<String, CellStyle> createStyles(Workbook wb) {
-		Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
-		
-		CellStyle style = wb.createCellStyle();
-		style.setAlignment(CellStyle.ALIGN_CENTER);
-		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
-		Font titleFont = wb.createFont();
-		titleFont.setFontName("Arial");
-		titleFont.setFontHeightInPoints((short) 16);
-		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
-		style.setFont(titleFont);
-		styles.put("title", style);
-
-		style = wb.createCellStyle();
-		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
-		style.setBorderRight(CellStyle.BORDER_THIN);
-		style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
-		style.setBorderLeft(CellStyle.BORDER_THIN);
-		style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
-		style.setBorderTop(CellStyle.BORDER_THIN);
-		style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
-		style.setBorderBottom(CellStyle.BORDER_THIN);
-		style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
-		Font dataFont = wb.createFont();
-		dataFont.setFontName("Arial");
-		dataFont.setFontHeightInPoints((short) 10);
-		style.setFont(dataFont);
-		styles.put("data", style);
-		
-		style = wb.createCellStyle();
-		style.cloneStyleFrom(styles.get("data"));
-		style.setAlignment(CellStyle.ALIGN_LEFT);
-		styles.put("data1", style);
-
-		style = wb.createCellStyle();
-		style.cloneStyleFrom(styles.get("data"));
-		style.setAlignment(CellStyle.ALIGN_CENTER);
-		styles.put("data2", style);
-
-		style = wb.createCellStyle();
-		style.cloneStyleFrom(styles.get("data"));
-		style.setAlignment(CellStyle.ALIGN_RIGHT);
-		styles.put("data3", style);
-		
-		style = wb.createCellStyle();
-		style.cloneStyleFrom(styles.get("data"));
+
+    private static Logger log = LoggerFactory.getLogger(ExportExcel.class);
+
+    /**
+     * 工作薄对象
+     */
+    private SXSSFWorkbook wb;
+
+    /**
+     * 工作表对象
+     */
+    private Sheet sheet;
+
+    /**
+     * 样式列表
+     */
+    private Map<String, CellStyle> styles;
+
+    /**
+     * 当前行号
+     */
+    private int rownum;
+
+    /**
+     * 注解列表(Object[]{ ExcelField, Field/Method })
+     */
+    List<Object[]> annotationList = Lists.newArrayList();
+
+    /**
+     * 构造函数
+     *
+     * @param title 表格标题,传“空值”,表示无标题
+     * @param cls   实体对象,通过annotation.ExportField获取标题
+     */
+    public ExportExcel(String title, Class<?> cls) {
+        this(title, cls, 1);
+    }
+
+    /**
+     * 构造函数
+     *
+     * @param title  表格标题,传“空值”,表示无标题
+     * @param cls    实体对象,通过annotation.ExportField获取标题
+     * @param type   导出类型(1:导出数据;2:导出模板)
+     * @param groups 导入分组
+     */
+    public ExportExcel(String title, Class<?> cls, int type, int... groups) {
+        // Get annotation field
+        Field[] fs = cls.getDeclaredFields();
+        for (Field f : fs) {
+            ExcelField ef = f.getAnnotation(ExcelField.class);
+            if (ef != null && (ef.type() == 0 || ef.type() == type)) {
+                if (groups != null && groups.length > 0) {
+                    boolean inGroup = false;
+                    for (int g : groups) {
+                        if (inGroup) {
+                            break;
+                        }
+                        for (int efg : ef.groups()) {
+                            if (g == efg) {
+                                inGroup = true;
+                                annotationList.add(new Object[]{ef, f});
+                                break;
+                            }
+                        }
+                    }
+                } else {
+                    annotationList.add(new Object[]{ef, f});
+                }
+            }
+        }
+        // Get annotation method
+        Method[] ms = cls.getDeclaredMethods();
+        for (Method m : ms) {
+            ExcelField ef = m.getAnnotation(ExcelField.class);
+            if (ef != null && (ef.type() == 0 || ef.type() == type)) {
+                if (groups != null && groups.length > 0) {
+                    boolean inGroup = false;
+                    for (int g : groups) {
+                        if (inGroup) {
+                            break;
+                        }
+                        for (int efg : ef.groups()) {
+                            if (g == efg) {
+                                inGroup = true;
+                                annotationList.add(new Object[]{ef, m});
+                                break;
+                            }
+                        }
+                    }
+                } else {
+                    annotationList.add(new Object[]{ef, m});
+                }
+            }
+        }
+        // Field sorting
+        Collections.sort(annotationList, new Comparator<Object[]>() {
+            public int compare(Object[] o1, Object[] o2) {
+                return new Integer(((ExcelField) o1[0]).sort()).compareTo(
+                        new Integer(((ExcelField) o2[0]).sort()));
+            }
+
+            ;
+        });
+        // Initialize
+        List<String> headerList = Lists.newArrayList();
+        for (Object[] os : annotationList) {
+            String t = ((ExcelField) os[0]).title();
+            // 如果是导出,则去掉注释
+            if (type == 1) {
+                String[] ss = StringUtils.split(t, "**", 2);
+                if (ss.length == 2) {
+                    t = ss[0];
+                }
+            }
+            headerList.add(t);
+        }
+        initialize(title, headerList);
+    }
+
+    /**
+     * 构造函数
+     *
+     * @param title      表格标题,传“空值”,表示无标题
+     * @param headerList 表头列表
+     */
+    public ExportExcel(String title, List<String> headerList) {
+        initialize(title, headerList);
+    }
+
+    /**
+     * 添加数据(通过annotation.ExportField添加数据)
+     *
+     * @return list 数据列表
+     */
+    public <E> ExportExcel setDataList(List<E> list) {
+        for (E e : list) {
+            int colunm = 0;
+            Row row = this.addRow();
+            StringBuilder sb = new StringBuilder();
+            for (Object[] os : annotationList) {
+                ExcelField ef = (ExcelField) os[0];
+                Object val = null;
+                // Get entity value
+                try {
+                    if (StringUtils.isNotBlank(ef.value())) {
+                        val = Reflections.invokeGetter(e, ef.value());
+                    } else {
+                        if (os[1] instanceof Field) {
+                            val = Reflections.invokeGetter(e, ((Field) os[1]).getName());
+                        } else if (os[1] instanceof Method) {
+                            val = Reflections.invokeMethod(e, ((Method) os[1]).getName(), new Class[]{}, new Object[]{});
+                        }
+                    }
+                } catch (Exception ex) {
+                    // Failure to ignore
+                    log.info(ex.toString());
+                    val = "";
+                }
+                this.addCell(row, colunm++, val, ef.align(), ef.fieldType());
+                sb.append(val + ", ");
+            }
+            log.debug("Write success: [" + row.getRowNum() + "] " + sb.toString());
+        }
+        return this;
+    }
+
+    /**
+     * 初始化函数
+     *
+     * @param title      表格标题,传“空值”,表示无标题
+     * @param headerList 表头列表
+     */
+    private void initialize(String title, List<String> headerList) {
+        this.wb = new SXSSFWorkbook(500);
+        this.sheet = wb.createSheet("Export");
+        this.styles = createStyles(wb);
+        // Create title
+        if (StringUtils.isNotBlank(title)) {
+            Row titleRow = sheet.createRow(rownum++);
+            titleRow.setHeightInPoints(30);
+            Cell titleCell = titleRow.createCell(0);
+            titleCell.setCellStyle(styles.get("title"));
+            titleCell.setCellValue(title);
+            sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
+                    titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1));
+        }
+        // Create header
+        if (headerList == null) {
+            throw new RuntimeException("headerList not null!");
+        }
+        Row headerRow = sheet.createRow(rownum++);
+        headerRow.setHeightInPoints(16);
+        for (int i = 0; i < headerList.size(); i++) {
+            Cell cell = headerRow.createCell(i);
+            cell.setCellStyle(styles.get("header"));
+            String[] ss = StringUtils.split(headerList.get(i), "**", 2);
+            if (ss.length == 2) {
+                cell.setCellValue(ss[0]);
+                Comment comment = this.sheet.createDrawingPatriarch().createCellComment(
+                        new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
+                comment.setString(new XSSFRichTextString(ss[1]));
+                cell.setCellComment(comment);
+            } else {
+                cell.setCellValue(headerList.get(i));
+            }
+//            sheet.autoSizeColumn(i);
+        }
+        for (int i = 0; i < headerList.size(); i++) {
+            int colWidth = sheet.getColumnWidth(i) * 2;
+            sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
+        }
+        log.debug("Initialize success.");
+    }
+
+    /**
+     * 创建表格样式
+     *
+     * @param wb 工作薄对象
+     * @return 样式列表
+     */
+    private Map<String, CellStyle> createStyles(Workbook wb) {
+        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
+
+        CellStyle style = wb.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+        Font titleFont = wb.createFont();
+        titleFont.setFontName("Arial");
+        titleFont.setFontHeightInPoints((short) 16);
+        titleFont.setBold(true);
+        style.setFont(titleFont);
+        styles.put("title", style);
+
+        style = wb.createCellStyle();
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+        style.setBorderRight(BorderStyle.THIN);
+        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
+        style.setBorderLeft(BorderStyle.THIN);
+        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
+        style.setBorderTop(BorderStyle.THIN);
+        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
+        style.setBorderBottom(BorderStyle.THIN);
+        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
+        Font dataFont = wb.createFont();
+        dataFont.setFontName("Arial");
+        dataFont.setFontHeightInPoints((short) 10);
+        style.setFont(dataFont);
+        styles.put("data", style);
+
+        style = wb.createCellStyle();
+        style.cloneStyleFrom(styles.get("data"));
+        style.setAlignment(HorizontalAlignment.LEFT);
+        styles.put("data1", style);
+
+        style = wb.createCellStyle();
+        style.cloneStyleFrom(styles.get("data"));
+        style.setAlignment(HorizontalAlignment.CENTER);
+        styles.put("data2", style);
+
+        style = wb.createCellStyle();
+        style.cloneStyleFrom(styles.get("data"));
+        style.setAlignment(HorizontalAlignment.RIGHT);
+        styles.put("data3", style);
+
+        style = wb.createCellStyle();
+        style.cloneStyleFrom(styles.get("data"));
 //		style.setWrapText(true);
-		style.setAlignment(CellStyle.ALIGN_CENTER);
-		style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
-		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
-		Font headerFont = wb.createFont();
-		headerFont.setFontName("Arial");
-		headerFont.setFontHeightInPoints((short) 10);
-		headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
-		headerFont.setColor(IndexedColors.WHITE.getIndex());
-		style.setFont(headerFont);
-		styles.put("header", style);
-		
-		return styles;
-	}
-
-	/**
-	 * 添加一行
-	 * @return 行对象
-	 */
-	public Row addRow(){
-		return sheet.createRow(rownum++);
-	}
-	
-
-	/**
-	 * 添加一个单元格
-	 * @param row 添加的行
-	 * @param column 添加列号
-	 * @param val 添加值
-	 * @return 单元格对象
-	 */
-	public Cell addCell(Row row, int column, Object val){
-		return this.addCell(row, column, val, 0, Class.class);
-	}
-	
-	/**
-	 * 添加一个单元格
-	 * @param row 添加的行
-	 * @param column 添加列号
-	 * @param val 添加值
-	 * @param align 对齐方式(1:靠左;2:居中;3:靠右)
-	 * @return 单元格对象
-	 */
-	public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType){
-		Cell cell = row.createCell(column);
-		String cellFormatString = "@";
-		try {
-			if(val == null){
-				cell.setCellValue("");
-			}else if(fieldType != Class.class){
-				cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val));
-			}else{
-				if(val instanceof String) {
-					cell.setCellValue((String) val);
-				}else if(val instanceof Integer) {
-					cell.setCellValue((Integer) val);
-					cellFormatString = "0";
-				}else if(val instanceof Long) {
-					cell.setCellValue((Long) val);
-					cellFormatString = "0";
-				}else if(val instanceof Double) {
-					cell.setCellValue((Double) val);
-					cellFormatString = "0.00";
-				}else if(val instanceof Float) {
-					cell.setCellValue((Float) val);
-					cellFormatString = "0.00";
-				}else if(val instanceof Date) {
-					cell.setCellValue((Date) val);
-					cellFormatString = "yyyy-MM-dd HH:mm";
-				}else {
-					cell.setCellValue((String)Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), 
-						"fieldtype."+val.getClass().getSimpleName()+"Type")).getMethod("setValue", Object.class).invoke(null, val));
-				}
-			}
+        style.setAlignment(HorizontalAlignment.CENTER);
+        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
+        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        Font headerFont = wb.createFont();
+        headerFont.setFontName("Arial");
+        headerFont.setFontHeightInPoints((short) 10);
+        headerFont.setBold(true);
+        headerFont.setColor(IndexedColors.WHITE.getIndex());
+        style.setFont(headerFont);
+        styles.put("header", style);
+
+        return styles;
+    }
+
+    /**
+     * 添加一行
+     *
+     * @return 行对象
+     */
+    public Row addRow() {
+        return sheet.createRow(rownum++);
+    }
+
+
+    /**
+     * 添加一个单元格
+     *
+     * @param row    添加的行
+     * @param column 添加列号
+     * @param val    添加值
+     * @return 单元格对象
+     */
+    public Cell addCell(Row row, int column, Object val) {
+        return this.addCell(row, column, val, 0, Class.class);
+    }
+
+    /**
+     * 添加一个单元格
+     *
+     * @param row    添加的行
+     * @param column 添加列号
+     * @param val    添加值
+     * @param align  对齐方式(1:靠左;2:居中;3:靠右)
+     * @return 单元格对象
+     */
+    public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType) {
+        Cell cell = row.createCell(column);
+        String cellFormatString = "@";
+        try {
+            if (val == null) {
+                cell.setCellValue("");
+            } else if (fieldType != Class.class) {
+                cell.setCellValue((String) fieldType.getMethod("setValue", Object.class).invoke(null, val));
+            } else {
+                if (val instanceof String) {
+                    cell.setCellValue((String) val);
+                } else if (val instanceof Integer) {
+                    cell.setCellValue((Integer) val);
+                    cellFormatString = "0";
+                } else if (val instanceof Long) {
+                    cell.setCellValue((Long) val);
+                    cellFormatString = "0";
+                } else if (val instanceof Double) {
+                    cell.setCellValue((Double) val);
+                    cellFormatString = "0.00";
+                } else if (val instanceof Float) {
+                    cell.setCellValue((Float) val);
+                    cellFormatString = "0.00";
+                } else if (val instanceof Date) {
+                    cell.setCellValue((Date) val);
+                    cellFormatString = "yyyy-MM-dd HH:mm";
+                } else {
+                    cell.setCellValue((String) Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
+                            "fieldtype." + val.getClass().getSimpleName() + "Type")).getMethod("setValue", Object.class).invoke(null, val));
+                }
+            }
 //			if (val != null){
-				CellStyle style = styles.get("data_column_"+column);
-				if (style == null){
-					style = wb.createCellStyle();
-					style.cloneStyleFrom(styles.get("data"+(align>=1&&align<=3?align:"")));
-			        style.setDataFormat(wb.createDataFormat().getFormat(cellFormatString));
-					styles.put("data_column_" + column, style);
-				}
-				cell.setCellStyle(style);
+            CellStyle style = styles.get("data_column_" + column);
+            if (style == null) {
+                style = wb.createCellStyle();
+                style.cloneStyleFrom(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
+                style.setDataFormat(wb.createDataFormat().getFormat(cellFormatString));
+                styles.put("data_column_" + column, style);
+            }
+            cell.setCellStyle(style);
 //			}
-		} catch (Exception ex) {
-			log.info("Set cell value ["+row.getRowNum()+","+column+"] error: " + ex.toString());
-			cell.setCellValue(val.toString());
-		}
-		return cell;
-	}
-
-
-	/**
-	 * 输出数据流
-	 * @param os 输出数据流
-	 */
-	public ExportExcel write(OutputStream os) throws IOException{
-		wb.write(os);
-		return this;
-	}
-	
-	/**
-	 * 输出到客户端
-	 * @param fileName 输出文件名
-	 */
-	public ExportExcel write(HttpServletResponse response, String fileName) throws IOException{
-		response.reset();
+        } catch (Exception ex) {
+            log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString());
+            cell.setCellValue(val.toString());
+        }
+        return cell;
+    }
+
+
+    /**
+     * 输出数据流
+     *
+     * @param os 输出数据流
+     */
+    public ExportExcel write(OutputStream os) throws IOException {
+        wb.write(os);
+        return this;
+    }
+
+    /**
+     * 输出到客户端
+     *
+     * @param fileName 输出文件名
+     */
+    public ExportExcel write(HttpServletResponse response, String fileName) throws IOException {
+        response.reset();
         response.setContentType("application/octet-stream; charset=utf-8");
-        response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(fileName, "UTF-8"));
-		write(response.getOutputStream());
-		return this;
-	}
-	
-	/**
-	 * 输出到文件
-	 * @param name 输出文件名
-	 */
-	public ExportExcel writeFile(String name) throws FileNotFoundException, IOException{
-		FileOutputStream os = new FileOutputStream(name);
-		this.write(os);
-		return this;
-	}
-	
-	/**
-	 * 清理临时文件
-	 */
-	public ExportExcel dispose(){
-		wb.dispose();
-		return this;
-	}
-	
-	/**
-	 * 导出测试
-	 */
-	public static void main(String[] args) throws Throwable {
-
-		List<String> headerList = Lists.newArrayList();
-		for (int i = 1; i <= 10; i++) {
-			headerList.add("表头"+i);
-		}
-
-		List<String> dataRowList = Lists.newArrayList();
-		for (int i = 1; i <= headerList.size(); i++) {
-			dataRowList.add("数据"+i);
-		}
-
-		List<List<String>> dataList = Lists.newArrayList();
-		for (int i = 1; i <=1000000; i++) {
-			dataList.add(dataRowList);
-		}
-
-		ExportExcel ee = new ExportExcel("表格标题", headerList);
-
-		for (int i = 0; i < dataList.size(); i++) {
-			Row row = ee.addRow();
-			for (int j = 0; j < dataList.get(i).size(); j++) {
-				ee.addCell(row, j, dataList.get(i).get(j));
-			}
-		}
-
-		ee.writeFile("target/export.xlsx");
-
-		ee.dispose();
-
-		log.debug("Export success.");
-
-	}
+        response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
+        write(response.getOutputStream());
+        return this;
+    }
+
+    /**
+     * 输出到文件
+     *
+     * @param name 输出文件名
+     */
+    public ExportExcel writeFile(String name) throws FileNotFoundException, IOException {
+        FileOutputStream os = new FileOutputStream(name);
+        this.write(os);
+        return this;
+    }
+
+    /**
+     * 清理临时文件
+     */
+    public ExportExcel dispose() {
+        wb.dispose();
+        return this;
+    }
+
+    /**
+     * 导出测试
+     */
+    public static void main(String[] args) throws Throwable {
+
+        List<String> headerList = Lists.newArrayList();
+        for (int i = 1; i <= 10; i++) {
+            headerList.add("表头" + i);
+        }
+
+        List<String> dataRowList = Lists.newArrayList();
+        for (int i = 1; i <= headerList.size(); i++) {
+            dataRowList.add("数据" + i);
+        }
+
+        List<List<String>> dataList = Lists.newArrayList();
+        for (int i = 1; i <= 1000000; i++) {
+            dataList.add(dataRowList);
+        }
+
+        ExportExcel ee = new ExportExcel("表格标题", headerList);
+
+        for (int i = 0; i < dataList.size(); i++) {
+            Row row = ee.addRow();
+            for (int j = 0; j < dataList.get(i).size(); j++) {
+                ee.addCell(row, j, dataList.get(i).get(j));
+            }
+        }
+
+        ee.writeFile("target/export.xlsx");
+
+        ee.dispose();
+
+        log.debug("Export success.");
+
+    }
 
 }

+ 0 - 87
src/main/java/platform/common/util/JxlsUtils.java

@@ -1,87 +0,0 @@
-package platform.common.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jxls.common.Context;
-import org.jxls.expression.JexlExpressionEvaluator;
-import org.jxls.transform.Transformer;
-import org.jxls.transform.poi.PoiTransformer;
-import org.jxls.util.JxlsHelper;
-
-/**
- * @author klguang
- */
-public class JxlsUtils{
-
-    public static void exportExcel(InputStream is, OutputStream os, Map<String, Object> model) throws IOException{
-        Context context = PoiTransformer.createInitialContext();
-        if (model != null) {
-            for (String key : model.keySet()) {
-                context.putVar(key, model.get(key));
-            }
-        }
-        JxlsHelper jxlsHelper = JxlsHelper.getInstance();
-        Transformer transformer  = jxlsHelper.createTransformer(is, os);
-        //获得配置
-        JexlExpressionEvaluator evaluator = (JexlExpressionEvaluator)transformer.getTransformationConfig().getExpressionEvaluator();
-        //设置静默模式,不报警告
-        //evaluator.getJexlEngine().setSilent(true);
-        //函数强制,自定义功能
-        Map<String, Object> funcs = new HashMap<String, Object>();
-        funcs.put("utils", new JxlsUtils());    //添加自定义功能
-        evaluator.getJexlEngine().setFunctions(funcs);
-        //必须要这个,否者表格函数统计会错乱
-        jxlsHelper.setUseFastFormulaProcessor(false).processTemplate(context, transformer);
-    }
-
-    public static void exportExcel(File xls, File out, Map<String, Object> model) throws FileNotFoundException, IOException {
-        exportExcel(new FileInputStream(xls), new FileOutputStream(out), model);
-    }
-
-    public static void exportExcel(String templatePath, OutputStream os, Map<String, Object> model) throws Exception {
-        File template = getTemplate(templatePath);
-        if(template != null){
-            exportExcel(new FileInputStream(template), os, model);
-        } else {
-            throw new Exception("Excel 模板未找到。");
-        }
-    }
-
-    //获取jxls模版文件
-    public static File getTemplate(String path){
-        File template = new File(path);
-        if(template.exists()){
-            return template;
-        }
-        return null;
-    }
-
-    // 日期格式化
-    public String dateFmt(Date date, String fmt) {
-        if (date == null) {
-            return "";
-        }
-        try {
-            SimpleDateFormat dateFmt = new SimpleDateFormat(fmt);
-            return dateFmt.format(date);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return "";
-    }
-
-    // if判断
-    public Object ifelse(boolean b, Object o1, Object o2) {
-        return b ? o1 : o2;
-    }
-}

+ 79 - 0
src/main/java/platform/common/util/excel/DynamicOneSheetEasyExcel.java

@@ -0,0 +1,79 @@
+package platform.common.util.excel;
+
+import com.alibaba.excel.EasyExcel;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class DynamicOneSheetEasyExcel implements OneSheetEasyExcel {
+    // 文件后缀名 固定
+    private static final String EXCEL_SUFFIX = ".xlsx";
+    // 文件名称
+    private String name;
+
+    private List<String> header;
+
+    private String sheetName;
+
+    @Override
+    public void setHeader(List<String> header) {
+        this.header = header;
+    }
+
+    @Override
+    public DynamicOneSheetEasyExcel setHeader(String header) {
+        if (this.header == null) {
+            setHeader(new ArrayList<>());
+        }
+        this.header.add(header);
+        return this;
+    }
+
+    @Override
+    public void setData(List<List<String>> data) {
+        EasyExcel.write(getName())
+                // 这里放入动态头
+                .head(getHeader())
+                .sheet(getSheetName())
+                // 当然这里数据也可以用 List<List<String>> 去传入
+                .doWrite(data);
+    }
+
+    @Override
+    public void exportData(List<List<String>> data, HttpServletResponse response) throws IOException {
+        EasyExcel.write(response.getOutputStream())
+                // 这里放入动态头
+                .head(getHeader())
+                .sheet(getSheetName())
+                // 当然这里数据也可以用 List<List<String>> 去传入
+                .doWrite(data);
+    }
+
+
+    public String getName() {
+        return name + EXCEL_SUFFIX;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List<List<String>> getHeader() {
+        List<List<String>> headerList = new ArrayList<List<String>>();
+        header.forEach(str -> {
+            headerList.add(new ArrayList<>(Arrays.asList(str)));
+        });
+        return headerList;
+    }
+
+    public void setSheetName(String sheetName) {
+        this.sheetName = sheetName;
+    }
+
+    public String getSheetName() {
+        return sheetName;
+    }
+}

+ 29 - 0
src/main/java/platform/common/util/excel/OneSheetEasyExcel.java

@@ -0,0 +1,29 @@
+package platform.common.util.excel;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+public interface OneSheetEasyExcel {
+
+    // 设置名称
+    void setName(String name);
+
+    // 设置名称
+    String getName();
+
+    // 设置sheet名称
+    void setSheetName(String sheetName);
+
+    // 创建头部
+    void setHeader(List<String> header);
+
+    // 链式设置头部
+    OneSheetEasyExcel setHeader(String header);
+
+    // 创建数据
+    void setData(List<List<String>> data);
+
+    // 导出到response
+    void exportData(List<List<String>> data, HttpServletResponse response) throws IOException;
+}

+ 63 - 0
src/main/java/platform/modules/government/dto/ApproveStatisticMonthly.java

@@ -0,0 +1,63 @@
+package platform.modules.government.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+/**
+ * @Author :huZhiHao
+ * @Date :Created in 2020/2/10 9:44
+ * @Description: 月度审核统计导出模板
+ * @Modified By:
+ * @Version: v0.0.1
+ */
+@Data
+public class ApproveStatisticMonthly {
+
+    @ExcelProperty(value = {" "," "},index = 0)
+    private String rowName;
+
+    @ExcelProperty(value = {"存量工业用地房屋出租","提交数"},index = 1)
+    private String rentApplyNum;
+
+    @ExcelProperty(value = {"存量工业用地房屋出租","通过数"},index = 2)
+    private String rentPassNum;
+
+    @ExcelProperty(value = {"存量工业用地房屋出租","通过率"},index = 3)
+    private String rentPassRate;
+
+    @ExcelProperty(value = {"存量工业用地用途依法改变","提交数"},index = 4)
+    private String useChangeApplyNum;
+
+    @ExcelProperty(value = {"存量工业用地用途依法改变","通过数"},index = 5)
+    private String useChangePassNum;
+
+    @ExcelProperty(value = {"存量工业用地用途依法改变","通过率"},index = 6)
+    private String useChangePassRate;
+
+    @ExcelProperty(value = {"存量工业用地不动产权权属转移登记","提交数"},index = 7)
+    private String immovablesChangeApplyNum;
+
+    @ExcelProperty(value = {"存量工业用地不动产权权属转移登记","通过数"},index = 8)
+    private String immovablesChangePassNum;
+
+    @ExcelProperty(value = {"存量工业用地不动产权权属转移登记","通过率"},index = 9)
+    private String immovablesChangePassRate;
+
+    @ExcelProperty(value = {"存量工业用地项目公司股权(结构)变更登记","提交数"},index = 10)
+    private String equityStructureChangeApplyNum;
+
+    @ExcelProperty(value = {"存量工业用地项目公司股权(结构)变更登记","通过数"},index = 11)
+    private String equityStructureChangePassNum;
+
+    @ExcelProperty(value = {"存量工业用地项目公司股权(结构)变更登记","通过率"},index = 12)
+    private String equityStructureChangePassRate;
+
+    @ExcelProperty(value = {"汇总","提交数"},index = 13)
+    private String totalApplyNum;
+
+    @ExcelProperty(value = {"汇总","通过数"},index = 14)
+    private String totalPassNum;
+
+    @ExcelProperty(value = {"汇总","通过率"},index = 15)
+    private String totalPassRate;
+}

+ 4 - 1
src/main/java/platform/modules/government/service/LandStatisticsService.java

@@ -581,6 +581,9 @@ public class LandStatisticsService {
                 summaryProcedureApplyAmountNum += summaryProcedureApplyNum;
                 summaryProcedurePassAmountNum += summaryProcedurePassNum;
 
+                totalApplyAmountNum += totalApplyNum;
+                totalPassAmountNum += totalPassNum;
+
                 map.put("rentApplyNum", rentApplyNum);
                 map.put("rentPassNum", rentPassNum);
                 map.put("rentPassRate", rentApplyNum == 0 ? 0 : rentPassNum * 100 / rentApplyNum);
@@ -936,7 +939,7 @@ public class LandStatisticsService {
         /*不通过数量*/
 
         /*通过率*/
-        for (int i = 0; i < streetList.size(); i++) {
+        for (int i = 0; i <= streetList.size(); i++) {
             rentPassRate[i] = rentApplyNum[i] == 0 ? 0 : rentPassNum[i] * 100 / rentApplyNum[i];
             useChangePassRate[i] = useChangeApplyNum[i] == 0 ? 0 : useChangePassNum[i] * 100 / useChangeApplyNum[i];
             immovablesChangePassRate[i] = immovablesChangeApplyNum[i] == 0 ? 0 : immovablesChangePassNum[i] * 100 / immovablesChangeApplyNum[i];

+ 200 - 20
src/main/java/platform/modules/government/web/LandStatisticController.java

@@ -1,20 +1,33 @@
 package platform.modules.government.web;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.EasyExcelFactory;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.metadata.Sheet;
+import com.alibaba.excel.metadata.Table;
+import com.alibaba.excel.write.merge.LoopMergeStrategy;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.*;
 import platform.common.base.controller.BaseController;
-import platform.common.util.JxlsUtils;
+import platform.common.util.excel.DynamicOneSheetEasyExcel;
+import platform.common.util.excel.OneSheetEasyExcel;
+import platform.modules.government.dto.ApproveStatisticMonthly;
+import platform.modules.government.entity.Street;
 import platform.modules.government.service.LandStatisticsService;
 import platform.modules.government.service.StreetService;
 import platform.modules.sys.web.ResponseMessage;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.OutputStream;
+import java.net.URLEncoder;
 import java.text.ParseException;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 
 /**
@@ -149,7 +162,7 @@ public class LandStatisticController extends BaseController {
 
     /**
      * @Author: huZhiHao
-     * @Description: 获取月度审核统计表
+     * @Description: 获取板块统计表
      * @Date: 2020/1/13
      * @Params:
      * @Return:
@@ -185,20 +198,187 @@ public class LandStatisticController extends BaseController {
         return ResponseMessage.success("获取数据成功", o);
     }
 
-    @GetMapping("/export")
-    @ResponseBody
-    public void export() throws Exception {
-        // 模板路径和输出流
-        String templatePath = "E:/test.xls";
-        OutputStream os = new FileOutputStream("E:/template.xls");
-        // 定义一个Map,往里面放入要在模板中显示数据
-        Map<String, Object> model = new HashMap<String, Object>();
-        model.put("id", "001");
-        model.put("name", "张三");
-        model.put("age", 18);
-        //调用之前写的工具类,传入模板路径,输出流,和装有数据Map
-        JxlsUtils.exportExcel(templatePath, os, model);
-        os.close();
-        System.out.println("完成");
+    /*
+     * 导出月度审核统计
+     * */
+    @GetMapping("/approve/statistic/monthly/export")
+    public ResponseMessage approveStatisticMonthlyExport(
+            HttpServletResponse response,
+            @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
+            @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
+            @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime) throws Exception {
+        // 文件输出位置
+        /*String outPath = "C:\\Users\\oukele\\Desktop\\test.xlsx";
+        try {
+            // 所有行的集合
+            List<List<Object>> list = new ArrayList<List<Object>>();
+
+            for (int i = 1; i <= 10; i++) {
+                // 第 n 行的数据
+                List<Object> row = new ArrayList<Object>();
+                row.add("第" + i + "单元格");
+                row.add("第" + i + "单元格");
+                list.add(row);
+            }
+
+            ExcelWriter excelWriter = EasyExcelFactory.getWriter(new FileOutputStream(outPath));
+            // 表单
+            Sheet sheet = new Sheet(1,0);
+            sheet.setSheetName("第一个Sheet");
+            // 创建一个表格
+            Table table = new Table(1);
+            // 动态添加 表头 headList --> 所有表头行集合
+            List<List<String>> headList = new ArrayList<List<String>>();
+            // 第 n 行 的表头
+            List<String> headTitle0 = new ArrayList<String>();
+            List<String> headTitle1 = new ArrayList<String>();
+            List<String> headTitle2 = new ArrayList<String>();
+            headTitle0.add("最顶部-1");
+            headTitle0.add("标题1");
+            headTitle1.add("最顶部-1");
+            headTitle1.add("标题2");
+            headTitle2.add("最顶部-1");
+            headTitle2.add("标题3");
+
+            headList.add(headTitle0);
+            headList.add(headTitle1);
+            headList.add(headTitle2);
+            table.setHead(headList);
+
+            excelWriter.write1(list,sheet,table);
+            // 记得 释放资源
+            excelWriter.finish();
+            System.out.println("ok");
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }*/
+
+        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
+        String fileName = URLEncoder.encode("全区统计-月度审核统计表", "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+
+        List<Map> list = (List<Map>) landStatisticsService.getMonthlyApproveStatistic(streetId, startTime, endTime);
+        List<ApproveStatisticMonthly> data = new ArrayList<>();
+        for (Map map : list) {
+            ApproveStatisticMonthly approveStatisticMonthly = new ApproveStatisticMonthly();
+
+            approveStatisticMonthly.setRowName(map.get("rowName") + "");
+            approveStatisticMonthly.setRentApplyNum(map.get("rentApplyNum") + "");
+            approveStatisticMonthly.setRentPassNum(map.get("rentPassNum") + "");
+            approveStatisticMonthly.setRentPassRate(map.get("rentPassRate") + "%");
+            approveStatisticMonthly.setUseChangeApplyNum(map.get("useChangeApplyNum") + "");
+            approveStatisticMonthly.setUseChangePassNum(map.get("useChangePassNum") + "");
+            approveStatisticMonthly.setUseChangePassRate(map.get("useChangePassRate") + "%");
+            approveStatisticMonthly.setImmovablesChangeApplyNum(map.get("immovablesChangeApplyNum") + "");
+            approveStatisticMonthly.setImmovablesChangePassNum(map.get("immovablesChangePassNum") + "");
+            approveStatisticMonthly.setImmovablesChangePassRate(map.get("immovablesChangePassRate") + "%");
+            approveStatisticMonthly.setEquityStructureChangeApplyNum(map.get("equityStructureChangeApplyNum") + "");
+            approveStatisticMonthly.setEquityStructureChangePassNum(map.get("equityStructureChangePassNum") + "");
+            approveStatisticMonthly.setEquityStructureChangePassRate(map.get("equityStructureChangePassRate") + "");
+            approveStatisticMonthly.setTotalApplyNum(map.get("totalApplyNum") + "");
+            approveStatisticMonthly.setTotalPassNum(map.get("totalPassNum") + "");
+            approveStatisticMonthly.setTotalPassRate(map.get("totalPassRate") + "%");
+
+            data.add(approveStatisticMonthly);
+        }
+        EasyExcel.write(response.getOutputStream(), ApproveStatisticMonthly.class).sheet("sheet1").doWrite(data);
+        return ResponseMessage.success("获取数据成功");
+    }
+
+    /*
+     * 导出月度审核统计
+     * */
+    @GetMapping("/approve/statistic/plate/export")
+    public ResponseMessage approveStatisticMonthlyExport(
+            HttpServletResponse response,
+            @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
+            @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime) throws Exception {
+
+        Map o = (Map) landStatisticsService.getPlateStatistic(startTime, endTime);
+
+        List<Street> headers = (List<Street>) o.get("head");
+        List<Map> datas = (List<Map>) o.get("data");
+
+        //填充数据实体
+        List<List<String>> data = new ArrayList<>();
+
+        for (Map map : datas) {
+            String name = (String) map.get("name");
+            int[] num = (int[]) map.get("num");
+
+            List<String> dataList = new ArrayList<>();
+            dataList.add(name);
+            for (int i : num) {
+                dataList.add(i + "");
+            }
+            data.add(dataList);
+
+            List<Map> ResultList = (List<Map>) map.get("type");
+            for (Map map1 : ResultList) {
+                String name1 = (String) map1.get("name");
+                List<String> dataList1 = new ArrayList<>();
+                dataList1.add(name1);
+                if (Objects.equals("存量工业用地项目公司股权(结构)变更登记", name1)) {
+                    String[] num1 = (String[]) map1.get("streetNum");
+                    for (String i : num1) {
+                        dataList1.add(i);
+                    }
+                    data.add(dataList1);
+                } else {
+                    int[] num1 = (int[]) map1.get("streetNum");
+                    for (int i : num1) {
+                        dataList1.add(i + "");
+                    }
+                    data.add(dataList1);
+                }
+            }
+            List<String> empty = new ArrayList<>();
+            empty.add("");
+            data.add(empty);
+        }
+
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        // 这里URLEncoder.encode可以防止中文乱码
+        String fileName = URLEncoder.encode("板块统计表", "UTF-8");
+
+        OneSheetEasyExcel excel = new DynamicOneSheetEasyExcel();
+
+        // 设置excel文件名称
+        excel.setName(fileName);
+        // 设置sheet名称,只导出一个sheet,所以只设置一次
+        excel.setSheetName("sheet1");
+        // 按顺序设置列头
+//        excel.setHeader("姓名")
+//                .setHeader("年龄")
+//                .setHeader("性别");
+        for (Street street : headers) {
+            excel.setHeader(street.getName());
+        }
+
+        // 设置返回文件名称
+        response.setHeader("Content-disposition", "attachment;filename=" + excel.getName());
+
+        // 准备数据 , 下面这部分代码可以直接由service里完成
+//        List<List<String>> data = new ArrayList<>();
+
+//        List<Person> list = new ArrayList<>();
+//        list.add(new Person("陈1", 34, false));
+//        list.add(new Person("王2", 33, true));
+//        list.add(new Person("三3", 7, true));
+//        list.forEach(person -> {
+//            data.add(
+//                    Arrays.asList(
+//                            person.getName(),
+//                            person.getAge().toString(),
+//                            person.getSex().toString()
+//                    ));
+//        });
+        // 将准备好的data 塞入excel对象里,实现导出
+        excel.exportData(data, response);
+        return ResponseMessage.success("获取数据成功");
     }
-}
+}

+ 13 - 0
src/main/java/platform/modules/request/LandStatisticRequest.java

@@ -0,0 +1,13 @@
+package platform.modules.request;
+
+import lombok.Data;
+
+@Data
+public class LandStatisticRequest {
+
+    private String street_id;
+
+    private String start_time;
+
+    private String end_time;
+}

+ 17 - 6
src/main/resources/templates/admin/government/land_statistic/plate.html

@@ -164,12 +164,14 @@
 </div>
 <div class="chartContent">
     <div class="title">月度审核统计表</div>
-    <input class="Wdate input-text" type="text" th:id="apply_startdateIE" th:name="apply_startdate"
+    <input class="Wdate input-text" type="text" th:id="monthly_start_time" th:name="monthly_start_time"
            style="float:left; width: 150px;"
-           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'apply_enddateIE\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
-    <input class="Wdate input-text" type="text" th:id="apply_enddateIE" th:name="apply_enddate"
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'monthly_end_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+    <input class="Wdate input-text" type="text" th:id="monthly_end_time" th:name="monthly_end_time"
            style="float:left; width: 150px;"
-           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'apply_startdateIE\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'monthly_start_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+    <a th:onclick="'javascript:exportMonthlyStatistic();'"
+       class="btn btn-secondary radius" type="button">导出</a>
     <div class="table001" style="width: 96%; margin-left: 2%;">
         <table id="monthly_approve_statistic" th:fragment="approve_statistic_monthly">
             <thead>
@@ -624,14 +626,23 @@
         streetId = 28
         var url = pagePath + "/land_statistic/approve/statistic/monthly"
 
-        var start_time = $('#apply_startdateIE').val();
-        var end_time = $('#apply_enddateIE').val();
+        var start_time = $('#monthly_start_time').val();
+        var end_time = $('#monthly_end_time').val();
 
         url += "?street_id=" + streetId + "&start_time=" + start_time + "&end_time=" + end_time;
 
         // 装载局部刷新返回的页面
         $('#monthly_approve_statistic').load(url);
     }
+
+    //导出月度统计
+    function exportMonthlyStatistic() {
+        streetId = 28;
+        var start_time = $('#monthly_start_time').val();
+        var end_time = $('#monthly_end_time').val();
+        window.open(pagePath + "/land_statistic/approve/statistic/monthly/export?start_time="
+            + start_time + "&end_time=" + end_time + "&street_id=" + streetId);
+    }
 </script>
 </body>
 </html>

+ 37 - 10
src/main/resources/templates/admin/government/land_statistic/region.html

@@ -106,7 +106,7 @@
             overflow-x: hidden;
         }
 
-        .chartContent .date_line .month_box{
+        .chartContent .date_line .month_box {
             display: inline-block;
             margin-left: 15px;
             margin-right: 15px;
@@ -117,6 +117,7 @@
             cursor: pointer;
             margin-bottom: -1px;
         }
+
         .chartContent .date_line .active_month {
             background-color: #ffffff;
             color: #00a0e9;
@@ -216,12 +217,14 @@
 </div>
 <div class="chartContent">
     <div class="title">月度审核统计表</div>
-    <input class="Wdate input-text" type="text" th:id="apply_startdateIE" th:name="apply_startdate"
+    <input class="Wdate input-text" type="text" th:id="monthly_start_time" th:name="monthly_start_time"
            style="float:left; width: 150px;"
-           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'apply_enddateIE\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
-    <input class="Wdate input-text" type="text" th:id="apply_enddateIE" th:name="apply_enddate"
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'monthly_end_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+    <input class="Wdate input-text" type="text" th:id="monthly_end_time" th:name="monthly_end_time"
            style="float:left; width: 150px;"
-           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'apply_startdateIE\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'monthly_start_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getMontylyApproveStatistic()} })"/>
+    <a th:onclick="'javascript:exportMonthlyStatistic();'"
+       class="btn btn-secondary radius" type="button">导出</a>
     <div class="table001" style="width: 96%; margin-left: 2%;">
         <table id="monthly_approve_statistic" th:fragment="approve_statistic_monthly">
             <thead>
@@ -276,9 +279,17 @@
     </div>
 </div>
 <div class="chartContent">
-    <div id="plate_approve_statistic" th:fragment="approve_statistic_plate">
+    <div class="title">板块统计表</div>
+    <input class="Wdate input-text" type="text" th:id="plate_start_time" th:name="plate_start_time"
+           style="float:left; width: 150px;"
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'plate_end_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getPlateStatistic()} })"/>
+    <input class="Wdate input-text" type="text" th:id="plate_end_time" th:name="plate_end_time"
+           style="float:left; width: 150px;"
+           onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'plate_start_time\')}',isShowClear:true,readOnly:true,onpicked: function(){getPlateStatistic()} })"/>
+    <a th:onclick="'javascript:exportPlateStatistic();'"
+       class="btn btn-secondary radius" type="button">导出</a>
 
-        <div class="title">板块统计表</div>
+    <div id="plate_approve_statistic" th:fragment="approve_statistic_plate">
         <div class="tableHead" style="width: 96%; margin-left: 2%;">
             <div class="tableHeadLi" style="width:9%;" th:each="model,iterStat:${head}" th:object="${model}"
                  th:if="${iterStat.index==0}">&nbsp;
@@ -750,8 +761,8 @@
 
         var url = pagePath + "/land_statistic/approve/statistic/monthly"
 
-        var start_time = $('#apply_startdateIE').val();
-        var end_time = $('#apply_enddateIE').val();
+        var start_time = $('#monthly_start_time').val();
+        var end_time = $('#monthly_end_time').val();
 
         url += "?start_time=" + start_time + "&end_time=" + end_time;
 
@@ -759,10 +770,26 @@
         $('#monthly_approve_statistic').load(url);
     }
 
+    //导出月度统计
+    function exportMonthlyStatistic() {
+        var start_time = $('#monthly_start_time').val();
+        var end_time = $('#monthly_end_time').val();
+        window.open(pagePath + "/land_statistic/approve/statistic/monthly/export?start_time=" + start_time + "&end_time=" + end_time);
+    }
+
+    //导出板块统计
+    function exportPlateStatistic() {
+        var start_time = $('#plate_start_time').val();
+        var end_time = $('#plate_end_time').val();
+        window.open(pagePath + "/land_statistic/approve/statistic/plate/export?start_time=" + start_time + "&end_time=" + end_time);
+    }
+
     //板块统计表
     function getPlateStatistic() {
+        var start_time = $('#plate_start_time').val();
+        var end_time = $('#plate_end_time').val();
         // 装载局部刷新返回的页面
-        $('#plate_approve_statistic').load(pagePath + "/land_statistic/approve/statistic/plate");
+        $('#plate_approve_statistic').load(pagePath + "/land_statistic/approve/statistic/plate?start_time=" + start_time + "&end_time=" + end_time);
     }
 
     $(document).on("click", ".liHead", function () {

BIN
src/main/resources/xls/test.xls