renkang
2025-01-09 cdf974d19bab00ac22fe2896eb34b920d58d74a6
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractBillServiceImpl.java
@@ -10,6 +10,7 @@
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.YwContractBillDataVO;
import com.doumee.dao.system.MultifileMapper;
import com.doumee.dao.system.model.Multifile;
import com.doumee.dao.system.model.SystemUser;
@@ -20,6 +21,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.util.CollectionUtils;
@@ -193,6 +195,7 @@
                        .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                        .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                        .selectAs(Company::getId,YwContractBill::getCompanyId)
                        .selectAs(Company::getName,YwContractBill::getCompanyName)
                        .selectAs(SystemUser::getRealname,YwContractBill::getRealname)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
@@ -209,7 +212,8 @@
        );
        //房源数据
        ywContractBill.setYwContractRoomList(ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
        ywContractBill.setYwContractRoomList(
                ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
                .selectAll(YwContractRoom.class)
                .selectAs(YwProject::getName,YwRoom::getProjectName)
                .selectAs(YwFloor::getName,YwRoom::getFloorName)
@@ -222,8 +226,8 @@
                .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ONE),YwContractRoom::getContractId,id)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ONE),YwContractRoom::getType,Constants.ONE)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO),YwContractRoom::getContractId,ywContractBill.getContractId())
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO),YwContractRoom::getType,Constants.ZERO)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO) || Constants.equalsInteger(ywContractBill.getType(),Constants.TWO),YwContractRoom::getContractId,ywContractBill.getContractId())
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO)| Constants.equalsInteger(ywContractBill.getType(),Constants.TWO),YwContractRoom::getType,Constants.ZERO)
        ));
        //收支记录
@@ -280,7 +284,6 @@
        YwContractBill model = pageWrap.getModel();
        IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
            queryWrapper.selectAll(YwContractBill.class)
//                    .select(" ( select ifnull(sum(case when yw.REVENUE_TYPE = 0 then yw.ACT_RECEIVABLE_FEE  else  -yw.ACT_RECEIVABLE_FEE end),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                    .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                    .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                    .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
@@ -391,9 +394,9 @@
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
                for (YwContractBill ywContractBill:ywContractBillList) {
                    if(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO)){
                    if(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO) || Constants.equalsInteger(ywContractBill.getType(),Constants.TWO)){
                        ywContractBill.setYwContractRoomList(
                                ywContractRoomList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)&&Constants.equalsInteger(i.getContractId(),ywContractBill.getContractId())).collect(Collectors.toList())
                                ywContractRoomList.stream().filter(i->(Constants.equalsInteger(i.getType(),Constants.TWO)||Constants.equalsInteger(i.getType(),Constants.ZERO))&&Constants.equalsInteger(i.getContractId(),ywContractBill.getContractId())).collect(Collectors.toList())
                        );
                    }else{
                        ywContractBill.setYwContractRoomList(
@@ -432,7 +435,7 @@
                for (String codeDate:codeDateSet) {
                    //获取当前日期的数据
                    List<YwContractBill> codeDateBillList =
                            ywContractBillList.stream().filter(i->i.getCodeDate().equals(codeDate)).collect(Collectors.toList());
                            ywContractBillList.stream().filter(i->StringUtils.isNotBlank(i.getCodeDate()) && i.getCodeDate().equals(codeDate)).collect(Collectors.toList());
                    if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(codeDateBillList)){
                        continue;
                    }
@@ -484,4 +487,59 @@
        return list;
    }
    @Override
    public YwContractBillDataVO getWaitDealList(Integer contractId){
        YwContractBillDataVO ywContractBillDataVO = new YwContractBillDataVO();
        ywContractBillDataVO.setInAmount(Constants.ZERO);
        ywContractBillDataVO.setInFee(BigDecimal.ZERO);
        ywContractBillDataVO.setPayAmount(Constants.ZERO);
        ywContractBillDataVO.setPayFee(BigDecimal.ZERO);
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<YwContractBill>();
        queryWrapper.selectAll(YwContractBill.class)
            .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
            .selectAs(YwContract::getCode,YwContractBill::getContractCode)
            .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
            .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
            .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
            .eq(YwContractBill::getIsdeleted,Constants.ZERO)
            .in(YwContractBill::getPayStatus,Constants.ZERO,Constants.TWO,Constants.THREE,Constants.FOUR)
            .eq(YwContractBill::getContractId,contractId)
            .orderByDesc(YwContractBill::getId);
        List<YwContractBill> list = ywContractBillMapper.selectJoinList(YwContractBill.class,queryWrapper);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
            for (YwContractBill ywContractBill:list) {
                //需收金额
                ywContractBill.setNeedReceivableFee(
                        ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
                );
                //收款账单
                if(Constants.equalsInteger(ywContractBill.getBillType(),Constants.ZERO)){
                    //应收金额 小于 实收金额 多收金额  应该是退款
                     if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)<Constants.ZERO){
                         ywContractBillDataVO.setPayAmount(ywContractBillDataVO.getPayAmount()+1);
                         ywContractBillDataVO.setPayFee(ywContractBillDataVO.getPayFee().add(ywContractBill.getNeedReceivableFee().abs()));
                     }else if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)>Constants.ZERO){
                         ywContractBillDataVO.setInAmount(ywContractBillDataVO.getInAmount()+1);
                         ywContractBillDataVO.setInFee(ywContractBillDataVO.getInFee().add(ywContractBill.getNeedReceivableFee().abs()));
                     }
                }else{
                    //付款账单
                    //应付金额 小于 实付金额 应该是付款款
                    if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)<Constants.ZERO){
                        ywContractBillDataVO.setPayAmount(ywContractBillDataVO.getPayAmount()+1);
                        ywContractBillDataVO.setPayFee(ywContractBillDataVO.getPayFee().add(ywContractBill.getNeedReceivableFee().abs()));
                    }else{
                        ywContractBillDataVO.setInAmount(ywContractBillDataVO.getInAmount()+1);
                        ywContractBillDataVO.setInFee(ywContractBillDataVO.getInFee().add(ywContractBill.getNeedReceivableFee().abs()));
                    }
                }
            }
            ywContractBillDataVO.setYwContractBillList(list);
        }
        return ywContractBillDataVO;
    }
}