Commit 4a7314cb authored by huyuchen's avatar huyuchen

huych-含风险项目商险不购买申请提交

parent 91c7aa8d
......@@ -370,6 +370,8 @@ public interface CommonConstants {
String ID = "ID";
String PARAM_IS_NOT_ERROR = "传参异常,请检查参数";
int EXCEL_EXPORT_LIMIT = 60000;
int EXCEL_EXPORT_LIMIT_NEW = 20000;
// 给量大的表导出使用
int EXCEL_EXPORT_LIMIT_3 = 30000;
......
package com.yifu.cloud.plus.v1.yifu.salary.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
......@@ -39,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.time.LocalDateTime;
......@@ -114,10 +116,11 @@ public class TInsuranceUnpurchaseApplyServiceImpl extends ServiceImpl<TInsurance
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcel.write(out, TInsuranceUnpurchaseApplyVo.class).build();
int index = 0;
// if (count > CommonConstants.EXCEL_EXPORT_LIMIT_NEW) {
// list.add(new ExportErrorVo("导出条数最大为20000条"));
// }
if (count > CommonConstants.ZERO_INT) {
if (count > CommonConstants.EXCEL_EXPORT_LIMIT_NEW) {
exportError(response, "数据超过2万条,请联系管理员后端导出");
} else {
for (int i = 0; i <= count; i = i + CommonConstants.EXCEL_EXPORT_LIMIT_NEW) {
// 获取实际记录
searchVo.setLimitStart(i);
......@@ -132,6 +135,7 @@ public class TInsuranceUnpurchaseApplyServiceImpl extends ServiceImpl<TInsurance
list.clear();
}
}
}
} else {
WriteSheet writeSheet = EasyExcel.writerSheet("含风险项目不购买申请表" + index).build();
excelWriter.write(list, writeSheet);
......@@ -559,4 +563,38 @@ public class TInsuranceUnpurchaseApplyServiceImpl extends ServiceImpl<TInsurance
insuranceUnpurchaseApply, insuranceUnpurchaseApply.getCreateUserDeptId());
}
private void exportError(HttpServletResponse response, String errorMessage) {
String fileName = "导出异常" + DateUtil.getThisTime() + CommonConstants.XLSX;
//获取要导出的列表
List<ExportErrorVo> list = new ArrayList<>();
list.add(new ExportErrorVo(errorMessage));
ServletOutputStream out = null;
try {
out = response.getOutputStream();
response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
response.setCharacterEncoding("utf-8");
response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, "UTF-8"));
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcelFactory.write(out, ExportErrorVo.class).build();
int index = 0;
WriteSheet writeSheet = EasyExcelFactory.writerSheet("异常信息" + index).build();
excelWriter.write(list, writeSheet);
if (Common.isNotNull(list)) {
list.clear();
}
out.flush();
excelWriter.finish();
} catch (Exception e) {
log.error("执行异常", e);
} finally {
try {
if (null != out) {
out.close();
}
} catch (IOException e) {
log.error("执行异常", e);
}
}
}
}
package com.yifu.cloud.plus.v1.yifu.salary.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.metadata.IPage;
......@@ -28,6 +29,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
......@@ -83,25 +85,25 @@ public class TInsuranceUnpurchasePersonServiceImpl extends ServiceImpl<TInsuranc
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcel.write(out, TInsuranceUnpurchasePersonVo.class).build();
int index = 0;
if (count > CommonConstants.EXCEL_EXPORT_LIMIT_NEW){
WriteSheet writeSheet = EasyExcel.writerSheet("含风险项目不购买申请明细表"+index).build();
excelWriter.write(list,writeSheet);
}
if (count > CommonConstants.ZERO_INT){
if (count > CommonConstants.EXCEL_EXPORT_LIMIT_NEW) {
exportError(response, "数据超过2万条,请联系管理员后端导出");
} else {
for (int i = 0; i <= count; i = i + CommonConstants.EXCEL_EXPORT_LIMIT_NEW) {
// 获取实际记录
searchVo.setLimitStart(i);
searchVo.setLimitEnd(CommonConstants.EXCEL_EXPORT_LIMIT_NEW);
list = baseMapper.getTInsuranceUnpurchaseInfoExportList(searchVo);
if (Common.isNotNull(list)){
WriteSheet writeSheet = EasyExcel.writerSheet("含风险项目不购买申请明细表"+index).build();
excelWriter.write(list,writeSheet);
if (Common.isNotNull(list)) {
WriteSheet writeSheet = EasyExcel.writerSheet("含风险项目不购买申请明细表" + index).build();
excelWriter.write(list, writeSheet);
index++;
}
if (Common.isNotNull(list)){
if (Common.isNotNull(list)) {
list.clear();
}
}
}
}else {
WriteSheet writeSheet = EasyExcel.writerSheet("含风险项目不购买申请明细表"+index).build();
excelWriter.write(list,writeSheet);
......@@ -221,5 +223,38 @@ public class TInsuranceUnpurchasePersonServiceImpl extends ServiceImpl<TInsuranc
}
}
private void exportError(HttpServletResponse response, String errorMessage) {
String fileName = "导出异常" + DateUtil.getThisTime() + CommonConstants.XLSX;
//获取要导出的列表
List<ExportErrorVo> list = new ArrayList<>();
list.add(new ExportErrorVo(errorMessage));
ServletOutputStream out = null;
try {
out = response.getOutputStream();
response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
response.setCharacterEncoding("utf-8");
response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, "UTF-8"));
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
ExcelWriter excelWriter = EasyExcelFactory.write(out, ExportErrorVo.class).build();
int index = 0;
WriteSheet writeSheet = EasyExcelFactory.writerSheet("异常信息" + index).build();
excelWriter.write(list, writeSheet);
if (Common.isNotNull(list)) {
list.clear();
}
out.flush();
excelWriter.finish();
} catch (Exception e) {
log.error("执行异常", e);
} finally {
try {
if (null != out) {
out.close();
}
} catch (IOException e) {
log.error("执行异常", e);
}
}
}
}
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