wujianwei
2025-08-15 252905374177e0d8d98430cb33cf79840479a3fe
service/src/main/java/com/ruoyi/cwgl/service/impl/EstimatedReceivableServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.cwgl.service.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@@ -7,9 +8,13 @@
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import com.ruoyi.common.utils.RandomUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.cwgl.domain.EstimatedReceivableBill;
import com.ruoyi.cwgl.domain.PendingSettlementBusiness;
import com.ruoyi.cwgl.mapper.EstimatedReceivableBillMapper;
import com.ruoyi.cwgl.mapper.EstimatedReceivableLogMapper;
import com.ruoyi.cwgl.mapper.PendingSettlementBusinessMapper;
import com.ruoyi.cwgl.service.IEstimatedReceivableLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@@ -43,6 +48,10 @@
    private EstimatedReceivableMapper estimatedReceivableMapper;
    @Autowired
    private IEstimatedReceivableLogService logService;
    @Resource
    private PendingSettlementBusinessMapper pendingSettlementBusinessMapper;
    @Resource
    private EstimatedReceivableBillMapper estimatedReceivableBillMapper;
    /**
     * 查询预估应收管理
@@ -111,7 +120,13 @@
    @Override
    public int insertEstimatedReceivable(EstimatedReceivable estimatedReceivable)
    {
        estimatedReceivable.setCreateTime(DateUtils.getNowDate());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
        Date nowDate = DateUtils.getNowDate();
        String datePart = dateFormat.format(nowDate);
        estimatedReceivable.setCreateTime(nowDate);
        estimatedReceivable.setFeeSystemNo("YF"+datePart+ RandomUtils.random(5));
        estimatedReceivable.setFeeType(0);
        return estimatedReceivableMapper.insertEstimatedReceivable(estimatedReceivable);
    }
@@ -142,6 +157,24 @@
        if (estimatedReceivable1.getRelatedBillStatus().equals(2)||estimatedReceivable1.getRelatedBillStatus().equals(3)){
            throw new ServiceException("结算中或已结算无法修改");
        }
        //原本金额
        Long oldAmount = estimatedReceivable1.getEstimatedAmount();
        //新金额
        Long newAmount = estimatedReceivable.getEstimatedAmount();
        if (!oldAmount.equals(newAmount)) {
              PendingSettlementBusiness pendingSettlementBusiness = pendingSettlementBusinessMapper.selectPendingSettlementBusinessByNo(estimatedReceivable.getDispatchNo());
              if (pendingSettlementBusiness!=null) {
                  Long estimatedTotalIncome = pendingSettlementBusiness.getEstimatedTotalIncome();
                  pendingSettlementBusiness.setEstimatedTotalIncome(estimatedTotalIncome-oldAmount+newAmount);
                  pendingSettlementBusinessMapper.updatePendingSettlementBusiness(pendingSettlementBusiness);
                  if (pendingSettlementBusiness.getBillId() != null) {
                      EstimatedReceivableBill estimatedReceivableBill = estimatedReceivableBillMapper.selectEstimatedReceivableBillById(pendingSettlementBusiness.getBillId());
                            estimatedReceivableBill.setTotalAmount(estimatedReceivableBill.getTotalAmount() -oldAmount + newAmount);
                            estimatedReceivableBillMapper.updateEstimatedReceivableBill(estimatedReceivableBill);
                  }
              }
        }
        estimatedReceivable.setUpdateTime(DateUtils.getNowDate());
        String username = SecurityUtils.getUsername();
        logService.insertEstimatedReceivableLog("修改应收",estimatedReceivable.getId(),username);