wujianwei
2025-08-13 8ad0d1ebdd0d9eab8b706901e3304cbb1b439c30
service/src/main/java/com/ruoyi/cwgl/service/impl/EstimatedReceivableBillServiceImpl.java
@@ -1,9 +1,15 @@
package com.ruoyi.cwgl.service.impl;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.cwgl.domain.EstimatedReceivableBillLog;
import com.ruoyi.cwgl.service.IEstimatedReceivableBillLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Async;
@@ -33,6 +39,8 @@
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private EstimatedReceivableBillMapper estimatedReceivableBillMapper;
    @Autowired
    private IEstimatedReceivableBillLogService logService;
    /**
@@ -179,4 +187,33 @@
    {
        return estimatedReceivableBillMapper.deleteEstimatedReceivableBillById(id);
    }
    @Override
    public int settlement(EstimatedReceivableBill estimatedReceivableBill) {
        Integer id = estimatedReceivableBill.getId();
        EstimatedReceivableBill oldData = estimatedReceivableBillMapper.selectEstimatedReceivableBillById(id);
        //应结算金额
        Long totalAmount = oldData.getTotalAmount()==null?0L:oldData.getTotalAmount();
        //已结算金额
        Long settledAmount = oldData.getSettledAmount()==null?0L:oldData.getSettledAmount();
        //当前提交金额
        Long settlementAmount = estimatedReceivableBill.getSettlementAmount();
        EstimatedReceivableBillLog estimatedReceivableBillLog = new EstimatedReceivableBillLog();
        estimatedReceivableBill.setSettledAmount(settlementAmount);
        estimatedReceivableBillLog.setCreateTime(new Date());
        estimatedReceivableBillLog.setBillId(estimatedReceivableBill.getId());
        estimatedReceivableBillLog.setCreateBy(SecurityUtils.getUsername());
        estimatedReceivableBillLog.setOperation("本次提交金额"+ settlementAmount);
        logService.insertEstimatedReceivableBillLog(estimatedReceivableBillLog);
        settledAmount = settledAmount+settlementAmount;
        if (settledAmount>totalAmount){
            //已结算大于应计算金额为已结算
            estimatedReceivableBill.setStatus(2);
        }else {
            //否则部分结算
            estimatedReceivableBill.setStatus(1);
        }
        return estimatedReceivableBillMapper.updateEstimatedReceivableBill(estimatedReceivableBill);
    }
}