Commit 4a7314cb authored by huyuchen's avatar huyuchen

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

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