蔡德晨 5 lat temu
rodzic
commit
9910cdde78

+ 255 - 15
src/main/java/com/jeeplus/modules/sg/financial/settlement/service/DataMaintenanceService.java

@@ -3,23 +3,25 @@
  */
 package com.jeeplus.modules.sg.financial.settlement.service;
 
+import com.jeeplus.common.utils.DateUtils;
 import com.jeeplus.common.utils.StringUtils;
+import com.jeeplus.common.utils.time.DateUtil;
 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.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 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.io.*;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 
 @Service
@@ -29,6 +31,8 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
 	@Autowired
 	private DataMaintenanceMapper dataMaintenanceMapper;
 
+	public static Map<String, CellStyle> styles;
+
 	public MaintainData get(String id) {
 		return super.get(id);
 	}
@@ -87,16 +91,32 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
 	}
 
 	public void export(MaintainData maintainData , HttpServletResponse response){
-		Workbook workbook = null;
+		InputStream inputStream = null;
+		XSSFWorkbook workbook = null;
 		try {
-			List<MaintainData> list = dataMaintenanceMapper.findList(maintainData);
-			workbook = ExcelWriter.exportData(list);
-			long time = System.currentTimeMillis();
-			String outFile = time + ".xlsx";
-
+			String path = (getSispPath() + "excelmodel/maintainDataExport.xlsx");
+			List<MaintainData> dataList = dataMaintenanceMapper.findList(maintainData);
+//			String path = "D:/IDEA workspace/sg_audit/target/classes/freemarker/excelmodel/maintainDataExport.xlsx";
+			File file = new File(path);
+			inputStream = new FileInputStream(file);// 将excel文件转为输入流
+			workbook = new XSSFWorkbook(inputStream);// 创建个workbook
+			styles = createStyles(workbook);  //创建样式
+			int rowNum = 3;
+			Sheet sheet = workbook.getSheetAt(0);
+			for (Iterator<MaintainData> it = dataList.iterator(); it.hasNext(); ) {
+				MaintainData data = it.next();
+				if (data == null) {
+					continue;
+				}
+				//输出行数据
+				Row row = sheet.createRow(rowNum++);
+				convertDataToRow(data, row);
+			}
+			String st = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
+			String str = URLEncoder.encode("概预算基本信息"+st+".xlsx", "UTF8");
 			OutputStream outputStream = response.getOutputStream();
 			response.reset();
-			response.setHeader("Content-Disposition", "attachment;filename="+outFile);
+			response.setHeader("Content-Disposition", "attachment;filename="+str);
 			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
 			workbook.write(outputStream);
 			outputStream.flush();
@@ -105,14 +125,21 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
 			e.printStackTrace();
 		} finally {
 		}
+
+
         	}
 
 
 	public void exportHeard( HttpServletResponse response){
-		Workbook workbook = null;
+		InputStream inputStream = null;
+		XSSFWorkbook workbook = null;
 		try {
-			workbook = ExcelWriter.exportHeard();
-			String str = URLEncoder.encode("数据维护导入模板.xlsx", "UTF8");
+			String path = (getSispPath() + "excelmodel/maintainDataImport.xlsx");
+//			String path = "D:/IDEA workspace/sg_audit/target/classes/freemarker/excelmodel/maintainDataImport.xlsx";
+			File file = new File(path);
+			inputStream = new FileInputStream(file);// 将excel文件转为输入流
+			workbook = new XSSFWorkbook(inputStream);// 创建个workbook,
+			String str = URLEncoder.encode("概预算基本信息导入模板.xlsx", "UTF8");
 			OutputStream outputStream = response.getOutputStream();
 			response.reset();
 			response.setHeader("Content-Disposition", "attachment;filename="+str);
@@ -125,5 +152,218 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
 		} finally {
 		}
 	}
+
+
+	public  String getSispPath() {
+		String sispPath = this.getClass().getResource("/").getPath()+ "freemarker/";
+		return sispPath;
+	}
+
+
+	private  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.getDesignUnits()) {
+			cell.setCellValue(maintainData.getDesignUnits());
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getConstructionUnits()) {
+			cell.setCellValue(maintainData.getConstructionUnits());
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getAddress()) {
+			cell.setCellValue(maintainData.getAddress());
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getProperty()) {
+			cell.setCellValue(maintainData.getProperty());
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getInvestment()) {
+			cell.setCellValue(maintainData.getInvestment());
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getStartDate()) {
+			cell.setCellValue(DateUtils.formatDate(maintainData.getStartDate()));
+
+		} else {
+			cell.setCellValue("");
+		}
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		if (null != maintainData.getEndDate()) {
+			cell.setCellValue(DateUtils.formatDate(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"));
+		cell.setCellValue(maintainData.getDesignFee()+maintainData.getSupervisionFee()+maintainData.getPreliminaryWorkFee()
+				+maintainData.getDamages()+maintainData.getManagementFee());
+
+		cell = row.createCell(cellNum++);
+		cell.setCellStyle(styles.get("data"));
+		cell.setCellValue(maintainData.getDesignFee()+maintainData.getSupervisionFee()+maintainData.getPreliminaryWorkFee()
+				+maintainData.getDamages()+maintainData.getManagementFee()+maintainData.getBuildingFee()+maintainData.getInstallFee()
+				+maintainData.getEquipmentFee()+maintainData.getMaterialFee());
+
+	}
+
+	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.BLACK.getIndex());
+		style.setFont(headerFont);
+		style.setFillForegroundColor(HSSFColor.WHITE.index);
+		styles.put("header", style);
+
+		return styles;
+	}
 	
 }

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

@@ -8,6 +8,7 @@ import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 
+import java.io.File;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -692,5 +693,30 @@ public class ExcelWriter {
         return sheet;
     }
 
+
+    public static Workbook export(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;
+    }
+
+    public  String getSispPath() {
+        String sispPath = this.getClass().getResource("/").getPath()+ "freemarker/";
+        return sispPath;
+    }
+
 }
 

BIN
src/main/resources/freemarker/excelmodel/maintainDataExport.xlsx


BIN
src/main/resources/freemarker/excelmodel/maintainDataImport.xlsx


+ 61 - 0
src/main/webapp/static/plugin/bootstrapTable/bootstrap-table-resizable.js

@@ -0,0 +1,61 @@
+
+const isInit = that => that.$el.data('resizableColumns') !== undefined
+
+const initResizable = that => {
+  if (that.options.resizable && !that.options.cardView && !isInit(that)) {
+    that.$el.resizableColumns()
+  }
+}
+
+const destroy = that => {
+  if (isInit(that)) {
+    that.$el.data('resizableColumns').destroy()
+  }
+}
+
+const reInitResizable = that => {
+  destroy(that)
+  initResizable(that)
+}
+
+$.extend($.fn.bootstrapTable.defaults, {
+  resizable: false
+})
+
+const BootstrapTable = $.fn.bootstrapTable.Constructor
+const _initBody = BootstrapTable.prototype.initBody
+const _toggleView = BootstrapTable.prototype.toggleView
+const _resetView = BootstrapTable.prototype.resetView
+
+BootstrapTable.prototype.initBody = function (...args) {
+  const that = this
+  _initBody.apply(this, Array.prototype.slice.apply(args))
+
+  that.$el
+    .off('column-switch.bs.table, page-change.bs.table')
+    .on('column-switch.bs.table, page-change.bs.table', () => {
+      reInitResizable(that)
+    })
+}
+
+BootstrapTable.prototype.toggleView = function (...args) {
+  _toggleView.apply(this, Array.prototype.slice.apply(args))
+
+  if (this.options.resizable && this.options.cardView) {
+    // Destroy the plugin
+    destroy(this)
+  }
+}
+
+BootstrapTable.prototype.resetView = function (...args) {
+  const that = this
+
+  _resetView.apply(this, Array.prototype.slice.apply(args))
+
+  if (this.options.resizable) {
+    // because in fitHeader function, we use setTimeout(func, 100);
+    setTimeout(() => {
+      initResizable(that)
+    }, 100)
+  }
+}

Plik diff jest za duży
+ 415 - 0
src/main/webapp/static/plugin/bootstrapTable/colResizable-1.6.js


+ 8 - 1
src/main/webapp/webpage/modules/sg/financial/settlement/dataMaintenanceList.js

@@ -271,7 +271,14 @@ $(document).ready(function() {
 		  $("#searchForm  .select-item").html("");
 		  $('#dataTable').bootstrapTable('refresh');
 		});
-		
+
+
+	// $("#dataTable").colResizable({
+	// 	liveDrag:true,
+	// 	gripInnerHtml:"<div class='grip'></div>",
+	// 	draggingClass:"dragging",
+	// 	resizeMode:'fit'
+	// });
 		
 	});
 		

+ 3 - 1
src/main/webapp/webpage/modules/sg/financial/settlement/dataMaintenanceList.jsp

@@ -8,12 +8,14 @@
 	<%@ include file="/webpage/include/bootstraptable.jsp"%>
 	<%@include file="/webpage/include/treeview.jsp" %>
 	<%@include file="dataMaintenanceList.js" %>
+	<script src="${ctxStatic}/plugin/bootstrapTable/bootstrap-table-resizable.js"></script>
+	<script src="${ctxStatic}/plugin/bootstrapTable/colResizable-1.6.js"></script>
 </head>
 <body>
 	<div class="wrapper wrapper-content">
 	<div class="panel panel-primary">
 	<div class="panel-heading">
-		<h3 class="panel-title">数据维护</h3>
+		<h3 class="panel-title">概预算基本信息</h3>
 	</div>
 	<div class="panel-body">