jiangping
2024-12-05 16217be9c85f95cb236e639da6e546bb38cdc53d
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractRevenueServiceImpl.java
@@ -24,6 +24,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -125,7 +126,7 @@
        BigDecimal waitPayTotal = BigDecimal.ZERO;
        //无付款记录 则为初次支付 根据账单类型 判断是支出 / 收入
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractRevenueList)){
            ywContractRevenue.setRevenueType(ywContractBill.getType());
            ywContractRevenue.setRevenueType(ywContractBill.getBillType());
            if(ywContractRevenue.getActReceivableFee().compareTo(ywContractBill.getReceivableFee())>Constants.ZERO){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请输入正确的金额!");
            }else  if(ywContractRevenue.getActReceivableFee().compareTo(ywContractBill.getReceivableFee())==Constants.ZERO){
@@ -135,8 +136,10 @@
            }
        }else{
            //获取已支付的总金额 (可能有收入 有支出)
            payTotal = ywContractRevenueList.stream().map(i->i.getActReceivableFee().multiply(
                    BigDecimal.valueOf(Constants.equalsInteger(ywContractRevenue.getRevenueType(),Constants.ZERO)?Constants.ONE:-Constants.ONE))
            if(Constants.equalsInteger(ywContractBill.getBillType(),Constants.ZERO)){
                payTotal = ywContractRevenueList.stream().map(i->
                        i.getActReceivableFee().multiply(
                                BigDecimal.valueOf(Constants.equalsInteger(i.getRevenueType(),Constants.ZERO)?Constants.ONE:-Constants.ONE))
            ).reduce(BigDecimal.ZERO,BigDecimal::add);
            //获取待支付款金额 如果账单类型为支出 或 (账单类型为收入 且 待支付金额 小于 0) 则为支付
            waitPayTotal = ywContractBill.getReceivableFee().subtract(payTotal);
@@ -148,6 +151,24 @@
            }else{
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"收支金额异常!请联系管理员");
            }
            }else{
                payTotal = ywContractRevenueList.stream().map(i->
                        i.getActReceivableFee().multiply(
                                BigDecimal.valueOf(Constants.equalsInteger(i.getRevenueType(),Constants.ZERO)?-Constants.ONE:Constants.ONE))
                ).reduce(BigDecimal.ZERO,BigDecimal::add);
                //获取待支付款金额 如果账单类型为支出 或 (账单类型为收入 且 待支付金额 小于 0) 则为支付
                waitPayTotal = ywContractBill.getReceivableFee().subtract(payTotal);
                //如果待支付金额 大于 0  则是 收入 否则是支出 其他状态 为异常!
                if(waitPayTotal.compareTo(BigDecimal.ZERO)>Constants.ZERO){
                    ywContractRevenue.setRevenueType(Constants.ONE);
                }else if(waitPayTotal.compareTo(BigDecimal.ZERO)<Constants.ZERO){
                    ywContractRevenue.setRevenueType(Constants.ZERO);
                }else{
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"收支金额异常!请联系管理员");
                }
            }
            //待支付的流水 如果为收入 则比对 金额值  如果是支出 则获取绝对值 进行对比
            if(Constants.equalsInteger(ywContractRevenue.getRevenueType(),Constants.ZERO)){
                //如果支付金额 大于 待支付金额 则提示异常 如果支付金额小于 待支付金额 则状态不变化 其他状态 异常
@@ -167,6 +188,21 @@
        }
        ywContractRevenueMapper.insert(ywContractRevenue);
        ywContractBillMapper.updateById(ywContractBill);
        //如果账单完结,则查询合同下开启中的账单是否存在退款中 如果不存在则标记合同已退款
        if(Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ONE)){
            if( ywContractBillMapper
                    .selectCount(new QueryWrapper<YwContractBill>().lambda().eq(YwContractBill::getContractId,ywContractBill.getContractId())
                            .ne(YwContractBill::getId,ywContractBill.getId())
                    .eq(YwContractBill::getStatus,Constants.ZERO)
                                    .in(YwContractBill::getPayStatus,Constants.ZERO,Constants.FOUR, Constants.TWO,Constants.THREE)
                    ) == Constants.ZERO){
                ywContractMapper.update(new UpdateWrapper<YwContract>().lambda()
                        .set(YwContract::getStatus,Constants.FOUR)
                        .set(YwContract::getEditDate,DateUtil.getCurrDateTime())
                        .eq(YwContract::getId,ywContractBill.getContractId())
                );
            }
        }
        //存储附件信息
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRevenue.getMultifileList())){
            for (Multifile multifile:ywContractRevenue.getMultifileList()) {