Selaa lähdekoodia

fix:
文件导入bug修复

18339543638 2 vuotta sitten
vanhempi
commit
a4aa52ca7d

+ 2 - 0
tr-modules/tr-module-export/src/main/java/cn/tr/module/excel/core/service/ExcelService.java

@@ -21,6 +21,7 @@ import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
 import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
 import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
 import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
 import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.util.ReflectionUtils;
 import org.springframework.util.ReflectionUtils;
 
 
@@ -50,6 +51,7 @@ public class ExcelService {
     private EventBus eventBus;
     private EventBus eventBus;
 
 
     @Autowired
     @Autowired
+    @Lazy
     private ExcelSheetManage sheetManage;
     private ExcelSheetManage sheetManage;
     /**
     /**
      * 导出execl
      * 导出execl

+ 17 - 6
tr-modules/tr-module-export/src/main/java/cn/tr/module/excel/core/service/ExcelSheetManage.java

@@ -1,6 +1,10 @@
 package cn.tr.module.excel.core.service;
 package cn.tr.module.excel.core.service;
 
 
 import cn.tr.module.excel.core.constant.ExcelConstant;
 import cn.tr.module.excel.core.constant.ExcelConstant;
+import cn.tr.module.excel.mapper.SysExportSheetMapper;
+import cn.tr.module.excel.sheet.dto.SysExportSheetDTO;
+import cn.tr.module.excel.sheet.service.ISysExportSheetService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.Cache;
 import org.springframework.cache.Cache;
 import org.springframework.cache.CacheManager;
 import org.springframework.cache.CacheManager;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
@@ -19,10 +23,11 @@ import java.util.Optional;
 public class ExcelSheetManage {
 public class ExcelSheetManage {
     private CacheManager cacheManager;
     private CacheManager cacheManager;
     private Map<String, Cache> cacheMap;
     private Map<String, Cache> cacheMap;
-
-    public ExcelSheetManage(CacheManager cacheManager) {
+    private ISysExportSheetService exportSheetService;
+    public ExcelSheetManage(CacheManager cacheManager, ISysExportSheetService exportSheetService) {
         this.cacheManager = cacheManager;
         this.cacheManager = cacheManager;
         this.cacheMap = new HashMap<>();
         this.cacheMap = new HashMap<>();
+        this.exportSheetService=exportSheetService;
     }
     }
 
 
     /**
     /**
@@ -38,13 +43,19 @@ public class ExcelSheetManage {
      * @param sheetId
      * @param sheetId
      * @param totalCount
      * @param totalCount
      */
      */
-    public boolean handleFinishByParseFinish(String sheetId,int totalCount){
+    public boolean handleFinishByParseFinish(String sheetId,int totalCount) throws Exception {
         Cache cache = getCache(sheetId);
         Cache cache = getCache(sheetId);
         //导入失败的数量
         //导入失败的数量
         Integer failCount = Optional.ofNullable(cache.get(ExcelConstant.SHEET_FAIL_COUNT, Integer.class)).orElse(0);
         Integer failCount = Optional.ofNullable(cache.get(ExcelConstant.SHEET_FAIL_COUNT, Integer.class)).orElse(0);
         //导入成功的数量
         //导入成功的数量
         Integer successCount =Optional.ofNullable( cache.get(ExcelConstant.SHEET_SUCCESS_COUNT, Integer.class)).orElse(0);
         Integer successCount =Optional.ofNullable( cache.get(ExcelConstant.SHEET_SUCCESS_COUNT, Integer.class)).orElse(0);
         cache.put(ExcelConstant.SHEET_TOTAL_COUNT,totalCount);
         cache.put(ExcelConstant.SHEET_TOTAL_COUNT,totalCount);
+        if(handleFinishByRowResult(sheetId,null)){
+            //导入完成
+            SysExportSheetDTO exportSheet = exportSheetService.selectSysExportSheetById(sheetId);
+
+            exportSheetService.handleSheetFinish(SysExportSheetMapper.INSTANCE.convertPO(exportSheet));
+        }
         return totalCount==(failCount+successCount);
         return totalCount==(failCount+successCount);
     }
     }
 
 
@@ -53,16 +64,16 @@ public class ExcelSheetManage {
      * @param sheetId
      * @param sheetId
      * @param success
      * @param success
      */
      */
-    public boolean handleFinishByRowResult(String sheetId,boolean success){
+    public boolean handleFinishByRowResult(String sheetId,Boolean success){
         Cache cache = getCache(sheetId);
         Cache cache = getCache(sheetId);
         //导入失败的数量
         //导入失败的数量
         Integer failCount = Optional.ofNullable(cache.get(ExcelConstant.SHEET_FAIL_COUNT, Integer.class)).orElse(0);
         Integer failCount = Optional.ofNullable(cache.get(ExcelConstant.SHEET_FAIL_COUNT, Integer.class)).orElse(0);
         //导入成功的数量
         //导入成功的数量
         Integer successCount =Optional.ofNullable( cache.get(ExcelConstant.SHEET_SUCCESS_COUNT, Integer.class)).orElse(0);
         Integer successCount =Optional.ofNullable( cache.get(ExcelConstant.SHEET_SUCCESS_COUNT, Integer.class)).orElse(0);
-        if(success){
+        if(Boolean.TRUE.equals(success)){
             ++successCount;
             ++successCount;
             cache.put(ExcelConstant.SHEET_SUCCESS_COUNT,successCount);
             cache.put(ExcelConstant.SHEET_SUCCESS_COUNT,successCount);
-        }else {
+        }else if(Boolean.FALSE.equals(success)){
             ++failCount;
             ++failCount;
             cache.put(ExcelConstant.SHEET_FAIL_COUNT,failCount);
             cache.put(ExcelConstant.SHEET_FAIL_COUNT,failCount);
         }
         }

+ 4 - 0
tr-modules/tr-module-export/src/main/java/cn/tr/module/excel/sheet/service/ISysExportSheetService.java

@@ -1,6 +1,8 @@
 package cn.tr.module.excel.sheet.service;
 package cn.tr.module.excel.sheet.service;
 
 
 import cn.tr.module.excel.sheet.dto.SysExportSheetDTO;
 import cn.tr.module.excel.sheet.dto.SysExportSheetDTO;
+import cn.tr.module.excel.sheet.po.SysExportSheetPO;
+
 import java.util.*;
 import java.util.*;
 
 
 /**
 /**
@@ -64,4 +66,6 @@ public interface ISysExportSheetService{
      * @param totalCount
      * @param totalCount
      */
      */
     void doSheetCallback(String sheetId,int totalCount) throws Exception;
     void doSheetCallback(String sheetId,int totalCount) throws Exception;
+
+    void handleSheetFinish(SysExportSheetPO sheet) throws Exception;
 }
 }

+ 3 - 1
tr-modules/tr-module-export/src/main/java/cn/tr/module/excel/sheet/service/impl/SysExportSheetServiceImpl.java

@@ -50,6 +50,7 @@ public class SysExportSheetServiceImpl implements ISysExportSheetService {
     private ISysExportRowService rowService;
     private ISysExportRowService rowService;
 
 
     @Autowired
     @Autowired
+    @Lazy
     private ExcelSheetManage excelSheetManage;
     private ExcelSheetManage excelSheetManage;
     /**
     /**
      * 根据id查询导入工作簿记录表
      * 根据id查询导入工作簿记录表
@@ -134,7 +135,8 @@ public class SysExportSheetServiceImpl implements ISysExportSheetService {
         baseRepository.updateById(sheet);
         baseRepository.updateById(sheet);
     }
     }
 
 
-    private void handleSheetFinish(SysExportSheetPO sheet) throws Exception {
+    @Override
+    public void handleSheetFinish(SysExportSheetPO sheet) throws Exception {
         sheet.setStatus(SheetImportStatus.importSuccess.getValue());
         sheet.setStatus(SheetImportStatus.importSuccess.getValue());
         sheet.setEndTime(new Date());
         sheet.setEndTime(new Date());
         sheet.setExportFileId(createImportFile(sheet));
         sheet.setExportFileId(createImportFile(sheet));