Commit e77f90b1 by 翁国栋

bug修改

parent cd094ea2
...@@ -34,11 +34,10 @@ import io.swagger.annotations.ApiOperation; ...@@ -34,11 +34,10 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIBuilder;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -2106,4 +2105,98 @@ public class InsureContorll { ...@@ -2106,4 +2105,98 @@ public class InsureContorll {
} }
} }
} }
@PostMapping(value = "/exportInsureUserData")
@ApiOperation(value = "导出投保人员名单", httpMethod = "POST", notes = "导出投保人员名单")
@ResponseBody
public Result<Object> exportInsureUserData(@RequestBody InsureDto insureDto, HttpServletResponse resp) {
String[] rowName = new String[]{"序号", "被保险人姓名(必选)", "证件类型(必选)", "证件号码(必选)", "方案名称(必选)", "二、三轮车车架号(必选)", "职业类别(必选)"};
XSSFWorkbook workbook = null;
/*
1,创建工作簿对象,然后创建大标题行,并设置标题
*/
// 创建工作簿对象
workbook = new XSSFWorkbook();
// 创建一个表格对象
XSSFSheet sheet = workbook.createSheet("Sheet1");
String mark = "title";
// 定义大标题行的样式
XSSFCellStyle titleCellStyle = ExcelUtils.getCellStyle(workbook, mark);
String title="导出线下人员名单";
// 如果参数title不等空,则设置Sheet表格的大标题
if (!"null".equals(title) && title != null
&& !"".equals(title) && !title.trim().isEmpty()) {
// 创建表格大标题行
XSSFRow titleRow = sheet.createRow(0);
// 创建表格大标题行的第一个单元格
XSSFCell titleCell = titleRow.createCell(0);
// 定义大标题行的宽度和高度(合并单元格)
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (rowName.length - 1)));
// 设置大标题行的单元格样式
titleCell.setCellStyle(titleCellStyle);
// 设置大标题行的单元格名称
titleCell.setCellValue(title);
}
int columnNum = rowName.length;
// 创建小标题行,由于0行和1行用作大标题行,所以小标题行从2开始
XSSFRow subTitleRow = sheet.createRow(2);
// 将列头设置到sheet的单元格中
for (int i = 0; i < columnNum; i++) {
// 创建小标题行的单元格
XSSFCell subTitleCell = subTitleRow.createCell(i);
// 设置单元格的单元格类型
subTitleCell.setCellType(CellType.STRING);
// 使用数组中的数据作为单元格的文本来创建小标题
XSSFRichTextString text = new XSSFRichTextString(rowName[i]);
// 设置小标题单元格的样式
subTitleCell.setCellStyle(titleCellStyle);
// 设置文本到小标题单元格中
subTitleCell.setCellValue(text);
}
XSSFCell cell=null;
List<PlansDto> list=insureDto.getPlans();
for (int i = 0; i < list.size(); i++) {
PlansDto objArr = list.get(i);
List<YgglMainEmp> ygglMainEmpList = ygglMainEmpMapper.selectListByIds(objArr.getUserIds());
// 创建当前要填充数据的行对象
for (int j = 0; j < ygglMainEmpList.size(); j++) {
XSSFRow currentRow = sheet.createRow(i + 3);
//第i+1行 第一列
cell = currentRow.createCell(0, CellType.NUMERIC);
cell.setCellValue(i+1);
cell = currentRow.createCell(1);
cell.setCellValue(i+1);
}
OutputStream os = null;
try {
resp.setContentType("application/octet-stream");
resp.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(list.size()+"名人员清单.xlsx", "UTF-8"));
resp.setCharacterEncoding("UTF-8");
os = resp.getOutputStream();
workbook.write(os);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return ResultUtil.error("导出成功");
}
} }
...@@ -33,7 +33,10 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; ...@@ -33,7 +33,10 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -128,17 +131,89 @@ public class InsureUserController{ ...@@ -128,17 +131,89 @@ public class InsureUserController{
policyDto.setPolicyDateStart(policyDateStart); policyDto.setPolicyDateStart(policyDateStart);
policyDto.setPlanId(planId); policyDto.setPlanId(planId);
policyDto.setCategoryId(categoryId); policyDto.setCategoryId(categoryId);
policyDto.setPage(null); // policyDto.setPage(null);
policyDto.setAll(true);
List<PolicyDto> userList = insureUserMapper.selectPolicyList(policyDto); List<PolicyDto> userList = insureUserMapper.selectPolicyList(policyDto);
String[] rowName = new String[]{"编号", "姓名", "证件类型", "证件号", "保单号", "状态", "计划", "保险生效时间", "保险失效时间"}; String[] rowName = new String[]{"编号", "姓名", "证件类型", "证件号", "保单号", "状态", "计划", "保险生效时间", "保险失效时间"};
List<Object[]> list = null;
XSSFWorkbook workbook = null;
/*
1,创建工作簿对象,然后创建大标题行,并设置标题
*/
// 创建工作簿对象
workbook = new XSSFWorkbook();
// 创建一个表格对象
XSSFSheet sheet = workbook.createSheet("Sheet1");
String mark = "title";
// 定义大标题行的样式
XSSFCellStyle titleCellStyle = ExcelUtils.getCellStyle(workbook, mark);
String title="导出线下人员名单";
// 如果参数title不等空,则设置Sheet表格的大标题
if (!"null".equals(title) && title != null
&& !"".equals(title) && !title.trim().isEmpty()) {
// 创建表格大标题行
XSSFRow titleRow = sheet.createRow(0);
// 创建表格大标题行的第一个单元格
XSSFCell titleCell = titleRow.createCell(0);
// 定义大标题行的宽度和高度(合并单元格)
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (rowName.length - 1)));
// 设置大标题行的单元格样式
titleCell.setCellStyle(titleCellStyle);
// 设置大标题行的单元格名称
titleCell.setCellValue(title);
}
int columnNum = rowName.length;
// 创建小标题行,由于0行和1行用作大标题行,所以小标题行从2开始
XSSFRow subTitleRow = sheet.createRow(2);
// 将列头设置到sheet的单元格中
for (int i = 0; i < columnNum; i++) {
// 创建小标题行的单元格
XSSFCell subTitleCell = subTitleRow.createCell(i);
// 设置单元格的单元格类型
subTitleCell.setCellType(CellType.STRING);
// 使用数组中的数据作为单元格的文本来创建小标题
XSSFRichTextString text = new XSSFRichTextString(rowName[i]);
// 设置小标题单元格的样式
subTitleCell.setCellStyle(titleCellStyle);
// 设置文本到小标题单元格中
subTitleCell.setCellValue(text);
}
XSSFCell cell=null;
for (int i = 0; i < userList.size(); i++) {
PolicyDto objArr = userList.get(i);
// 创建当前要填充数据的行对象
XSSFRow currentRow = sheet.createRow(i + 3);
//第i+1行 第一列
cell = currentRow.createCell(0, CellType.NUMERIC);
cell.setCellValue(i+1);
cell = currentRow.createCell(1);
cell.setCellValue(objArr.getName());
cell = currentRow.createCell(2);
cell.setCellValue("身份证");
cell = currentRow.createCell(3);
cell.setCellValue(objArr.getZjNum());
cell = currentRow.createCell(4);
cell.setCellValue(objArr.getPolicyNo());
cell = currentRow.createCell(5);
cell.setCellValue(objArr.getStatus().equals("1")?"生效":"失效");
cell = currentRow.createCell(6);
cell.setCellValue(objArr.getPlanName());
cell = currentRow.createCell(7);
cell.setCellValue(objArr.getPolicyDateStart());
cell = currentRow.createCell(8);
cell.setCellValue(objArr.getPolicyDateEnd());
}
OutputStream os = null; OutputStream os = null;
try { try {
resp.setContentType("application/octet-stream"); resp.setContentType("application/octet-stream");
resp.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(localDate+"_"+list.size()+"名人员清单.xlsx", "UTF-8")); resp.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(localDate+"_"+userList.size()+"名人员清单.xlsx", "UTF-8"));
resp.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8");
os = resp.getOutputStream(); os = resp.getOutputStream();
XSSFWorkbook workbook= ExcelUtils.exportExcel(localDate+"_"+list.size()+"投保人列表导出.xlsx",rowName, Collections.singletonList(list.stream().toArray()));
workbook.write(os); workbook.write(os);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -8,10 +8,9 @@ import org.apache.poi.xssf.usermodel.*; ...@@ -8,10 +8,9 @@ import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import javax.servlet.ServletOutputStream;
import java.io.FileInputStream; import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.*;
import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -425,7 +424,7 @@ public class ExcelUtils { ...@@ -425,7 +424,7 @@ public class ExcelUtils {
* @param mark 标记,当且仅当为title时获取标题行的样式,否则为普通单元格样式 * @param mark 标记,当且仅当为title时获取标题行的样式,否则为普通单元格样式
* @return * @return
*/ */
private static XSSFCellStyle getCellStyle(XSSFWorkbook workbook, String mark) { public static XSSFCellStyle getCellStyle(XSSFWorkbook workbook, String mark) {
// 创建字体对象 // 创建字体对象
XSSFFont font = workbook.createFont(); XSSFFont font = workbook.createFont();
...@@ -507,5 +506,16 @@ public class ExcelUtils { ...@@ -507,5 +506,16 @@ public class ExcelUtils {
return xssfCell.getStringCellValue().trim(); return xssfCell.getStringCellValue().trim();
} }
} }
public static void excelOutputStream(XSSFWorkbook workbook, String fileName, HttpServletResponse response){
try {
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -284,7 +284,9 @@ insure: ...@@ -284,7 +284,9 @@ insure:
#保全申请 #保全申请
batchUrl: 'http://sandbox.portal.unistar-ins.com/fuli/Home/WelfareProduct/batch_declare' batchUrl: 'http://sandbox.portal.unistar-ins.com/fuli/Home/WelfareProduct/batch_declare'
#保全取消支付 #保全取消支付
cancelPayment: 'http://sandbox.portal.unistar-ins.com/fuli/Home/OrderImport/order_import_set' cancelPayment: 'http://sandbox.portal.unistar-ins.com/cps/Labor/OrderImport/order_import_set'
#预付款提交接口
order_import_set: 'https://portal.unistar-ins.com/cps/Labor/OrderImport/order_import_set'
youling: youling:
serverUrl: 'https://tapi.youlingrc.com' serverUrl: 'https://tapi.youlingrc.com'
......
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