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;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.ruoyi.common.utils.PageUtils;
|
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.annotation.DataSource;
|
import com.ruoyi.common.enums.DataSourceType;
|
import com.ruoyi.common.core.service.BaseService;
|
|
import com.ruoyi.cwgl.mapper.FundFlowMapper;
|
import com.ruoyi.cwgl.domain.FundFlow;
|
import com.ruoyi.cwgl.domain.FundFlowLog;
|
import com.ruoyi.cwgl.service.IFundFlowService;
|
import com.ruoyi.cwgl.service.IFundFlowLogService;
|
import com.ruoyi.common.core.text.Convert;
|
|
/**
|
* 资金流水Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2026-01-12
|
*/
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class FundFlowServiceImpl extends BaseService<FundFlowMapper, FundFlow> implements IFundFlowService
|
{
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
@Resource
|
private FundFlowMapper fundFlowMapper;
|
@Resource
|
private IFundFlowLogService fundFlowLogService;
|
@Autowired
|
private RedisCache redisCache;
|
|
|
/**
|
* 查询资金流水
|
*
|
* @param id 资金流水ID
|
* @return 资金流水
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public FundFlow selectFundFlowById(Integer id)
|
{
|
return fundFlowMapper.selectFundFlowById(id);
|
}
|
|
/**
|
* 查询资金流水 记录数
|
*
|
* @param fundFlow 资金流水
|
* @return 资金流水集合
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public int selectFundFlowCount(FundFlow fundFlow)
|
{
|
return fundFlowMapper.selectFundFlowCount(fundFlow);
|
}
|
|
/**
|
* 查询资金流水列表
|
*
|
* @param fundFlow 资金流水
|
* @return 资金流水
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public List<FundFlow> selectFundFlowList(FundFlow fundFlow)
|
{
|
return fundFlowMapper.selectFundFlowList(fundFlow);
|
}
|
|
/**
|
* 查询资金流水列表 异步 导出
|
*
|
* @param fundFlow 资金流水
|
* @param exportKey 导出功能的唯一标识
|
* @return 资金流水集合
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Async
|
@Override
|
public void export(FundFlow fundFlow,String exportKey) {
|
|
super.export(FundFlow.class,exportKey,"fundFlowData",(pageNum)->{
|
PageUtils.startPage(pageNum, Constants.EXPORT_PATE_SIZE);
|
return selectFundFlowList(fundFlow);
|
});
|
}
|
|
|
/**
|
* 新增资金流水
|
*
|
* @param fundFlow 资金流水
|
* @return 结果
|
*/
|
@Override
|
public int insertFundFlow(FundFlow fundFlow)
|
{
|
fundFlow.setCreateTime(DateUtils.getNowDate());
|
int result = fundFlowMapper.insertFundFlow(fundFlow);
|
|
// 记录操作日志
|
if (result > 0) {
|
FundFlowLog log = new FundFlowLog();
|
log.setFlowId(fundFlow.getId());
|
log.setOperation("新增资金流水,流水号:" + fundFlow.getBankFlowNo());
|
fundFlowLogService.insertFundFlowLog(log);
|
}
|
|
return result;
|
}
|
|
/**
|
* 新增资金流水[批量]
|
*
|
* @param fundFlows 资金流水
|
* @return 结果
|
*/
|
@Override
|
public int insertFundFlowBatch(List<FundFlow> fundFlows)
|
{
|
int rows = fundFlowMapper.insertFundFlowBatch(fundFlows);
|
return rows;
|
}
|
|
/**
|
* 修改资金流水
|
*
|
* @param fundFlow 资金流水
|
* @return 结果
|
*/
|
@Override
|
public int updateFundFlow(FundFlow fundFlow)
|
{
|
fundFlow.setUpdateTime(DateUtils.getNowDate());
|
int result = fundFlowMapper.updateFundFlow(fundFlow);
|
|
// 记录操作日志
|
if (result > 0) {
|
FundFlowLog log = new FundFlowLog();
|
log.setFlowId(fundFlow.getId());
|
log.setOperation("修改资金流水,流水号:" + fundFlow.getBankFlowNo());
|
fundFlowLogService.insertFundFlowLog(log);
|
}
|
|
return result;
|
}
|
|
/**
|
* 修改资金流水[批量]
|
*
|
* @param fundFlows 资金流水
|
* @return 结果
|
*/
|
@Override
|
public int updateFundFlowBatch(List<FundFlow> fundFlows){
|
return fundFlowMapper.updateFundFlowBatch(fundFlows);
|
}
|
|
/**
|
* 删除资金流水对象
|
*
|
* @param ids 需要删除的数据ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteFundFlowByIds(String ids)
|
{
|
return deleteFundFlowByIds(Convert.toIntArray(ids));
|
}
|
|
/**
|
* 删除资金流水对象
|
*
|
*
|
* @param ids 需要删除的数据ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteFundFlowByIds(Integer[] ids)
|
{
|
return fundFlowMapper.deleteFundFlowByIds(ids);
|
}
|
|
/**
|
* 删除资金流水信息
|
*
|
* @param id 资金流水ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteFundFlowById(Integer id)
|
{
|
return fundFlowMapper.deleteFundFlowById(id);
|
}
|
|
/**
|
* 确认资金流水(将状态改为待认领)
|
*
|
* @param id 资金流水ID
|
* @return 结果
|
*/
|
@Override
|
public int confirmFundFlow(Integer id)
|
{
|
// 先查询资金流水信息
|
FundFlow fundFlow = fundFlowMapper.selectFundFlowById(id);
|
if (fundFlow == null) {
|
throw new RuntimeException("资金流水不存在");
|
}
|
|
// 判断状态是否为0(正常)才能确认
|
if (!"0".equals(fundFlow.getStatus())) {
|
throw new RuntimeException("只有状态为草稿的资金流水才能确认");
|
}
|
|
// 将状态改为"1"(待认领)
|
fundFlow.setStatus("1");
|
int result = fundFlowMapper.updateFundFlow(fundFlow);
|
|
// 记录操作日志
|
if (result > 0) {
|
FundFlowLog log = new FundFlowLog();
|
log.setFlowId(id);
|
log.setOperation("确认资金流水,流水号:" + fundFlow.getBankFlowNo() + ",状态从草稿改为待认领");
|
fundFlowLogService.insertFundFlowLog(log);
|
}
|
|
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;
|
}
|
}
|
}
|