From 3da0feec9d4825c7ee18eaf948d0f7d5d206eca4 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 05 六月 2023 10:24:02 +0800
Subject: [PATCH] finish report export excel
---
service-job/src/main/java/com/java110/job/export/ExportDataExecutor.java | 101 ++++++++++++++++++++++++++++++++++----------------
1 files changed, 69 insertions(+), 32 deletions(-)
diff --git a/service-job/src/main/java/com/java110/job/export/ExportDataExecutor.java b/service-job/src/main/java/com/java110/job/export/ExportDataExecutor.java
index b24c955..c15c0a2 100644
--- a/service-job/src/main/java/com/java110/job/export/ExportDataExecutor.java
+++ b/service-job/src/main/java/com/java110/job/export/ExportDataExecutor.java
@@ -1,49 +1,75 @@
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.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.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.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.List;
import java.util.concurrent.ExecutorService;
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 IUserDownloadFileV1InnerServiceSMO userDownloadFileV1InnerServiceSMOImpl;
+
+ private FileUploadTemplate fileUploadTemplate;
//榛樿绾跨▼澶у皬
private static final int DEFAULT_EXPORT_POOL = 4;
+ private boolean isRun = false;
+
+ public ExportDataExecutor(boolean isRun) {
+
+ this.isRun = isRun;
+ }
+
+ public ExportDataExecutor() {
+ }
+
@Override
public void run() {
- try {
- doExportData();
- }catch (Exception e){
- log.error("澶勭悊娑堟伅寮傚父",e);
- e.printStackTrace();
+ while (isRun) {
+ log.debug("瀵煎嚭鏁版嵁绾跨▼寮�濮嬪鐞�");
+ try {
+ doExportData();
+ } catch (Throwable e) {
+ log.error("澶勭悊娑堟伅寮傚父", e);
+ e.printStackTrace();
+ }
+ log.debug("瀵煎嚭鏁版嵁绾跨▼澶勭悊瀹屾垚");
+
}
}
private void doExportData() throws Exception {
- ExportDataDto exportDataDto = ExportDataQueue.getData();
+ ExportDataDto exportDataDto = ExportDataQueue.getData();
- if(exportDataDto == null){
+ this.userDownloadFileV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("userDownloadFileV1InnerServiceSMOImpl", IUserDownloadFileV1InnerServiceSMO.class);
+ this.fileUploadTemplate = ApplicationContextFactory.getBean("fileUploadTemplate", FileUploadTemplate.class);
+
+ ByteArrayInputStream inputStream = null;
+ ByteArrayOutputStream os = null;
+ SXSSFWorkbook workbook = null;
+ String fileName = "";
+
+ if (exportDataDto == null) {
return;
}
@@ -51,50 +77,61 @@
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 {
-
+ workbook = exportDataAdaptImpl.exportData(exportDataDto);
+ //淇濆瓨鏂囦欢璺緞鍒� 鏂囦欢涓嬭浇琛�
os = new ByteArrayOutputStream();
workbook.write(os);
inputStream = new ByteArrayInputStream(os.toByteArray());
- fileUploadTemplate.saveFile(inputStream,exportDataDto.getFileName());
+ fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName());
- }finally {
+
+ updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH,fileName, "涓嬭浇瀹屾垚");
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FAIL, "","涓嬭浇澶辫触" + ExceptionUtil.getStackTrace(e));
+ } finally {
try {
workbook.close();
- }catch (Exception e){
+ } catch (Exception e) {
}
try {
inputStream.close();
- }catch (Exception e){
+ } catch (Exception e) {
}
try {
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.execute(new ExportDataExecutor());
+ executorService.execute(new ExportDataExecutor(true));
}
}
--
Gitblit v1.8.0