ContractPaymentServiceImpl.java
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package vion.service.impl;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.mapper.ContractPaymentMapper;
import vion.model.Contract;
import vion.model.ContractPayment;
import vion.service.IContractPaymentService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author HlQ
* @date 2023/11/29
*/
@Service
@RequiredArgsConstructor
public class ContractPaymentServiceImpl extends ServiceImpl<ContractPaymentMapper, ContractPayment> implements IContractPaymentService {
@Override
public void calMoney(Contract contract) {
List<ContractPayment> contractPaymentList = this.lambdaQuery().eq(ContractPayment::getContractId, contract.getId()).list();
Map<Integer, BigDecimal> type2RatioMap = contractPaymentList.stream().collect(Collectors.toMap(ContractPayment::getPaymentType, ContractPayment::getPaymentRatio));
Integer status = contract.getStatus();
BigDecimal sumRatio = new BigDecimal(0);
for (int i = 1; i <= status; i++) {
BigDecimal ratio = type2RatioMap.get(i);
NumberUtil.add(ratio, sumRatio);
}
BigDecimal totalAmount = contract.getTotalAmount();
BigDecimal curAmount = NumberUtil.mul(totalAmount, sumRatio);
BigDecimal recAmount = NumberUtil.sub(curAmount, contract.getPaidAmount());
BigDecimal outsideAmount = NumberUtil.sub(totalAmount, recAmount);
contract.setReceivableAmount(recAmount);
contract.setOutstandingAmount(outsideAmount);
}
}