jiangping
2024-12-05 6bd7d8d56d0671e1251e6ae6eef9a16ea5ce2253
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
@@ -303,9 +303,10 @@
        BigDecimal fee = Constants.formatBigdecimal(model.getBtFee());
        String str = "退租摘要:剩余未结清账单{param1}份,关闭账单{param2}份【退租日{param3},退租费用合计需{param4}{param5}元。】";
        str = str.replace("{param1}",model.getBtWaitBill()+"")
                .replace("{param2}",DateUtil.getDateLongSlash(model.getBtDate()))
                .replace("{param3}",fee.compareTo(new BigDecimal(0)) >=0?"收":"付")
                .replace("{param4}",(fee.compareTo(new BigDecimal(0)) >=0?
                .replace("{param2}",model.getBtCLoseBill()+"")
                .replace("{param3}",DateUtil.getDateLongSlash(model.getBtDate()))
                .replace("{param4}",fee.compareTo(new BigDecimal(0)) >=0?"收":"付")
                .replace("{param5}",(fee.compareTo(new BigDecimal(0)) >=0?
                        Constants.formatBigdecimal(model.getBtFee()).intValue()
                        :(Constants.formatBigdecimal(model.getBtFee()).intValue() * -1))+"" );
        return  str;
@@ -1209,6 +1210,24 @@
    }
    @Override
    public YwContract findById(Integer id) {
        YwContract model =queryDetailInfoById(id);
        //查询操作日志记录
        YwWorkorderLog log = new YwWorkorderLog();
        log.setJobId(model.getId());
        log.setIsdeleted(Constants.ZERO);
        model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log)
                .lambda()
                .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey()
                        ,Constants.YwLogType.CONTRACT_CREATE.getKey()
                        ,Constants.YwLogType.CONTRACT_UPDATE.getKey())
                .orderByAsc(YwWorkorderLog::getCreateDate)));
        //查询账单集合
        queryBillListByModel(model,new Date());
        return model;
    }
    private YwContract queryDetailInfoById(Integer id) {
        MPJLambdaWrapper<YwContract> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwContract.class )
                .selectAs(Company::getName,YwContract::getCompanyName )
@@ -1224,7 +1243,9 @@
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .eq( YwContract::getId,id);
        YwContract model = ywContractMapper.selectJoinOne(YwContract.class,queryWrapper);
        if(model != null){
        if (model == null) {
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
            //合同附件
            initFiles(model);
            //查询房源信息数据
@@ -1258,30 +1279,20 @@
                    .orderByAsc(YwContractDetail::getSortnum);
            model.setWyDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class,dw));
            //查询操作日志记录
            YwWorkorderLog log = new YwWorkorderLog();
            log.setJobId(model.getId());
            log.setIsdeleted(Constants.ZERO);
            model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log)
                    .lambda()
                    .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey()
                            ,Constants.YwLogType.CONTRACT_CREATE.getKey()
                            ,Constants.YwLogType.CONTRACT_UPDATE.getKey())
                    .orderByAsc(YwWorkorderLog::getCreateDate)));
            //查询账单集合
            queryBillListByModel(model,new Date());
        }
        return model;
    }
    @Override
    public YwContract findForBills(YwContract model) {
        queryBillListByModel(model,model.getBtDate());
    public YwContract findForBills(YwContract param) {
        YwContract model = queryDetailInfoById(param.getId());
        queryBillListByModel(model,param.getBtDate());
        return model;
    }
    private void queryBillListByModel(YwContract model,Date date) {
        if(date ==null){
            date = new Date();
        }
        //查询账单集合
        model.setBillList(ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                .selectAll(YwContractBill.class )
@@ -1290,9 +1301,9 @@
                .eq(  YwContractBill::getContractId,model.getId())
                .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                .orderByAsc(YwContractBill::getSortnum,YwContractBill::getCreateDate)));
        for (YwContractBill ywContractBill:model.getBillList()) {
            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee());
//            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
        }
        model.setCanBackRentBills(new ArrayList<>());
        long nowStart = Utils.Date.getStart(date).getTime();
@@ -1307,7 +1318,6 @@
                        continue;
                    }
                    model.getCanBackRentBills().add(bill);
                }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
                    if(bill.getEndDate().getTime()<nowStart){
                        //如果已结清,账单直接关闭
@@ -1318,7 +1328,42 @@
                    model.getCanBackRentBills().add(bill);
                }
            }
            for(YwContractBill bill : model.getCanBackRentBills()){
                YwContractDetail detail = null;
                if(Constants.equalsInteger(bill.getCostType(),Constants.ZERO)){
                    detail = getDetailByIdFromList(bill.getDetailId(),model.getZlDetailList());
                    if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null
                            &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){
                        Date odate = bill.getEndDate();
                        bill.setEndDate(date);
                        BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getZlFreeStartDate(),model.getZlFreeEndDate());
                        bill.setEndDate(odate);
                        bill.setNeedReceivableFee(actFee);
        }
                }else if(Constants.equalsInteger(bill.getCostType(),Constants.ONE)){
                    detail = getDetailByIdFromList(bill.getDetailId(),model.getWyDetailList());
                    if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null
                            &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){
                        Date odate = bill.getEndDate();
                        bill.setEndDate(date);
                        BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getWyFreeStartDate(),model.getWyFreeEndDate());
                        bill.setEndDate(odate);
                        bill.setNeedReceivableFee(actFee);
                    }
                }
            }
        }
    }
    private YwContractDetail getDetailByIdFromList(Integer detailId, List<YwContractDetail> list) {
        if(list!=null){
            for(YwContractDetail d : list){
                if(Constants.equalsInteger(detailId,d.getId())){
                    return d;
                }
            }
        }
        return  null;
    }
    @Override