liyong
2026-04-23 f2e783ca6e47761e7daadbac193cf80474d35edd
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -13,7 +13,7 @@
import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.approve.pojo.ApproveProcess;
import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
import com.ruoyi.approve.vo.ApproveProcessVO;
import com.ruoyi.approve.bean.vo.ApproveProcessVO;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.mapper.SupplierManageMapper;
@@ -55,6 +55,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
@@ -84,52 +85,71 @@
 * @date 2025-05-09
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService {
    private final AccountExpenseService accountExpenseService;
    private final PurchaseLedgerMapper purchaseLedgerMapper;
    @Autowired
    private  AccountExpenseService accountExpenseService;
    @Autowired
    private  PurchaseLedgerMapper purchaseLedgerMapper;
    private final SalesLedgerMapper salesLedgerMapper;
    private final SalesLedgerProductMapper salesLedgerProductMapper;
    @Autowired
    private  SalesLedgerMapper salesLedgerMapper;
    @Autowired
    private  SalesLedgerProductMapper salesLedgerProductMapper;
    private final SysUserMapper userMapper;
    @Autowired
    private  SysUserMapper userMapper;
    private final TempFileMapper tempFileMapper;
    @Autowired
    private  TempFileMapper tempFileMapper;
    private final CommonFileMapper commonFileMapper;
    @Autowired
    private  CommonFileMapper commonFileMapper;
    private final SupplierManageMapper supplierManageMapper;
    @Autowired
    private  SupplierManageMapper supplierManageMapper;
    private final ProductMapper productMapper;
    @Autowired
    private  ProductMapper productMapper;
    private final ProductModelMapper productModelMapper;
    @Autowired
    private  ProductModelMapper productModelMapper;
    private final SysUserMapper sysUserMapper;
    @Autowired
    private  SysUserMapper sysUserMapper;
    private final TicketRegistrationMapper ticketRegistrationMapper;
    @Autowired
    private  TicketRegistrationMapper ticketRegistrationMapper;
    private final ProductRecordMapper productRecordMapper;
    @Autowired
    private  ProductRecordMapper productRecordMapper;
    private final PaymentRegistrationMapper paymentRegistrationMapper;
    private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
    private final StringRedisTemplate redisTemplate;
    private final QualityInspectMapper qualityInspectMapper;
    private final CommonFileServiceImpl commonFileService;
    private final QualityTestStandardBindingMapper qualityTestStandardBindingMapper;
    private final QualityTestStandardParamMapper qualityTestStandardParamMapper;
    private final QualityTestStandardMapper qualityTestStandardMapper;
    private final QualityInspectParamMapper qualityInspectParamMapper;
    private final ApproveProcessServiceImpl approveProcessService;
    private final ProcurementRecordMapper procurementRecordStorageMapper;
    private final PurchaseLedgerTemplateMapper purchaseLedgerTemplateMapper;
    private final SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper;
    @Autowired
    private  PaymentRegistrationMapper paymentRegistrationMapper;
    @Autowired
    private  InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
    @Autowired
    private  StringRedisTemplate redisTemplate;
    @Autowired
    private  QualityInspectMapper qualityInspectMapper;
    @Autowired
    private  CommonFileServiceImpl commonFileService;
    @Autowired
    private  QualityTestStandardBindingMapper qualityTestStandardBindingMapper;
    @Autowired
    private  QualityTestStandardParamMapper qualityTestStandardParamMapper;
    @Autowired
    private  QualityTestStandardMapper qualityTestStandardMapper;
    @Autowired
    private  QualityInspectParamMapper qualityInspectParamMapper;
    @Autowired
    private  ApproveProcessServiceImpl approveProcessService;
    @Autowired
    private  ProcurementRecordMapper procurementRecordStorageMapper;
    @Autowired
    private  PurchaseLedgerTemplateMapper purchaseLedgerTemplateMapper;
    @Autowired
    private  SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper;
    @Value("${file.upload-dir}")
    private String uploadDir;
@@ -139,21 +159,35 @@
        if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) {
            queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber());
        }
        if(purchaseLedger.getSupplierId()!=null){
            queryWrapper.eq(PurchaseLedger::getSupplierId, purchaseLedger.getSupplierId());
        }
        if (purchaseLedger.getApprovalStatus() != null) {
            queryWrapper.eq(PurchaseLedger::getApprovalStatus, purchaseLedger.getApprovalStatus());
        }
        return purchaseLedgerMapper.selectList(queryWrapper);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws Exception {
        PurchaseLedger purchaseLedger = new PurchaseLedger();
        SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
        //录入人
        SysUser sysUser = userMapper.selectUserById(purchaseLedgerDto.getRecorderId());
        if (ObjectUtils.isNotEmpty(sysUser)) {
            purchaseLedger.setRecorderName(sysUser.getNickName());
            purchaseLedger.setPhoneNumber(sysUser.getPhonenumber());
        }else {
            purchaseLedger.setRecorderName(SecurityUtils.getLoginUser().getNickName());
            SysUser sysUser1 = userMapper.selectUserById(SecurityUtils.getUserId());
            purchaseLedger.setPhoneNumber(sysUser1.getPhonenumber());
        }
        SupplierManage supplierManage = supplierManageMapper.selectById(purchaseLedgerDto.getSupplierId());
        // DTO转Entity
        PurchaseLedger purchaseLedger = new PurchaseLedger();
        BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) {
@@ -163,8 +197,7 @@
        purchaseLedger.setSalesLedgerId(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getId() : -1);
        purchaseLedger.setSupplierName(supplierManage.getSupplierName());
        purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId());
        purchaseLedger.setRecorderName(sysUser.getNickName());
        purchaseLedger.setPhoneNumber(sysUser.getPhonenumber());
        purchaseLedger.setApprovalStatus(1);
        // 3. 新增或更新主表
        if (purchaseLedger.getId() == null) {
@@ -189,15 +222,15 @@
        if (productList != null && !productList.isEmpty()) {
            handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType());
        }
        //新增原材料检验
        if (productList != null) {
            for (SalesLedgerProduct saleProduct : productList) {
                //是否推送质检,如果true就添加
                if (saleProduct.getIsChecked()) {
                    addQualityInspect(purchaseLedger, saleProduct);
                }
            }
        }
        //新增原材料检验  审批之后才生成检验
//        if (productList != null) {
//            for (SalesLedgerProduct saleProduct : productList) {
//                //是否推送质检,如果true就添加
//                if (saleProduct.getIsChecked()) {
//                    addQualityInspect(purchaseLedger, saleProduct);
//                }
//            }
//        }
        // 5. 迁移临时文件到正式目录
        if (purchaseLedgerDto.getTempFileIds() != null && !purchaseLedgerDto.getTempFileIds().isEmpty()) {
            migrateTempFilesToFormal(purchaseLedger.getId(), purchaseLedgerDto.getTempFileIds());