feat: 添加采购交易Service实现类
This commit is contained in:
@@ -0,0 +1,166 @@
|
|||||||
|
package com.ruoyi.ccdi.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.ccdi.domain.CcdiPurchaseTransaction;
|
||||||
|
import com.ruoyi.ccdi.domain.dto.CcdiPurchaseTransactionAddDTO;
|
||||||
|
import com.ruoyi.ccdi.domain.dto.CcdiPurchaseTransactionEditDTO;
|
||||||
|
import com.ruoyi.ccdi.domain.dto.CcdiPurchaseTransactionQueryDTO;
|
||||||
|
import com.ruoyi.ccdi.domain.excel.CcdiPurchaseTransactionExcel;
|
||||||
|
import com.ruoyi.ccdi.domain.vo.CcdiPurchaseTransactionVO;
|
||||||
|
import com.ruoyi.ccdi.mapper.CcdiPurchaseTransactionMapper;
|
||||||
|
import com.ruoyi.ccdi.service.ICcdiPurchaseTransactionImportService;
|
||||||
|
import com.ruoyi.ccdi.service.ICcdiPurchaseTransactionService;
|
||||||
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购交易信息 服务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2026-02-06
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CcdiPurchaseTransactionServiceImpl implements ICcdiPurchaseTransactionService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CcdiPurchaseTransactionMapper transactionMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ICcdiPurchaseTransactionImportService transactionImportService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询采购交易列表
|
||||||
|
*
|
||||||
|
* @param queryDTO 查询条件
|
||||||
|
* @return 采购交易VO集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public java.util.List<CcdiPurchaseTransactionVO> selectTransactionList(CcdiPurchaseTransactionQueryDTO queryDTO) {
|
||||||
|
Page<CcdiPurchaseTransactionVO> page = new Page<>(1, Integer.MAX_VALUE);
|
||||||
|
Page<CcdiPurchaseTransactionVO> resultPage = transactionMapper.selectTransactionPage(page, queryDTO);
|
||||||
|
return resultPage.getRecords();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询采购交易列表
|
||||||
|
*
|
||||||
|
* @param page 分页对象
|
||||||
|
* @param queryDTO 查询条件
|
||||||
|
* @return 采购交易VO分页结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<CcdiPurchaseTransactionVO> selectTransactionPage(Page<CcdiPurchaseTransactionVO> page, CcdiPurchaseTransactionQueryDTO queryDTO) {
|
||||||
|
return transactionMapper.selectTransactionPage(page, queryDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询采购交易列表(用于导出)
|
||||||
|
*
|
||||||
|
* @param queryDTO 查询条件
|
||||||
|
* @return 采购交易Excel实体集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public java.util.List<CcdiPurchaseTransactionExcel> selectTransactionListForExport(CcdiPurchaseTransactionQueryDTO queryDTO) {
|
||||||
|
Page<CcdiPurchaseTransactionVO> page = new Page<>(1, Integer.MAX_VALUE);
|
||||||
|
Page<CcdiPurchaseTransactionVO> resultPage = transactionMapper.selectTransactionPage(page, queryDTO);
|
||||||
|
|
||||||
|
return resultPage.getRecords().stream().map(vo -> {
|
||||||
|
CcdiPurchaseTransactionExcel excel = new CcdiPurchaseTransactionExcel();
|
||||||
|
BeanUtils.copyProperties(vo, excel);
|
||||||
|
return excel;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询采购交易详情
|
||||||
|
*
|
||||||
|
* @param purchaseId 采购事项ID
|
||||||
|
* @return 采购交易VO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CcdiPurchaseTransactionVO selectTransactionById(String purchaseId) {
|
||||||
|
return transactionMapper.selectTransactionById(purchaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增采购交易
|
||||||
|
*
|
||||||
|
* @param addDTO 新增DTO
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public int insertTransaction(CcdiPurchaseTransactionAddDTO addDTO) {
|
||||||
|
// 检查采购事项ID唯一性
|
||||||
|
if (transactionMapper.selectById(addDTO.getPurchaseId()) != null) {
|
||||||
|
throw new RuntimeException("该采购事项ID已存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
CcdiPurchaseTransaction transaction = new CcdiPurchaseTransaction();
|
||||||
|
BeanUtils.copyProperties(addDTO, transaction);
|
||||||
|
int result = transactionMapper.insert(transaction);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改采购交易
|
||||||
|
*
|
||||||
|
* @param editDTO 编辑DTO
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public int updateTransaction(CcdiPurchaseTransactionEditDTO editDTO) {
|
||||||
|
CcdiPurchaseTransaction transaction = new CcdiPurchaseTransaction();
|
||||||
|
BeanUtils.copyProperties(editDTO, transaction);
|
||||||
|
int result = transactionMapper.updateById(transaction);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除采购交易
|
||||||
|
*
|
||||||
|
* @param purchaseIds 需要删除的采购事项ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public int deleteTransactionByIds(String[] purchaseIds) {
|
||||||
|
return transactionMapper.deleteBatchIds(java.util.List.of(purchaseIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入采购交易数据(异步)
|
||||||
|
*
|
||||||
|
* @param excelList Excel实体列表
|
||||||
|
* @param isUpdateSupport 是否更新支持,true-存在则更新,false-存在则跳过
|
||||||
|
* @return 任务ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public String importTransaction(java.util.List<CcdiPurchaseTransactionExcel> excelList, Boolean isUpdateSupport) {
|
||||||
|
if (StringUtils.isNull(excelList) || excelList.isEmpty()) {
|
||||||
|
throw new RuntimeException("至少需要一条数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成任务ID
|
||||||
|
String taskId = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
// 获取当前用户名
|
||||||
|
String userName = SecurityUtils.getUsername();
|
||||||
|
|
||||||
|
// 调用异步导入服务
|
||||||
|
transactionImportService.importTransactionAsync(excelList, isUpdateSupport, taskId, userName);
|
||||||
|
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user