ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 一、概述 导入的数据量特别大的时候,系统需要消耗大量计算时间的情况下,可以采用异步导入数据的方案来提升用户体验; 平台提供了完整的解决方案来实现异步导入机制; ## 二、方案 参考异步任务的技术特性:[后端框架/SprigBoot/核心技术/异步任务](../../../%E5%90%8E%E7%AB%AF%E6%A1%86%E6%9E%B6/SprigBoot/%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF/%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1.md) 导入的业务代码: ``` @RayServiceMethod @Transactional public ResponseObject importCandidate(String excelBase64) throws Exception { importCandidateCardAction.importAction(model, asynOrderExecutor.startImportOrder("", excelBase64, model)); return responseObj; } ``` ``` @Component public class ImportCandidateCardAction extends BaseAsynAction { @Autowired private CardInfoCandidateDao cardInfoCandidateDao; @Async public void importAction(RayModel model, SysAsynOrder sysAsynOrder) throws Exception { Workbook wb = Base64Util.getWorkbookByBase64(Base64Util.trimHeadFromFront(sysAsynOrderFileDao.findByOrderId(sysAsynOrder.getOrderId()))); Sheet sheet = wb.getSheetAt(0); for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) { //省略业务逻辑 } asynOrderExecutor.completeImportOrder(sysAsynOrder, "完成", AsynOrderStatus.EXECUTED_SUCCESS); } } ``` 这样,就实现了异步导入,在导入订单列表(PC版首页右上角)里面,即可查看导入文件的执行情况,如果执行完成,即可看到执行结果;