|
@@ -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);
|
|
|
}
|
|
}
|