jiangping
2025-06-06 a2299a6d4a6f99e9c11132138f5d3e9ec68f03ea
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;
@@ -84,7 +85,12 @@
        ){
             throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        YwContractBill ywContractBill = ywContractBillMapper.selectById(ywContractRevenue.getBillId());
        YwContractBill ywContractBill = ywContractBillMapper.selectJoinOne(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>()
                        .selectAll(YwContractBill.class)
                        .selectAs(YwContract::getStatus, YwContractBill::getContractStatus)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .eq(YwContractBill::getId,ywContractRevenue.getBillId()));
        if(Objects.isNull(ywContractBill)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到账单信息");
        }
@@ -125,7 +131,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,19 +141,39 @@
            }
        }else{
            //获取已支付的总金额 (可能有收入 有支出)
            payTotal = ywContractRevenueList.stream().map(i->i.getActReceivableFee().multiply(
                    BigDecimal.valueOf(Constants.equalsInteger(ywContractRevenue.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.ZERO);
            }else if(waitPayTotal.compareTo(BigDecimal.ZERO)<Constants.ZERO){
                ywContractRevenue.setRevenueType(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);
                //如果待支付金额 大于 0  则是 收入 否则是支出 其他状态 为异常!
                if(waitPayTotal.compareTo(BigDecimal.ZERO)>Constants.ZERO){
                    ywContractRevenue.setRevenueType(Constants.ZERO);
                }else if(waitPayTotal.compareTo(BigDecimal.ZERO)<Constants.ZERO){
                    ywContractRevenue.setRevenueType(Constants.ONE);
                }else{
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"收支金额异常!请联系管理员");
                }
            }else{
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"收支金额异常!请联系管理员");
                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 +193,22 @@
        }
        ywContractRevenueMapper.insert(ywContractRevenue);
        ywContractBillMapper.updateById(ywContractBill);
        //如果账单完结,则查询合同下开启中的账单是否存在退款中 如果不存在则标记合同已退款
        if(Constants.equalsInteger(ywContractBill.getContractStatus(),Constants.THREE)
                && 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()) {
@@ -232,6 +274,7 @@
                new MPJLambdaWrapper<YwContractRevenue>().selectAll(YwContractRevenue.class)
                        .selectAs(YwContractBill::getCode,YwContractRevenue::getBillCode)
                        .selectAs(YwContract::getCode,YwContractRevenue::getContractCode)
                        .selectAs(YwContract::getStatus,YwContractRevenue::getContractStatus)
                        .selectAs(YwCustomer::getName,YwContractRevenue::getCustomerName)
                        .selectAs(SystemUser::getRealname,YwContractRevenue::getRealname)
                        .selectAs(YwAccount::getTitle,YwContractRevenue::getAccountTitle)
@@ -391,6 +434,7 @@
                        .selectAs(YwContractBill::getCode,YwContractRevenue::getBillCode)
                        .selectAs(YwContractBill::getType,YwContractRevenue::getBillType)
                         .selectAs(YwContract::getCode,YwContractRevenue::getContractCode)
                        .selectAs(YwContract::getStatus,YwContractRevenue::getContractStatus)
                        .selectAs(YwCustomer::getName,YwContractRevenue::getCustomerName)
                        .selectAs(SystemUser::getRealname,YwContractRevenue::getRealname)
                        .leftJoin(YwContractBill.class,YwContractBill::getId,YwContractRevenue::getBillId)
@@ -405,7 +449,8 @@
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getRevenueType()),
                                YwContractRevenue::getRevenueType,model.getRevenueType())
                        .ge(Objects.nonNull(model)&&Objects.nonNull(model.getPayDateStart()),YwContractRevenue::getActPayDate, Utils.Date.getStart(model.getPayDateStart()))
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getPayDateEnd()),YwContractRevenue::getActPayDate, Utils.Date.getEnd(model.getPayDateEnd())) )
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getPayDateEnd()),YwContractRevenue::getActPayDate, Utils.Date.getEnd(model.getPayDateEnd()))
                        .orderByDesc(YwContractRevenue::getId))
                ;
        this.dealRoomDetail(iPage.getRecords());