|
@@ -3,23 +3,25 @@
|
|
*/
|
|
*/
|
|
package com.jeeplus.modules.sg.financial.settlement.service;
|
|
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.StringUtils;
|
|
|
|
+import com.jeeplus.common.utils.time.DateUtil;
|
|
import com.jeeplus.core.persistence.Page;
|
|
import com.jeeplus.core.persistence.Page;
|
|
import com.jeeplus.core.service.CrudService;
|
|
import com.jeeplus.core.service.CrudService;
|
|
import com.jeeplus.modules.sg.financial.settlement.entity.MaintainData;
|
|
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.mapper.DataMaintenanceMapper;
|
|
import com.jeeplus.modules.sg.financial.settlement.util.ExcelWriter;
|
|
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.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -29,6 +31,8 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
|
|
@Autowired
|
|
@Autowired
|
|
private DataMaintenanceMapper dataMaintenanceMapper;
|
|
private DataMaintenanceMapper dataMaintenanceMapper;
|
|
|
|
|
|
|
|
+ public static Map<String, CellStyle> styles;
|
|
|
|
+
|
|
public MaintainData get(String id) {
|
|
public MaintainData get(String id) {
|
|
return super.get(id);
|
|
return super.get(id);
|
|
}
|
|
}
|
|
@@ -87,16 +91,32 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
|
|
}
|
|
}
|
|
|
|
|
|
public void export(MaintainData maintainData , HttpServletResponse response){
|
|
public void export(MaintainData maintainData , HttpServletResponse response){
|
|
- Workbook workbook = null;
|
|
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ XSSFWorkbook workbook = null;
|
|
try {
|
|
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();
|
|
OutputStream outputStream = response.getOutputStream();
|
|
response.reset();
|
|
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");
|
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
workbook.write(outputStream);
|
|
workbook.write(outputStream);
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
@@ -105,14 +125,21 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void exportHeard( HttpServletResponse response){
|
|
public void exportHeard( HttpServletResponse response){
|
|
- Workbook workbook = null;
|
|
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ XSSFWorkbook workbook = null;
|
|
try {
|
|
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();
|
|
OutputStream outputStream = response.getOutputStream();
|
|
response.reset();
|
|
response.reset();
|
|
response.setHeader("Content-Disposition", "attachment;filename="+str);
|
|
response.setHeader("Content-Disposition", "attachment;filename="+str);
|
|
@@ -125,5 +152,218 @@ public class DataMaintenanceService extends CrudService<DataMaintenanceMapper, M
|
|
} finally {
|
|
} 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;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|