|
@@ -6,9 +6,11 @@ import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.base.BaseEntity;
|
|
|
import com.fjhx.config.TaskPoolConfig;
|
|
|
+import com.fjhx.constants.VRedisKeyConstant;
|
|
|
import com.fjhx.entity.excel.ExcelImportLog;
|
|
|
import com.fjhx.listener.EasyExcelListener;
|
|
|
import com.fjhx.mapper.excel.ExcelImportLogMapper;
|
|
|
+import com.fjhx.params.excel.BaseExcelVo;
|
|
|
import com.fjhx.params.excel.ExcelProcessingProgress;
|
|
|
import com.fjhx.service.excel.ExcelImportLogService;
|
|
|
import org.springblade.core.excel.support.ExcelException;
|
|
@@ -48,8 +50,8 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
private BladeRedis bladeRedis;
|
|
|
|
|
|
@Override
|
|
|
- public <T> void asyncRead(String flag, MultipartFile file, Class<T> cls, Integer businessType,
|
|
|
- Consumer<List<T>> handleFun, Runnable errorFun) {
|
|
|
+ public <T extends BaseExcelVo> void asyncRead(Long flag, MultipartFile file, Class<T> cls, Integer businessType,
|
|
|
+ Consumer<List<T>> handleFun, Runnable errorFun) {
|
|
|
|
|
|
String filename = file.getOriginalFilename();
|
|
|
if (ObjectUtils.isEmpty(filename)) {
|
|
@@ -119,19 +121,19 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ExcelProcessingProgress getReadRate(String flag) {
|
|
|
- ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(flag);
|
|
|
+ public ExcelProcessingProgress getReadRate(Long flag) {
|
|
|
+ ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(VRedisKeyConstant.EXCEL_FLAG_KEY + flag);
|
|
|
|
|
|
// 如果处理完成、用户取消、发生异常,删除缓存
|
|
|
if (excelProcessingProgress != null && excelProcessingProgress.getStatus() > 3) {
|
|
|
- bladeRedis.del(flag);
|
|
|
+ bladeRedis.del(VRedisKeyConstant.EXCEL_FLAG_KEY + flag);
|
|
|
}
|
|
|
|
|
|
return excelProcessingProgress;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void stopRead(String flag) {
|
|
|
+ public void stopRead(Long flag) {
|
|
|
// 导入信息放入redis缓存
|
|
|
ExcelProcessingProgress excelProcessingProgress = new ExcelProcessingProgress();
|
|
|
excelProcessingProgress.setStatus(6); // 预处理阶段
|
|
@@ -139,14 +141,19 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
setProgress(flag, excelProcessingProgress);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void readErrorData(Long flag, List<? extends BaseExcelVo> list) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 插入缓存信息
|
|
|
*
|
|
|
* @param flag 缓存标记
|
|
|
* @param excelProcessingProgress 缓存对象
|
|
|
*/
|
|
|
- private synchronized void setProgress(String flag, ExcelProcessingProgress excelProcessingProgress) {
|
|
|
- bladeRedis.setEx(flag, excelProcessingProgress, 60L * 60 * 12);
|
|
|
+ private synchronized void setProgress(Long flag, ExcelProcessingProgress excelProcessingProgress) {
|
|
|
+ bladeRedis.setEx(VRedisKeyConstant.EXCEL_FLAG_KEY + flag, excelProcessingProgress, 60L * 60 * 12);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -156,15 +163,15 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
* @param status 状态
|
|
|
* @param percentage 进度
|
|
|
*/
|
|
|
- private synchronized void verificationAndUpdateProgress(String flag, Integer status, Integer percentage) {
|
|
|
- ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(flag);
|
|
|
+ private synchronized void verificationAndUpdateProgress(Long flag, Integer status, Integer percentage) {
|
|
|
+ ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(VRedisKeyConstant.EXCEL_FLAG_KEY + flag);
|
|
|
if (ObjectUtil.isNull(excelProcessingProgress) || excelProcessingProgress.getStatus().equals(6)) {
|
|
|
throw new ExcelException("取消导入");
|
|
|
}
|
|
|
|
|
|
excelProcessingProgress.setStatus(status);
|
|
|
excelProcessingProgress.setPercentage(percentage);
|
|
|
- bladeRedis.setEx(flag, excelProcessingProgress, 60L * 60 * 12);
|
|
|
+ bladeRedis.setEx(VRedisKeyConstant.EXCEL_FLAG_KEY + flag, excelProcessingProgress, 60L * 60 * 12);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -174,10 +181,10 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
* @param businessType 业务类型
|
|
|
* @param file 文件
|
|
|
*/
|
|
|
- private void saveLog(String flag, Integer businessType, MultipartFile file) {
|
|
|
+ private void saveLog(Long flag, Integer businessType, MultipartFile file) {
|
|
|
// 上传记录记录数据库
|
|
|
ExcelImportLog excelImportLog = new ExcelImportLog();
|
|
|
- excelImportLog.setFlag(flag);
|
|
|
+ excelImportLog.setId(flag);
|
|
|
excelImportLog.setBusinessType(businessType);
|
|
|
excelImportLog.setStatus(0);
|
|
|
excelImportLog.setFileName(file.getOriginalFilename());
|
|
@@ -191,11 +198,11 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
|
|
|
* @param flag 标记
|
|
|
* @param status 状态
|
|
|
*/
|
|
|
- private void editLog(Long start, String flag, Integer status) {
|
|
|
+ private void editLog(Long start, Long flag, Integer status) {
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
update(q -> q
|
|
|
- .eq(ExcelImportLog::getFlag, flag)
|
|
|
+ .eq(ExcelImportLog::getId, flag)
|
|
|
.set(ExcelImportLog::getStatus, status)
|
|
|
.set(ExcelImportLog::getExecuteTime, (end - start) / 1000)
|
|
|
.set(BaseEntity::getUpdateTime, new Date())
|