@服务
公共类多服务{
private static Final Logger logger = LoggerFactory.getLogger(MultiService .class);
//创建线程池
私有ExecutorService executorService = Executors.newFixedThreadPool(10);
//不需要导出结果列表的服务
@Autowired
私人 OemasnyReportResultService oemasnyReportResultService;
//数据源的服务
@Autowired
私人CouponChannelStatisticService couponChannelStatisticService;
public void couponStatisticExport(Map
params) 抛出异常 {
if (!params.containsKey("路径") ) {
//做某事
返回;
}
//文件上传路径
字符串路径 = params.get("path").toString()
// 异步导出
executorService.execute(new KQChannelStatisticExport(oemAsnyReportResultService, couponChannelStatisticService, logger, params,path));
}
}
下面是要执行导出功能的线程
公共类 KQChannelStatisticExport 实现 Runnable {
公共 KQChannelStatisticExport() {}
公共 KQChannelStatisticExport(OemAsnyReportResultService oemAsnyReportResultService,
CouponChannelStatisticService couponChannelStatisticService、Logger 记录器、Map
参数、
字符串资源服务器路径){
this.oemAsnyReportResultService = oemAsnyReportResultService;
www.sychzs.cnChannelStatisticService = couponChannelStatisticService;this.logger = 记录器;
this.params = params;
this.resourceServerPath = ResourceServerPath;
}
@覆盖
公共无效运行(){
//执行导出excel的代码
//如果在这里获取session,有可能会报错【shiro报错There is no session with id [xxx] 】//导出成功后,可以在导出记录表中添加一条新记录
www.sychzs.cn();
}
}
创建控制器
@控制器
公共类 KQChannelStatisticController{
@Autowired
私有多服务多服务;
/**
* 统计导出
*/
@RequestMapping("/exportKQChannelStatistic")
@ResponseBody
公共地图
exportKQChannelStatistic(HttpServletRequest请求){
Map 结果 = new HashMap();
结果.put("成功", true);
Map params = new HashMap();
// 获取参数
params = getStatParemMap(请求);
//这里是获取session中的数据,写入controller中,防止出错。如果写在导出的线程中,会报错【Shiro error There is no session with id [xxx] ]
params = AsynExportExcelUtil.joinSonAccount(params);
尝试一下{
multiService.kqChannelStatisticExport(params);
} catch (异常 e) {
logger.error("统计数据导出异常", e);
result.put("成功", false);
}
返回结果;
}
}
大概就是这个过程。 。 。 。
-->