2021-01-06【easyExcel,springBoot 批量任务】
程序员文章站
2022-06-28 16:22:09
easyExcel 下载// project\model\ImpGjContractModel.javapublic void exportGjContractRecordMbExcel() throws IOException { List list =null; ServletOutputStream out = response.getOutputStream(); ExcelWriter wr...
springBoot @Async 异步任务
// async\GjContractAsync.java
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 异步
*/
@Component
public class GjContractAsync {
private static Logger logger = LoggerFactory.getLogger(GjContractAsync.class);
private static String DATE_FORMAT1 = "yyyyMMdd";
private static String SAV_CUS = "2"; // 保险蓄客
@Autowired
private GjKhxxDao gjKhxxDao;
@Autowired
private GjContractDao gjContractDao;
@Autowired
private HisGjContractDao hisGjContractDao;
@Transactional(rollbackFor = Exception.class)
@Async
public void mainAysc(List<Object> dataList, UserInfo userInfo) {
logger.info("开始执行xxxx异步任务....");
// 异步任务逻辑,无返回
logger.info("结束xxxx异步任务....");
}
/**
* 【保单状态处理】
* @author copote
* @date 2020/12/17 16:07
*/
private ImpGjContractModel handerContractStatus(ImpGjContractModel item) {
if(CommonUtil.isNotEmpty( item.getcState())){
// NORMAL((String) "1","正常"),
// CANCEL((String) "2","当日撤单");
if(ContractStatusEnum.NORMAL.getName().equals( item.getcState().trim()) ||
ContractStatusEnum.NORMAL.getCode().equals( item.getcState().trim())
){
item.setcState(ContractStatusEnum.NORMAL.getCode());
}else{
// 保费为负值
item.setcState(ContractStatusEnum.CANCEL.getCode());
System.out.println(ContractStatusEnum.CANCEL.getName()+"=========保费为负值=========="+item.getnPremium().negate());
item.setnPremium(item.getnPremium().negate());
}
}
return item;
}
}
easyExcel 下载
// project\model\ImpGjContractModel.java
public void exportGjContractRecordMbExcel() throws IOException {
List<ImpGjContractModel> list =null;
ServletOutputStream out = response.getOutputStream();
ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true);
String fileName = "个金保险蓄客保险出单模板";
Sheet sheet = new Sheet(1, 0,ImpGjContractModel.class);
//设置自适应宽度
sheet.setAutoWidth(Boolean.TRUE);
// 第一个 sheet 名称
sheet.setSheetName("个金保险蓄客保险出单");
writer.write(list, sheet);
//通知浏览器以附件的形式下载处理,设置返回头要注意文件名有中文
// response.setHeader("Content-disposition", "attachment;filename=" + new String( fileName.getBytes("gb2312"), "ISO8859-1" ) + ".xlsx");
response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "utf-8"));
writer.finish();
response.setContentType("multipart/form-data");
response.setCharacterEncoding("utf-8");
out.flush();
}
spring Scheduled 批量任务
// spring 批量任务:project\task\GjStatisTask.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
public class GjStatisTask {
private static Logger logger = LoggerFactory.getLogger(GjStatisTask.class);
@Autowired
private GjKhxxDao gjKhxxDao;
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron="0 0 17 * * ?")
// @Scheduled(cron="0 20 * * * ?")
void GjTemporaryStatis(){
logger.info("开始执行个金统计生成临时表数据任务....");
//先执行 truncate table T_STBT_KHXX_GJ_TGTJ 删除临时表
gjKhxxDao.deleteKhxxGjTgtj();
gjKhxxDao.insertIntoKhxxGjTgtj();
// insert into select 添加到临时表
logger.info("结束个金统计生成临时表数据任务....");
}
}
本文地址:https://blog.csdn.net/qq_32265719/article/details/112259450