refactor: 修改员工信息导入接口为异步并添加状态查询接口
- 将importData接口改为异步调用,使用CompletableFuture - 添加getImportStatus接口查询导入任务状态 - 添加getImportFailures接口查询导入失败记录(支持分页) - 添加必要的导入:CompletableFuture、ImportResultVO、ImportStatusVO、ImportFailureVO - 保持现有的权限注解@PreAuthorize和日志注解@Log Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,9 @@ import com.ruoyi.ccdi.domain.dto.CcdiEmployeeEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiEmployeeQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiEmployeeExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiEmployeeVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportFailureVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportResultVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.service.ICcdiEmployeeService;
|
||||
import com.ruoyi.ccdi.utils.EasyExcelUtil;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
@@ -25,6 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 员工信息Controller
|
||||
@@ -120,7 +124,7 @@ public class CcdiEmployeeController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入员工信息
|
||||
* 导入员工信息(异步)
|
||||
*/
|
||||
@Operation(summary = "导入员工信息")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:employee:import')")
|
||||
@@ -128,7 +132,54 @@ public class CcdiEmployeeController extends BaseController {
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
||||
List<CcdiEmployeeExcel> list = EasyExcelUtil.importExcel(file.getInputStream(), CcdiEmployeeExcel.class);
|
||||
String message = employeeService.importEmployee(list, updateSupport);
|
||||
return success(message);
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return error("至少需要一条数据");
|
||||
}
|
||||
|
||||
// 异步导入
|
||||
CompletableFuture<ImportResultVO> future = employeeService.importEmployeeAsync(list, updateSupport);
|
||||
|
||||
// 立即返回taskId
|
||||
ImportResultVO result = future.get();
|
||||
|
||||
return success("导入任务已提交,正在后台处理", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入状态
|
||||
*/
|
||||
@Operation(summary = "查询员工导入状态")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:employee:import')")
|
||||
@GetMapping("/importStatus/{taskId}")
|
||||
public AjaxResult getImportStatus(@PathVariable String taskId) {
|
||||
try {
|
||||
ImportStatusVO status = employeeService.getImportStatus(taskId);
|
||||
return success(status);
|
||||
} catch (Exception e) {
|
||||
return error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入失败记录
|
||||
*/
|
||||
@Operation(summary = "查询导入失败记录")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:employee:import')")
|
||||
@GetMapping("/importFailures/{taskId}")
|
||||
public TableDataInfo getImportFailures(
|
||||
@PathVariable String taskId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
|
||||
List<ImportFailureVO> failures = employeeService.getImportFailures(taskId);
|
||||
|
||||
// 手动分页
|
||||
int fromIndex = (pageNum - 1) * pageSize;
|
||||
int toIndex = Math.min(fromIndex + pageSize, failures.size());
|
||||
|
||||
List<ImportFailureVO> pageData = failures.subList(fromIndex, toIndex);
|
||||
|
||||
return getDataTable(pageData, failures.size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user