Commit 6dce2d83 authored by suichenguang's avatar suichenguang

Merge remote-tracking branch 'origin/dev' into dev

parents df1b4385 e021f88c
......@@ -3,10 +3,18 @@ package com.yxproject.start.api;
import com.yxproject.start.service.DetailReceiptListService;
import com.yxproject.start.service.ReceiptService;
import com.yxproject.start.utils.ExportExcel;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -19,10 +27,27 @@ public class ExportExcelApi {
* 导出公安网数据
*/
@RequestMapping("printExcelData")
public Byte[] printExcelData(String date){
public byte[] printExcelData(@RequestParam("date") String date, HttpServletResponse response){
List<Map<String, Object>> mapList = detailReceiptListService.selectPostDetails(replaceDate(date));
response.setContentType("application/x-download");
response.setCharacterEncoding("UTF-8");
String dateTime = DateFormatUtils.format(new Date(), "yyyyMMddHH");
// //使用Servlet实现文件下载的时候,避免浏览器自动打开文件
String fout = null;
fout = ExportExcel.exportExcelDate(mapList);
String outFile = dateTime + "公安网数据";
try {
FileInputStream fis = new FileInputStream(new File(fout));
byte[] b = new byte[fis.available()];
fis.read(b);
fis.close();
response.addHeader("Content-Disposition", "attachment;filename=" + outFile + ".xls");
return b;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
......
package com.yxproject.start.utils;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
......@@ -8,6 +7,7 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @auther zhangyusheng
......@@ -15,5 +15,109 @@ import java.util.List;
*/
public class ExportExcel {
/**
* 导出公安网信息
* @param mapList 公安网信息
* @return
*/
public static String exportExcelDate(List<Map<String,Object>> mapList){
//第一步创建workbook
HSSFWorkbook wb = new HSSFWorkbook();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
HSSFSheet sheet = wb.createSheet("公安网信息表");
sheet.setColumnWidth(0, 30 * 110);
sheet.setColumnWidth(1, 30 * 110);
sheet.setColumnWidth(2, 30 * 110);
sheet.setColumnWidth(3, 30 * 110);
sheet.setColumnWidth(4, 30 * 110);
sheet.setColumnWidth(5, 30 * 110);
sheet.setColumnWidth(6, 30 * 110);
sheet.setColumnWidth(7, 30 * 110);
sheet.setColumnWidth(8, 30 * 110);
sheet.setColumnWidth(9, 30 * 110);
sheet.setColumnWidth(10, 30 * 110);
sheet.setColumnWidth(11, 30 * 110);
sheet.setColumnWidth(12, 30 * 110);
//第三步创建行row:添加表头0行
HSSFRow row = sheet.createRow(0);
HSSFCellStyle style = wb.createCellStyle();//样式
style.setWrapText(true);//设置自动换行
HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 12);
style.setFont(font);
row = sheet.createRow(0); //创建下标为0的单元格
row.setHeightInPoints(Short.parseShort("20"));//设置行高
HSSFCell cell = row.createCell(0); //设定值
cell.setCellValue("个人受理号");
cell = row.createCell(1); //设定值
cell.setCellValue("受理号");
cell = row.createCell(2); //设定值
cell.setCellValue("姓名");
cell = row.createCell(3); //设定值
cell.setCellValue("性别");
cell = row.createCell(4); //设定值
cell.setCellValue("派出所代码");
cell = row.createCell(5); //设定值
cell.setCellValue("身份证号");
cell = row.createCell(6); //设定值
cell.setCellValue("签发机关");
cell = row.createCell(7); //设定值
cell.setCellValue("运单号");
cell = row.createCell(8); //设定值
cell.setCellValue("制证类型");
cell = row.createCell(9); //设定值
cell.setCellValue("原制证类型");
cell = row.createCell(10); //设定值
cell.setCellValue("交接日期");
cell = row.createCell(11); //设定值
cell.setCellValue("交接人");
cell = row.createCell(12); //设定值
cell.setCellValue("备注");
for (int i =0;i<mapList.size();i++){
row = sheet.createRow(i + 1);
cell = row.createCell(0); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("UPLOAD_NO")+"")?"":mapList.get(i).get("UPLOAD_NO")+"");
cell = row.createCell(1); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("ACCEPT_NO")+"")?"":mapList.get(i).get("ACCEPT_NO")+"");
cell = row.createCell(2); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("NAME")+"")?"":mapList.get(i).get("NAME")+"");
cell = row.createCell(3); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("SEX")+"")?"":mapList.get(i).get("SEX")+"");
cell = row.createCell(4); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("POLICE_CODE")+"")?"":mapList.get(i).get("POLICE_CODE")+"");
cell = row.createCell(5); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("CARD_ID")+"")?"":mapList.get(i).get("CARD_ID")+"");
cell = row.createCell(6); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("SIGN_GOVT")+"")?"":mapList.get(i).get("SIGN_GOVT")+"");
cell = row.createCell(7); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("SIGN_GOVT")+"")?"":mapList.get(i).get("SIGN_GOVT")+"");
cell = row.createCell(8); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("CARD_TYPE_ID")+"")?"":mapList.get(i).get("CARD_TYPE_ID")+"");
cell = row.createCell(9); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("OLD_CARD_TYPE_ID")+"")?"":mapList.get(i).get("OLD_CARD_TYPE_ID")+"");
cell = row.createCell(10); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("CHECK_DATE")+"")?"":mapList.get(i).get("CHECK_DATE")+"");
cell = row.createCell(11); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("CHECK_NAME")+"")?"":mapList.get(i).get("CHECK_NAME")+"");
cell = row.createCell(12); //设定值
cell.setCellValue("null".equals(mapList.get(i).get("NOTE")+"")?"":mapList.get(i).get("NOTE")+"");
}
//第六步将生成excel文件保存到指定路径下
FileOutputStream fout = null;
try {
// fout = new FileOutputStream("E:\\Excel\\" + simpleDateFormat.format(new Date()) + countyInfoList.get(0).get("COUNTYNAME") + ".xls");
fout = new FileOutputStream("D:\\Excel\\" + simpleDateFormat.format(new Date())+ "公安网信息表" + ".xls");
wb.write(fout);
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Excel文件生成成功..." + new Date());
// return "E:\\Excel\\" + simpleDateFormat.format(new Date()) +countyInfoList.get(0).get("COUNTYNAME") + ".xls";
return "D:\\Excel\\" + simpleDateFormat.format(new Date()) + "公安网信息表" + ".xls";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment