| | |
| | | package com.ruoyi.cwgl.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.file.DownloadExportUtil; |
| | | import com.ruoyi.common.utils.file.DownloadExportUtil.ExprotStatus; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.scheduling.annotation.Async; |
| | |
| | | private FundFlowMapper fundFlowMapper; |
| | | @Resource |
| | | private IFundFlowLogService fundFlowLogService; |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 导入资金流水数据 |
| | | * |
| | | * @param fundFlowList 资金流水数据列表 |
| | | * @return 导入结果 |
| | | */ |
| | | @Override |
| | | public String importFundFlow(List<FundFlow> fundFlowList ) |
| | | { |
| | | if (fundFlowList == null || fundFlowList.isEmpty()) { |
| | | throw new RuntimeException("导入资金流水数据不能为空"); |
| | | } |
| | | |
| | | int successNum = 0; |
| | | int failureNum = 0; |
| | | StringBuilder successMsg = new StringBuilder(); |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | |
| | | for (FundFlow fundFlow : fundFlowList) { |
| | | try { |
| | | |
| | | |
| | | // 新增 |
| | | fundFlow.setCreateTime(DateUtils.getNowDate()); |
| | | int result = fundFlowMapper.insertFundFlow(fundFlow); |
| | | if (result > 0) { |
| | | successNum++; |
| | | // 记录操作日志 |
| | | FundFlowLog log = new FundFlowLog(); |
| | | log.setFlowId(fundFlow.getId()); |
| | | log.setOperation("导入资金流水,流水号:" + fundFlow.getBankFlowNo()); |
| | | fundFlowLogService.insertFundFlowLog(log); |
| | | } else { |
| | | failureNum++; |
| | | failureMsg.append("、").append(fundFlow.getBankFlowNo()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | failureNum++; |
| | | failureMsg.append("、").append(fundFlow.getBankFlowNo()); |
| | | logger.error("导入资金流水 {} 失败:{}", fundFlow.getBankFlowNo(), e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | if (failureNum > 0) { |
| | | failureMsg.insert(0, "失败的流水号:"); |
| | | } |
| | | |
| | | successMsg.append("成功导入 " + successNum + " 条资金流水数据"); |
| | | if (failureNum > 0) { |
| | | successMsg.append("," + failureMsg); |
| | | } |
| | | |
| | | return successMsg.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 导入资金流水模板 |
| | | * |
| | | * @param exportKey 导出功能的唯一标识 |
| | | */ |
| | | @DataSource(DataSourceType.SLAVE) |
| | | @Async |
| | | @Override |
| | | public void importTemplate(String exportKey) { |
| | | String fileName = ExcelUtil.encodeFileName("资金流水导入模板"); |
| | | |
| | | // 设置当前任务为"下载中"状态 |
| | | DownloadExportUtil.deleteDownloadFile(redisCache, exportKey, ExprotStatus.XZZ.getStatus()); |
| | | |
| | | try { |
| | | // 创建空列表用于生成模板(只需要表头) |
| | | List<FundFlow> fundFlowList = new ArrayList<>(); |
| | | |
| | | // 使用export方法创建模板 |
| | | export(FundFlow.class, exportKey, fileName, (pageNum) -> { |
| | | return fundFlowList; |
| | | }); |
| | | |
| | | logger.info("导入模板导出完成: {}, file: {}", exportKey, fileName); |
| | | } catch (Exception e) { |
| | | logger.error("导入模板导出失败: {}, error: {}", exportKey, e.getMessage(), e); |
| | | DownloadExportUtil.deleteDownloadFile(redisCache, exportKey, ExprotStatus.XZYC.getStatus()); |
| | | throw e; |
| | | } |
| | | } |
| | | } |