|
@@ -1,39 +1,47 @@
|
|
|
package com.java110.job.export;
|
|
package com.java110.job.export;
|
|
|
|
|
|
|
|
-import com.java110.core.client.*;
|
|
|
|
|
|
|
+import com.java110.core.client.FileUploadTemplate;
|
|
|
import com.java110.core.log.LoggerFactory;
|
|
import com.java110.core.log.LoggerFactory;
|
|
|
import com.java110.dto.data.ExportDataDto;
|
|
import com.java110.dto.data.ExportDataDto;
|
|
|
-import com.java110.utils.cache.MappingCache;
|
|
|
|
|
|
|
+import com.java110.dto.userDownloadFile.UserDownloadFileDto;
|
|
|
|
|
+import com.java110.intf.job.IUserDownloadFileV1InnerServiceSMO;
|
|
|
|
|
+import com.java110.po.userDownloadFile.UserDownloadFilePo;
|
|
|
import com.java110.utils.factory.ApplicationContextFactory;
|
|
import com.java110.utils.factory.ApplicationContextFactory;
|
|
|
-import com.java110.utils.util.COSUtil;
|
|
|
|
|
-import com.java110.utils.util.OSSUtil;
|
|
|
|
|
|
|
+import com.java110.utils.util.ExceptionUtil;
|
|
|
|
|
+import com.java110.utils.util.StringUtil;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
-import java.util.List;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 导出数据执行器
|
|
* 导出数据执行器
|
|
|
*/
|
|
*/
|
|
|
-public class ExportDataExecutor implements Runnable{
|
|
|
|
|
|
|
+public class ExportDataExecutor implements Runnable {
|
|
|
private static final Logger log = LoggerFactory.getLogger(ExportDataQueue.class);
|
|
private static final Logger log = LoggerFactory.getLogger(ExportDataQueue.class);
|
|
|
|
|
|
|
|
|
|
+ private IUserDownloadFileV1InnerServiceSMO userDownloadFileV1InnerServiceSMOImpl;
|
|
|
|
|
+
|
|
|
|
|
+ private FileUploadTemplate fileUploadTemplate;
|
|
|
|
|
|
|
|
//默认线程大小
|
|
//默认线程大小
|
|
|
private static final int DEFAULT_EXPORT_POOL = 4;
|
|
private static final int DEFAULT_EXPORT_POOL = 4;
|
|
|
|
|
|
|
|
|
|
+ public ExportDataExecutor() {
|
|
|
|
|
+ this.userDownloadFileV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("userDownloadFileV1InnerServiceSMOImpl", IUserDownloadFileV1InnerServiceSMO.class);
|
|
|
|
|
+ this.fileUploadTemplate = ApplicationContextFactory.getBean("fileUploadTemplate", FileUploadTemplate.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
doExportData();
|
|
doExportData();
|
|
|
- }catch (Exception e){
|
|
|
|
|
- log.error("处理消息异常",e);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理消息异常", e);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -41,9 +49,14 @@ public class ExportDataExecutor implements Runnable{
|
|
|
|
|
|
|
|
private void doExportData() throws Exception {
|
|
private void doExportData() throws Exception {
|
|
|
|
|
|
|
|
- ExportDataDto exportDataDto = ExportDataQueue.getData();
|
|
|
|
|
|
|
+ ExportDataDto exportDataDto = ExportDataQueue.getData();
|
|
|
|
|
+
|
|
|
|
|
+ ByteArrayInputStream inputStream = null;
|
|
|
|
|
+ ByteArrayOutputStream os = null;
|
|
|
|
|
+ SXSSFWorkbook workbook = null;
|
|
|
|
|
+ String fileName = "";
|
|
|
|
|
|
|
|
- if(exportDataDto == null){
|
|
|
|
|
|
|
+ if (exportDataDto == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -51,49 +64,57 @@ public class ExportDataExecutor implements Runnable{
|
|
|
|
|
|
|
|
IExportDataAdapt exportDataAdaptImpl = ApplicationContextFactory.getBean(businessAdapt, IExportDataAdapt.class);
|
|
IExportDataAdapt exportDataAdaptImpl = ApplicationContextFactory.getBean(businessAdapt, IExportDataAdapt.class);
|
|
|
|
|
|
|
|
- if(exportDataAdaptImpl == null){
|
|
|
|
|
- return ;
|
|
|
|
|
|
|
+ if (exportDataAdaptImpl == null) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- SXSSFWorkbook workbook= exportDataAdaptImpl.exportData(exportDataDto);
|
|
|
|
|
-
|
|
|
|
|
- //保存文件路径到 文件下载表
|
|
|
|
|
- FileUploadTemplate fileUploadTemplate = ApplicationContextFactory.getBean("fileUploadTemplate", FileUploadTemplate.class);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- ByteArrayInputStream inputStream = null;
|
|
|
|
|
- ByteArrayOutputStream os = null;
|
|
|
|
|
|
|
+ updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_DOING,"", "开始下载");
|
|
|
try {
|
|
try {
|
|
|
-
|
|
|
|
|
|
|
+ workbook = exportDataAdaptImpl.exportData(exportDataDto);
|
|
|
|
|
+ //保存文件路径到 文件下载表
|
|
|
os = new ByteArrayOutputStream();
|
|
os = new ByteArrayOutputStream();
|
|
|
workbook.write(os);
|
|
workbook.write(os);
|
|
|
inputStream = new ByteArrayInputStream(os.toByteArray());
|
|
inputStream = new ByteArrayInputStream(os.toByteArray());
|
|
|
|
|
|
|
|
- fileUploadTemplate.saveFile(inputStream,exportDataDto.getFileName());
|
|
|
|
|
|
|
+ fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName());
|
|
|
|
|
+ updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH,fileName, "下载完成");
|
|
|
|
|
|
|
|
- }finally {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FAIL, "","下载失败" + ExceptionUtil.getStackTrace(e));
|
|
|
|
|
+ } finally {
|
|
|
try {
|
|
try {
|
|
|
workbook.close();
|
|
workbook.close();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
inputStream.close();
|
|
inputStream.close();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
os.close();
|
|
os.close();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void updateUserDownloadFile(ExportDataDto exportDataDto, String state,String url, String remark) {
|
|
|
|
|
+ UserDownloadFilePo userDownloadFilePo = new UserDownloadFilePo();
|
|
|
|
|
+ userDownloadFilePo.setDownloadId(exportDataDto.getDownloadId());
|
|
|
|
|
+ userDownloadFilePo.setState(state);
|
|
|
|
|
+ if(!StringUtil.isEmpty(url)){
|
|
|
|
|
+ userDownloadFilePo.setTempUrl(url);
|
|
|
|
|
+ }
|
|
|
|
|
+ userDownloadFilePo.setRemark(remark.length() > 512 ? remark.substring(0, 512): remark);
|
|
|
|
|
+ userDownloadFileV1InnerServiceSMOImpl.updateUserDownloadFile(userDownloadFilePo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 线程启动器
|
|
* 线程启动器
|
|
|
*/
|
|
*/
|
|
|
- public static void startExportDataExecutor(){
|
|
|
|
|
|
|
+ public static void startExportDataExecutor() {
|
|
|
ExecutorService executorService = Executors.newFixedThreadPool(DEFAULT_EXPORT_POOL);
|
|
ExecutorService executorService = Executors.newFixedThreadPool(DEFAULT_EXPORT_POOL);
|
|
|
executorService.execute(new ExportDataExecutor());
|
|
executorService.execute(new ExportDataExecutor());
|
|
|
}
|
|
}
|