蔡德晨 преди 5 години
родител
ревизия
bee5c8a5c2

+ 9 - 0
src/main/java/com/jeeplus/modules/sg/financial/settlement/entity/MaintainData.java

@@ -21,8 +21,17 @@ public class MaintainData extends DataEntity<MaintainData> {
     private Double damages;      //线路施工赔偿费
     private Double managementFee;   //法人管理费
     private Double totalFee;      //合计
+    private String state;
 
 
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
     private String[] projectIds;  //项目定义号数组
 
     public String[] getProjectIds() {

+ 1 - 0
src/main/java/com/jeeplus/modules/sg/financial/settlement/mapper/xml/DataMaintenanceMapper.xml

@@ -181,6 +181,7 @@
 			update_date = #{updateDate},
 			remarks = #{remarks},
 			start_date = #{startDate},
+			project_id = #{projectId},
 			end_date = #{endDate},
 			approval_number = #{approvalNumber},
 			building_fee = #{buildingFee},

+ 27 - 0
src/main/java/com/jeeplus/modules/sg/financial/settlement/service/DataMaintenanceService.java

@@ -7,12 +7,15 @@ import com.jeeplus.core.persistence.Page;
 import com.jeeplus.core.service.CrudService;
 import com.jeeplus.modules.sg.financial.settlement.entity.MaintainData;
 import com.jeeplus.modules.sg.financial.settlement.mapper.DataMaintenanceMapper;
+import com.jeeplus.modules.sg.financial.settlement.util.ExcelWriter;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.List;
 
 
@@ -56,6 +59,30 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
 
 	public void export(MaintainData maintainData , HttpServletResponse response){
 		Workbook workbook = null;
+		try {
+			List<MaintainData> list = dataMaintenanceMapper.findList(maintainData);
+			workbook = ExcelWriter.exportData(list);
+			long time = System.currentTimeMillis();
+			String outFile = time + ".xlsx";
+
+			OutputStream outputStream = response.getOutputStream();
+			response.reset();
+			response.setHeader("Content-Disposition", "attachment;filename="+outFile);
+			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+			workbook.write(outputStream);
+			outputStream.flush();
+			outputStream.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+		}
+
+
+
+
+
+
+
         	}
 	
 }

+ 380 - 0
src/main/java/com/jeeplus/modules/sg/financial/settlement/util/ExcelWriter.java

@@ -0,0 +1,380 @@
+package com.jeeplus.modules.sg.financial.settlement.util;
+
+
+import com.jeeplus.modules.sg.financial.settlement.entity.MaintainData;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+
+import java.util.*;
+
+/**
+ *
+ * Description: 生成Excel并写入数据
+ */
+public class ExcelWriter {
+
+    public static Map<String, CellStyle> styles;
+
+    /**
+     * 生成Excel并写入数据信息
+     * @param dataList 数据列表
+     * @return 写入数据后的工作簿对象
+     */
+    public static Workbook exportData(List<MaintainData> dataList){
+        // 生成xlsx的Excel
+        Workbook workbook = new SXSSFWorkbook();
+
+
+        // 生成Sheet表,写入第一行的列头
+        Sheet sheet = buildDataSheet(workbook);
+        //构建每行的数据内容
+        int rowNum = 3;
+        for (Iterator<MaintainData> it = dataList.iterator(); it.hasNext(); ) {
+            MaintainData data = it.next();
+            if (data == null) {
+                continue;
+            }
+            //输出行数据
+            Row row = sheet.createRow(rowNum++);
+            convertDataToRow(data, row);
+        }
+        return workbook;
+    }
+
+    /**
+     * 生成sheet表,并写入第一行数据(列头)
+     * @param workbook 工作簿对象
+     * @return 已经写入列头的Sheet
+     */
+    private static Sheet buildDataSheet(Workbook workbook) {
+        Sheet sheet = workbook.createSheet();
+        // 设置列头宽度
+//        for (int i=0; i<CELL_HEADS.size(); i++) {
+//            sheet.setColumnWidth(i, 4000);
+//        }
+        // 设置默认行高
+        sheet.setDefaultRowHeight((short) 400);
+        sheet.addMergedRegion(new CellRangeAddress(2, 0, 0, 0));
+        sheet.addMergedRegion(new CellRangeAddress(2, 0, 1, 1));
+        sheet.addMergedRegion(new CellRangeAddress(2, 0, 2, 2));
+        sheet.addMergedRegion(new CellRangeAddress(2, 0, 3, 3));
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 4, 13));
+        sheet.addMergedRegion(new CellRangeAddress(2, 1, 4, 4));
+        sheet.addMergedRegion(new CellRangeAddress(2, 1, 5, 5));
+        sheet.addMergedRegion(new CellRangeAddress(2, 1, 6, 6));
+        sheet.addMergedRegion(new CellRangeAddress(2, 1, 7, 7));
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 8, 13));
+        // 构建头单元格样式
+        styles = createStyles(sheet.getWorkbook());
+        CellStyle cellStyle = buildHeadCellStyle(sheet.getWorkbook());
+
+
+
+        // 写入第一行各列的数据
+        Row row1 = sheet.createRow(0);
+        Row row2 = sheet.createRow(1);
+        Row row3 = sheet.createRow(2);
+        Cell cell1 = row1.createCell(0);
+        cell1.setCellValue("项目定义编码");
+        cell1.setCellStyle(styles.get("header"));
+        Cell cell2 = row1.createCell(1);
+        cell2.setCellValue("开工时间");
+        cell2.setCellStyle(styles.get("header"));
+        Cell cell3 = row1.createCell(2);
+        cell3.setCellValue("竣工时间");
+        cell3.setCellStyle(styles.get("header"));
+        Cell cell4 = row1.createCell(3);
+        cell4.setCellValue("批准文号");
+        cell4.setCellStyle(styles.get("header"));
+
+
+        Cell cella = row2.createCell(0);
+        cella.setCellValue("");
+        cella.setCellStyle(styles.get("header"));
+        Cell cellb = row2.createCell(1);
+        cellb.setCellValue("");
+        cellb.setCellStyle(styles.get("header"));
+        Cell cellc = row2.createCell(2);
+        cellc.setCellValue("");
+        cellc.setCellStyle(styles.get("header"));
+        Cell celld = row2.createCell(3);
+        celld.setCellValue("");
+        celld.setCellStyle(styles.get("header"));
+
+        Cell cellm = row2.createCell(9);
+        cellm.setCellValue("");
+        cellm.setCellStyle(styles.get("header"));
+        Cell celln = row2.createCell(10);
+        celln.setCellValue("");
+        celln.setCellStyle(styles.get("header"));
+        Cell cello = row2.createCell(11);
+        cello.setCellValue("");
+        cello.setCellStyle(styles.get("header"));
+        Cell cellp = row2.createCell(12);
+        cellp.setCellValue("");
+        cellp.setCellStyle(styles.get("header"));
+        Cell cellq = row2.createCell(13);
+        cellq.setCellValue("");
+        cellq.setCellStyle(styles.get("header"));
+
+        Cell celle = row3.createCell(0);
+        celle.setCellValue("");
+        celle.setCellStyle(styles.get("header"));
+        Cell cellf = row3.createCell(1);
+        cellf.setCellValue("");
+        cellf.setCellStyle(styles.get("header"));
+        Cell cellg = row3.createCell(2);
+        cellg.setCellValue("");
+        cellg.setCellStyle(styles.get("header"));
+        Cell cellh = row3.createCell(3);
+        cellh.setCellValue("");
+        cellh.setCellStyle(styles.get("header"));
+
+        Cell cell5 = row1.createCell(4);
+        cell5.setCellValue("概算数");
+        cell5.setCellStyle(styles.get("header"));
+        Cell cell6 = row2.createCell(4);
+        cell6.setCellValue("建筑费");
+        cell6.setCellStyle(styles.get("header"));
+        Cell cell7 = row2.createCell(5);
+        cell7.setCellValue("安装费");
+        cell7.setCellStyle(styles.get("header"));
+        Cell cell8 = row2.createCell(6);
+        cell8.setCellValue("设备购置费");
+        cell8.setCellStyle(styles.get("header"));
+
+        Cell cellj = row3.createCell(4);
+        cellj.setCellValue("");
+        cellj.setCellStyle(styles.get("header"));
+        Cell cellk = row3.createCell(5);
+        cellk.setCellValue("");
+        cellk.setCellStyle(styles.get("header"));
+        Cell celll = row3.createCell(6);
+        celll.setCellValue("");
+        celll.setCellStyle(styles.get("header"));
+
+        Cell cell9 = row2.createCell(7);
+        cell9.setCellValue("主材费");
+        cell9.setCellStyle(styles.get("header"));
+        Cell cell10 = row2.createCell(8);
+        cell10.setCellValue("其他费用");
+        cell10.setCellStyle(styles.get("header"));
+        Cell cell11 = row3.createCell(8);
+        cell11.setCellValue("设计费");
+        cell11.setCellStyle(styles.get("header"));
+        Cell cell12 = row3.createCell(9);
+        cell12.setCellValue("监理费");
+        cell12.setCellStyle(styles.get("header"));
+        Cell cell13 = row3.createCell(10);
+        cell13.setCellValue("项目前期工作费");
+        cell13.setCellStyle(styles.get("header"));
+        Cell cell14 = row3.createCell(11);
+        cell14.setCellValue("线路施工赔偿费");
+        cell14.setCellStyle(styles.get("header"));
+        Cell cell15 = row3.createCell(12);
+        cell15.setCellValue("法人管理费(余物清理费)");
+        cell15.setCellStyle(styles.get("header"));
+        Cell cell16 = row3.createCell(13);
+        cell16.setCellValue("合计");
+        cell16.setCellStyle(styles.get("header"));
+        return sheet;
+    }
+
+    /**
+     * 设置第一行列头的样式
+     * @param workbook 工作簿对象
+     * @return 单元格样式对象
+     */
+    private static CellStyle buildHeadCellStyle(Workbook workbook) {
+        CellStyle style = workbook.createCellStyle();
+        //对齐方式设置
+        style.setAlignment(CellStyle.ALIGN_CENTER);
+        //边框颜色和宽度设置
+//        style.setBorderBottom(CellStyle.THIN);
+        style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); // 下边框
+        style.setBorderLeft(CellStyle.BORDER_THIN);
+        style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); // 左边框
+        style.setBorderRight(CellStyle.BORDER_THIN);
+        style.setRightBorderColor(IndexedColors.BLACK.getIndex()); // 右边框
+        style.setBorderTop(CellStyle.BORDER_THIN);
+        style.setTopBorderColor(IndexedColors.BLACK.getIndex()); // 上边框
+        //设置背景颜色
+//        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+//        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        return style;
+    }
+
+    private static 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"));
+//		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.BLACK.getIndex());
+        style.setFont(headerFont);
+        style.setFillForegroundColor(HSSFColor.WHITE.index);
+        styles.put("header", style);
+
+        return styles;
+    }
+
+    /**
+     * 将数据转换成行
+     * @param row 行对象
+     * @return
+     */
+    private static void convertDataToRow(MaintainData maintainData, Row row){
+        int cellNum = 0;
+        Cell cell;
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getProjectId()) {
+            cell.setCellValue(maintainData.getProjectId());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getStartDate()) {
+            cell.setCellValue(maintainData.getStartDate());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getEndDate()) {
+            cell.setCellValue(maintainData.getEndDate());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getApprovalNumber()) {
+            cell.setCellValue(maintainData.getApprovalNumber());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getBuildingFee()) {
+            cell.setCellValue(maintainData.getBuildingFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getInstallFee()) {
+            cell.setCellValue(maintainData.getInstallFee());
+        } else {
+            cell.setCellValue("");
+        }
+
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getEquipmentFee()) {
+            cell.setCellValue(maintainData.getEquipmentFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getMaterialFee()) {
+            cell.setCellValue(maintainData.getMaterialFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getDesignFee()) {
+            cell.setCellValue(maintainData.getDesignFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getSupervisionFee()) {
+            cell.setCellValue(maintainData.getSupervisionFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getPreliminaryWorkFee()) {
+            cell.setCellValue(maintainData.getPreliminaryWorkFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getDamages()) {
+            cell.setCellValue(maintainData.getDamages());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getManagementFee()) {
+            cell.setCellValue(maintainData.getManagementFee());
+        } else {
+            cell.setCellValue("");
+        }
+        cell = row.createCell(cellNum++);
+        cell.setCellStyle(styles.get("data"));
+        if (null != maintainData.getTotalFee()) {
+            cell.setCellValue(maintainData.getTotalFee());
+        } else {
+            cell.setCellValue("");
+        }
+
+    }
+}

+ 0 - 458
src/main/java/com/jeeplus/modules/sg/financial/settlement/util/ExportUtil.java

@@ -1,458 +0,0 @@
-/**
- * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
- */
-package com.jeeplus.modules.sg.financial.settlement.util;
-
-import com.google.common.collect.Lists;
-import com.jeeplus.common.utils.Encodes;
-import com.jeeplus.common.utils.Reflections;
-import com.jeeplus.common.utils.excel.annotation.ExcelField;
-import com.jeeplus.modules.sys.utils.DictUtils;
-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.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.*;
-
-
-public class ExportUtil {
-
-	private static Logger log = LoggerFactory.getLogger(ExportUtil.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 ExportUtil(String title, Class<?> cls){
-		this(title, cls, 1);
-	}
-
-	/**
-	 * 构造函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param cls 实体对象,通过annotation.ExportField获取标题
-	 * @param type 导出类型(1:导出数据;2:导出模板)
-	 * @param groups 导入分组
-	 */
-	public ExportUtil(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 headers 表头数组
-	 */
-	public ExportUtil(String title, String[] headers) {
-		initialize(title, Lists.newArrayList(headers));
-	}
-
-	/**
-	 * 构造函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param headerList 表头列表
-	 */
-	public ExportUtil(String title, List<String> headerList) {
-		initialize(title, headerList);
-	}
-	
-	/**
-	 * 初始化函数
-	 * @param title 表格标题,传“空值”,表示无标题
-	 * @param headerList 表头列表
-	 */
-	private void initialize(String title, List<String> headerList) {
-		this.wb = new SXSSFWorkbook(500);
-		this.sheet = wb.createSheet("维护数据");
-		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"));
-//		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);
-		CellStyle style = styles.get("data"+(align>=1&&align<=3?align:""));
-		try {
-			if (val == null){
-				cell.setCellValue("");
-			} else if (val instanceof String) {
-				cell.setCellValue((String) val);
-			} else if (val instanceof Integer) {
-				cell.setCellValue((Integer) val);
-			} else if (val instanceof Long) {
-				cell.setCellValue((Long) val);
-			} else if (val instanceof Double) {
-				cell.setCellValue((Double) val);
-			} else if (val instanceof Float) {
-				cell.setCellValue((Float) val);
-			} else if (val instanceof Date) {
-				DataFormat format = wb.createDataFormat();
-	            style.setDataFormat(format.getFormat("yyyy-MM-dd"));
-				cell.setCellValue((Date) val);
-			} else {
-				if (fieldType != Class.class){
-					cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val));
-				}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));
-				}
-			}
-		} catch (Exception ex) {
-			log.info("Set cell value ["+row.getRowNum()+","+column+"] error: " + ex.toString());
-			cell.setCellValue(val.toString());
-		}
-		cell.setCellStyle(style);
-		return cell;
-	}
-
-	/**
-	 * 添加数据(通过annotation.ExportField添加数据)
-	 * @return list 数据列表
-	 */
-	public <E> ExportUtil 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[] {});
-						}
-					}
-					// If is dict, get dict label
-					if (StringUtils.isNotBlank(ef.dictType())){
-						val = DictUtils.getDictLabel(val==null?"":val.toString(), ef.dictType(), "");
-					}
-				}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 os 输出数据流
-	 */
-	public ExportUtil write(OutputStream os) throws IOException{
-		wb.write(os);
-		return this;
-	}
-	
-	/**
-	 * 输出到客户端
-	 * @param fileName 输出文件名
-	 */
-	public ExportUtil write(HttpServletResponse response, String fileName) throws IOException{
-		response.reset();
-        response.setContentType("application/octet-stream; charset=utf-8");
-        response.setHeader("Content-Disposition", "attachment; filename="+Encodes.urlEncode(fileName));
-		write(response.getOutputStream());
-		return this;
-	}
-	
-	/**
-	 * 输出到文件
-	 * @param name 输出文件名
-	 */
-	public ExportUtil writeFile(String name) throws FileNotFoundException, IOException{
-		FileOutputStream os = new FileOutputStream(name);
-		this.write(os);
-		return this;
-	}
-	
-	/**
-	 * 清理临时文件
-	 */
-	public ExportUtil 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.");
-//		
-//	}
-
-}

+ 63 - 12
src/main/java/com/jeeplus/modules/sg/financial/settlement/web/DataMaintenanceController.java

@@ -13,6 +13,7 @@ import com.jeeplus.core.persistence.Page;
 import com.jeeplus.core.web.BaseController;
 import com.jeeplus.modules.sg.financial.settlement.entity.MaintainData;
 import com.jeeplus.modules.sg.financial.settlement.service.DataMaintenanceService;
+import com.jeeplus.modules.sys.utils.UserUtils;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.shiro.authz.annotation.Logical;
@@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -71,16 +73,61 @@ public class DataMaintenanceController extends BaseController {
 	@ResponseBody
 	@RequiresPermissions("sg:settlement:list")
 	@RequestMapping(value = "data")
-	public Map<String, Object> data(MaintainData maintainData, HttpServletRequest request, HttpServletResponse response, Model model) {
+	public Map<String, Object> data(MaintainData maintainData, HttpServletRequest request, HttpServletResponse response, Model model,HttpSession session) {
+		String id = UserUtils.getUser().getId();
+		String state = maintainData.getState();
+		StringBuilder stringBuilder = new StringBuilder();
+		if(state.equals("0")) {
+			String st = (String) session.getAttribute(id);
+			if (StringUtils.isNotBlank(st)) {
+				stringBuilder.append(st);
+			}
+		}else {
+			session.removeAttribute(id);
+		}
 		String projectId = maintainData.getProjectId();
 		if(StringUtils.isNotBlank(projectId)){
-			String[] sts = projectId.split("\\s+");
+			stringBuilder.append(projectId);
+		}
+		String newstr = stringBuilder.toString();
+		if(StringUtils.isNotBlank(newstr)){
+			String[] sts = newstr.split("\\s+");
 			maintainData.setProjectIds(sts);
 		}
 		Page<MaintainData> page = dataMaintenanceService.findPage(new Page<MaintainData>(request, response), maintainData);
 		return getBootstrapData(page);
 	}
-
+	/**
+	 * 导入查询
+	 */
+	@ResponseBody
+	@RequiresPermissions("sg:settlement:import")
+	@RequestMapping(value = "importsel")
+	public Map<String, Object> importSelect(@RequestParam("file")MultipartFile file, MaintainData maintainData, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws IOException, InvalidFormatException {
+//		try {
+			ImportExcel importExcel = new ImportExcel(file, 1, 0);
+			int lastRow = importExcel.getLastDataRowNum();
+			StringBuilder stringBuilder = new StringBuilder();
+			for(int i=1;i<lastRow;i++){
+				Row row = importExcel.getRow(i);
+				String str = (String) importExcel.getCellValue(row, 0);
+				if(StringUtils.isNotBlank(str)) {
+					stringBuilder.append(str + " ");
+				}
+			}
+			String st = stringBuilder.toString();
+			String sts = st.substring(0,st.length()-1);
+			String id = UserUtils.getUser().getId();
+			session.setAttribute(id,st);
+			String[] strs = st.split(" ");
+			maintainData.setProjectIds(strs);
+			Page<MaintainData> page = dataMaintenanceService.findPage(new Page<MaintainData>(request, response), maintainData);
+			return getBootstrapData(page);
+//			return "redirect:/a/sg/settlement/data";
+//		}catch (Exception e){
+//			return  null;
+//		}
+	}
 	/**
 	 * 查看,增加,编辑表单页面
 	 */
@@ -153,9 +200,10 @@ public class DataMaintenanceController extends BaseController {
     public AjaxJson exportFile(MaintainData maintainData, HttpServletRequest request, HttpServletResponse response) {
 		AjaxJson j = new AjaxJson();
 		try {
-            String fileName = DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
-            Page<MaintainData> page = dataMaintenanceService.findPage(new Page<MaintainData>(request, response, -1), maintainData);
-    		new ExportExcel(null, MaintainData.class).setDataList(page.getList()).write(response, fileName).dispose();
+//            String fileName = DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
+//            Page<MaintainData> page = dataMaintenanceService.findPage(new Page<MaintainData>(request, response, -1), maintainData);
+//    		new ExportExcel(null, MaintainData.class).setDataList(page.getList()).write(response, fileName).dispose();
+			dataMaintenanceService.export(maintainData,response);
     		j.setSuccess(true);
     		j.setMsg("导出成功!");
     		return j;
@@ -173,17 +221,17 @@ public class DataMaintenanceController extends BaseController {
 	@ResponseBody
 	@RequiresPermissions("sg:settlement:import")
     @RequestMapping(value = "import")
-   	public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException, InvalidFormatException, IllegalAccessException, InstantiationException, ParseException {
+   	public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
 		AjaxJson j = new AjaxJson();
-//		try {
+		try {
 			ImportExcel ei = new ImportExcel(file, 2, 0);
 			List<MaintainData> list = getData(ei);
 			dataMaintenanceService.saveList(list);
 			j.setMsg("导入成功");
-//		} catch (Exception e) {
-//			j.setSuccess(false);
-//			j.setMsg("导入失败!失败信息:"+e.getMessage());
-//		}
+		} catch (Exception e) {
+			j.setSuccess(false);
+			j.setMsg("导入失败!失败信息:"+e.getMessage());
+		}
 		return j;
     }
 
@@ -248,6 +296,7 @@ public class DataMaintenanceController extends BaseController {
       return d;
 	}
 
+
 	private Date getDate(ImportExcel importExcel,Row row,int col) throws ParseException {
 		Date d = null;
 		Object o = importExcel.getCellValue(row,col);
@@ -260,4 +309,6 @@ public class DataMaintenanceController extends BaseController {
 
 
 
+
+
 }

+ 25 - 0
src/main/webapp/webpage/modules/sg/settlement/dataMaintenanceList.js

@@ -206,6 +206,31 @@ $(document).ready(function() {
 	    	       }
 			}); 
 		});
+
+         $("#btnSearch").click(function () {
+             $("#st").val("0");
+              jp.open({
+                     type: 2,
+                     area: [500, 200],
+                     auto: true,
+                     title:"导入数据",
+                     content: "${ctx}/tag/importExcel" ,
+                     btn: ['确定', '关闭'],
+                     btn1: function(index, layero){
+                     var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
+                     iframeWin.contentWindow.importExcel('${ctx}/sg/settlement/importsel', function (data) {
+                      top.layer.msg('成功', {icon:1})
+                       $('#dataTable').bootstrapTable('load',data);
+                     jp.close(index);
+                     getTdValue();
+                      });//调用保存事件
+                       return false;
+                    },
+                    btn2: function(index){
+                    jp.close(index);
+                    }
+              })
+       })
 		
 		
 	 $("#export").click(function(){//导出Excel文件

+ 5 - 0
src/main/webapp/webpage/modules/sg/settlement/dataMaintenanceList.jsp

@@ -24,6 +24,7 @@
 			 <div class="col-xs-12 col-sm-6 col-md-4">
 				<label class="label-item single-overflow pull-left" title="项目定义号:">项目定义号:</label>
 				<form:input path="projectId" htmlEscape="false" maxlength="64"  class=" form-control"/>
+				 <form:input path="state" id="st" htmlEscape="false" style="display:none" value="1"  class=" form-control" />
 			</div>
 		 <div class="col-xs-12 col-sm-6 col-md-4">
 			<div style="margin-top:26px">
@@ -65,6 +66,10 @@
 					<i class="fa fa-search-plus"></i> 查看
 				</button>
 			</shiro:hasPermission>
+		    <shiro:hasPermission name="sg:settlement:import">
+					<button id="btnSearch" class="btn btn-info"><i class="fa fa-folder-open-o"></i> 导入查询
+			    </button>
+		    </shiro:hasPermission>
 		    </div>
 		
 	<!-- 表格 -->