renkang
2025-01-10 b5cf636e0ab19cbfea6c72d36f5629eb10bf2bda
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractBillServiceImpl.java
@@ -7,9 +7,12 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.YwContractBillCallDataVO;
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 +23,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;
@@ -54,6 +58,9 @@
    @Autowired
    private YwContractMapper ywContractMapper;
    @Autowired
    private MemberMapper memberMapper;
    @Override
@@ -66,7 +73,7 @@
                || Objects.isNull(ywContractBill.getBillType())
                || Objects.isNull(ywContractBill.getCompanyId())
                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractBill.getYwContractRoomList())
                || Objects.nonNull(ywContractBill.getFeeType())
                || Objects.isNull(ywContractBill.getFeeType())
                || (Constants.equalsInteger(ywContractBill.getFeeType(),Constants.ZERO)&& (Objects.isNull(ywContractBill.getStartDate())
                || Objects.isNull(ywContractBill.getEndDate())))
        ){
@@ -87,6 +94,26 @@
        ywContractBill.setIsdeleted(Constants.ZERO);
        ywContractBill.setType(Constants.ONE);
        ywContractBill.setStatus(Constants.ZERO);
        if(Constants.equalsInteger(ywContractBill.getBillType(),Constants.ZERO)){
            ywContractBill.setPayStatus(Constants.ZERO);
        }else{
            ywContractBill.setPayStatus(Constants.THREE);
        }
        if(Constants.equalsInteger(ywContractBill.getFeeType(),Constants.ONE)){
            ywContractBill.setStartDate(ywContractBill.getPlanPayDate());
            ywContractBill.setEndDate(ywContractBill.getPlanPayDate());
        }
        //查询合同下的最大的序号
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectList(new QueryWrapper<YwContractBill>()
                .lambda().eq(YwContractBill::getContractId,ywContract.getId())
                .in(YwContractBill::getCostType,Constants.ZERO,Constants.SIX,Constants.FOUR,Constants.FIVE,7)
                .orderByDesc(YwContractBill::getId));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
            ywContractBill.setSortnum(ywContractBillList.size() + 1 );
        }else{
            ywContractBill.setSortnum(0);
        }
        ywContractBillMapper.insert(ywContractBill);
        //房源数据
@@ -169,30 +196,57 @@
    public YwContractBill getDetail(Integer id) {
        YwContractBill ywContractBill = ywContractBillMapper.selectJoinOne(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>().selectAll(YwContractBill.class)
                        .select(" ( select ifnull(sum(yw.ACT_RECEIVABLE_FEE),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 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)
                        .selectAs(Company::getId,YwContractBill::getCompanyId)
                        .selectAs(Company::getName,YwContractBill::getCompanyName)
                        .selectAs(SystemUser::getRealname,YwContractBill::getRealname)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .leftJoin(Company.class,Company::getId,YwContract::getCompanyId)
                        .leftJoin(SystemUser.class,SystemUser::getId,YwContractBill::getCreator)
                        .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                        .eq(YwContractBill::getId,id));
        if(Objects.isNull(ywContractBill)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        ywContractBill.setNeedReceivableFee(
                ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
        );
        //房源数据
        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)
                .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
                .selectAs(YwRoom::getCode,YwContractRoom::getRoomName)
                .selectAs(YwRoom::getArea,YwContractRoom::getArea)
                .leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
                .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
                .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
                .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                .eq(YwContractRoom::getContractId,id)
                .eq(YwContractRoom::getType,Constants.ONE)
                .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) || 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)
        ));
        //收支记录
        ywContractBill.setYwContractRevenueList(
                ywContractRevenueMapper.selectJoinList(YwContractRevenue.class,new MPJLambdaWrapper<YwContractRevenue>()
                    .selectAll(YwContractRevenue.class)
                    .selectAs(YwCustomer::getName,YwContractRevenue::getCustomerName)
                    .leftJoin(YwContract.class,YwContract::getId,YwContractRevenue::getContractId)
                    .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                    .eq(YwContractRevenue::getStatus,Constants.ZERO)
                    .eq(YwContractRevenue::getBillId,ywContractBill.getId())
                    .orderByDesc(YwContractRevenue::getId)
                )
        );
        //附件数据
        List<Multifile> multifileList = multifileMapper.selectJoinList(Multifile.class,new MPJLambdaWrapper<Multifile>()
@@ -235,7 +289,7 @@
        YwContractBill model = pageWrap.getModel();
        IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
            queryWrapper.selectAll(YwContractBill.class)
                    .select(" ( select ifnull(sum(yw.ACT_RECEIVABLE_FEE),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)
                    .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
@@ -245,15 +299,24 @@
                            YwCustomer::getName,model.getCustomerName())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getStatus()),
                            YwContractBill::getStatus,model.getStatus())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getBillType()),
                            YwContractBill::getBillType,model.getBillType())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
                            YwContractBill::getPayStatus,model.getPayStatus())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getType()),
                            YwContractBill::getType,model.getType())
                    .le(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                            YwContractBill::getPlanPayDate, DateUtil.getCurrDateTime())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                            YwContractBill::getStatus, Constants.ZERO)
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getContractId()),
                            YwContractBill::getContractId,model.getContractId())
                    .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getContractCode()),
                            YwContract::getCode,model.getContractCode())
                .ge(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateStart()),YwContractBill::getPlanPayDate, Utils.Date.getStart(model.getPlanPayDateStart()))
                .le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd())) )
        ;
                .le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd()))
                    .orderByDesc(YwContractBill::getId));
        this.dealRoomDetail(iPage.getRecords());
        for (YwContractBill ywContractBill:iPage.getRecords()) {
            //需收金额
@@ -261,15 +324,88 @@
                    ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
            );
            //是否逾期
            if(Constants.equalsInteger(ywContractBill.getStatus(),Constants.ZERO) && (Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ZERO)
            || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.TWO)
            || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.THREE)
            || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.FOUR))
            && ywContractBill.getEndDate().getTime() < System.currentTimeMillis()){
            if(Constants.equalsInteger(ywContractBill.getStatus(),Constants.ZERO)
                && (Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ZERO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.TWO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.THREE)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.FOUR))
            && ywContractBill.getPlanPayDate().getTime() < System.currentTimeMillis()){
                ywContractBill.setIsOverdue(Constants.ONE);
            }else{
                ywContractBill.setIsOverdue(Constants.ZERO);
            }
            //楼宇名称
            List<YwContractRoom> ywContractRoomList = ywContractBill.getYwContractRoomList();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
                StringBuilder roomPathName = new StringBuilder();
                for (YwContractRoom ywContractRoom:ywContractRoomList) {
                    if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
                        roomPathName.append(ywContractRoom.getProjectName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
                        roomPathName.append(ywContractRoom.getBuildingName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
                        roomPathName.append(ywContractRoom.getFloorName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
                        roomPathName.append(ywContractRoom.getRoomName());
                    }
                    if(StringUtils.isNotBlank(roomPathName)){
                        roomPathName.append(";");
                    }
                }
                ywContractBill.setRoomPathName(roomPathName.toString());
            }
        }
        return PageData.from(iPage);
    }
    /**
     * 逾期账单
     * @param pageWrap
     * @return
     */
    @Override
    public PageData<YwContractBill> findPageForOverdue(PageWrap<YwContractBill> pageWrap) {
        IPage<YwContractBill> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwContractBill model = pageWrap.getModel();
        IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
                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)
                        .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getCustomerName()),
                                YwCustomer::getName,model.getCustomerName())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getStatus()),
                                YwContractBill::getStatus,model.getStatus())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getBillType()),
                                YwContractBill::getBillType,model.getBillType())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
                                YwContractBill::getPayStatus,model.getPayStatus())
                        .in(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
                                YwContractBill::getPayStatus,Constants.ZERO,Constants.THREE,Constants.TWO,Constants.FOUR)
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getType()),
                                YwContractBill::getType,model.getType())
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                                YwContractBill::getPlanPayDate, DateUtil.getCurrDateTime())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                                YwContractBill::getStatus, Constants.ZERO)
                        .ge(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateStart()),YwContractBill::getPlanPayDate, Utils.Date.getStart(model.getPlanPayDateStart()))
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd()))
                        .orderByDesc(YwContractBill::getId));
        this.dealRoomDetail(iPage.getRecords());
        for (YwContractBill ywContractBill:iPage.getRecords()) {
            //需收金额
            ywContractBill.setNeedReceivableFee(
                    ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
            );
            //楼宇名称
            List<YwContractRoom> ywContractRoomList = ywContractBill.getYwContractRoomList();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
@@ -339,9 +475,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(
@@ -380,7 +516,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;
                    }
@@ -407,5 +543,131 @@
    }
    @Override
    public List<YwContractBill> getCanBackBill(YwContractBill model) {
        List<YwContractBill> list = ywContractBillMapper.selectJoinList(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>().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)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                        .in(YwContractBill::getCostType,Constants.ZERO,Constants.ONE,Constants.FOUR,Constants.FIVE,7)
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getContractId()),
                                YwContractBill::getContractId,model.getContractId())
                        .and(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),
                                i->i.le(YwContractBill::getStartDate, Utils.Date.getEnd(model.getPlanPayDateEnd())).or()
                        .in(YwContractBill::getPayStatus,Constants.ONE,Constants.TWO) ))
                ;
        for (YwContractBill ywContractBill:list) {
            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
        }
        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;
    }
    @Override
    public List<YwContractBillCallDataVO> getNoticeCustomerData(List<Integer> billIds){
        List<YwContractBillCallDataVO> ywContractBillCallDataVOList = new ArrayList<>();
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                .selectAll(YwContractBill.class)
                .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                .selectAs(YwCustomer::getUserId,YwContractBill::getCustomerUserId)
                .selectAs(YwCustomer::getId,YwContractBill::getCustomerId)
                .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .in(YwContractBill::getId,billIds)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractBillList) ||
            !Constants.equalsInteger(billIds.size(),ywContractBillList.size())
        ){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"账单数据错误,请刷新重试");
        }
        for (YwContractBill ywContractBill:ywContractBillList) {
            YwContractBillCallDataVO ywContractBillCallDataVO = new YwContractBillCallDataVO();
            ywContractBillCallDataVO.setBillId(ywContractBill.getId());
            ywContractBillCallDataVO.setCustomerName(ywContractBill.getCustomerName());
            ywContractBillCallDataVO.setUserId(ywContractBill.getCustomerUserId());
            //查询客户下的所有人员
            ywContractBillCallDataVO.setMemberList(
                memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getCustomerId,ywContractBill.getCustomerId())
                        .eq(Member::getIsdeleted,Constants.ZERO))
            );
            ywContractBillCallDataVOList.add(ywContractBillCallDataVO);
        }
        return ywContractBillCallDataVOList;
    }
    public void downloadCallFeeDoc(List<Integer> billIds){
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                .selectAll(YwContractBill.class)
                .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                .selectAs(YwCustomer::getUserId,YwContractBill::getCustomerUserId)
                .selectAs(YwCustomer::getId,YwContractBill::getCustomerId)
                .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .in(YwContractBill::getId,billIds)
        );
    }
}