liukangdong
2024-12-03 a40e6a45b2207a9b172b7687ce6e4fe7da8b9ac6
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
@@ -33,6 +33,7 @@
import java.math.BigDecimal;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 运维合同信息表Service实现
@@ -86,7 +87,6 @@
        dealMultifileBiz(model);//处理附件信息
        dealRoomsForContract(model);//处理房源关联表
        dealLogBiz(model,Constants.YwLogType.CONTRACT_CREATE,model.getLoginUserInfo().getRealname(),"【"+model.getRemark().replace("合同摘要:","")+"】");//记录新建日志
        return model.getId();
    }
@@ -193,7 +193,7 @@
            }
            for(YwContractDetail d :model.getWyDetailList()){
                if(  d.getStartDate() == null
                        ||d.getEditDate() == null
                        ||d.getEndDate() == null
                        ||d.getPrice() == null
                        ||d.getCircleType() == null
                        || d.getCircleType()>6
@@ -236,9 +236,9 @@
        String str = "";
        //起租日2024/06/01,租赁数为500㎡。首期租赁三月一付,租金单价35元/㎡·月。首期物业三月一付,物业单价4.3元/㎡·月
        String str0 = "合同摘要:起租日{param1},租赁数为{param2}㎡。首期租赁{param3},租金单价{param4}元{param5}。首期物业{param6},物业单价{param7}{param8}";
        String str1 = "合同摘要:起租日{param1},租赁数为{param2}㎡。首期租赁{param3},租金单价{param4}元{param5}。";
        String str2 = "合同摘要:起租日{param1},首期物业{param6},物业单价{param7}元{param8}";
        String str0 = "合同摘要:起租日{param1},租赁数为{param2}㎡。首期租赁{param3},租金单价{param4}{param5}。首期物业{param6},物业单价{param7}{param8}";
        String str1 = "合同摘要:起租日{param1},租赁数为{param2}㎡。首期租赁{param3},租金单价{param4}{param5}。";
        String str2 = "合同摘要:起租日{param1},首期物业{param6},物业单价{param7}{param8}";
        if(Constants.equalsInteger(model.getType(),Constants.ZERO)){
            str= str0;
        }
@@ -252,10 +252,10 @@
                .replace("{param2}",model.getTotalArea().intValue()+"")
                .replace("{param3}",Constants.getPayTypeByNum(model.getZlPayType()))
                .replace("{param4}",Constants.formatBigdecimal(model.getZlFirstPrice()).intValue()+"")
                .replace("{param5}",Constants.getUnitTypeByNum(model.getZlFirstCircle())
                .replace("{param5}",Constants.getUnitTypeByNum(model.getZlFirstCircle()))
                .replace("{param6}",Constants.getPayTypeByNum(model.getWyPayType()))
                .replace("{param7}",Constants.formatBigdecimal(model.getWyFirstPrice()).intValue()+"")
                .replace("{param8}",Constants.getUnitTypeByNum(model.getWyFirstCircle())));
                .replace("{param8}",Constants.getUnitTypeByNum(model.getWyFirstCircle()));
        return  str;
    }
    private String getbackRentRemarkByParam(YwContract model) {
@@ -311,6 +311,9 @@
        update.setBtFee(param.getBtFee());
        update.setBtRemark(getbackRentRemarkByParam(param));
        ywContractMapper.updateById(update);
//        if(1==1){
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
//        }
        dealLogBiz(param,Constants.YwLogType.CONTRACT_BACK, param.getLoginUserInfo().getRealname(),getbackRentLogByParam(param));
        return param.getId();
    }
@@ -348,7 +351,7 @@
        List<YwContractBill> canBills = new ArrayList<>();//可退租修改数据
        List<YwContractBill> allBills = ywContractBillMapper.selectList(new QueryWrapper<YwContractBill>().
                select("*," +
                        "( select ifnull(sum(yw.ACT_RECEIVABLE_FEE),0) from  yw_contract_revenue yw where yw.bill_id = yw_contract_bill.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee " )
                        "( 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 = yw_contract_bill.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee " )
                .lambda().
                eq(YwContractBill::getIsdeleted,Constants.ZERO)
                .eq(YwContractBill::getContractId,param.getId()));
@@ -365,15 +368,23 @@
                }
                if(Constants.equalsInteger(bill.getPayStatus(),Constants.ZERO)
                        ||Constants.equalsInteger(bill.getPayStatus(),Constants.THREE)){
                    if(bill.getStartDate().getTime()>param.getEditDate().getTime()){
                    if(bill.getStartDate().getTime()<param.getBtDate().getTime()){
                        canBills.add(bill);
                    }else{
                        //如果还没开始,账单直接关闭
                        closeBills.add(bill);
                        noBills.add(bill);
                    }else{
                        canBills.add(bill);
                    }
//                    if(bill.getStartDate().getTime()>param.getEditDate().getTime()){
//                        //如果还没开始,账单直接关闭
//                        closeBills.add(bill);
//                        noBills.add(bill);
//                    }else{
//                        canBills.add(bill);
//                    }
                }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
                    if(bill.getEndDate().getTime()<param.getEditDate().getTime()){
                    if(bill.getStartDate().getTime()>param.getBtDate().getTime()){
//                    if(bill.getEndDate().getTime()<param.getEditDate().getTime()){
                        //如果已结清,账单直接关闭
                        noBills.add(bill);
                    }else{
@@ -415,6 +426,7 @@
                        //如果账单还有款待收,则保持状态不变
                    }
                }
                b.setReceivableFee(editBill.getReceivableFee());
                b.setEditDate(param.getEditDate());
                b.setEditor(param.getEditor());
                b.setBtActDate(param.getBtActDate());
@@ -467,26 +479,21 @@
        if(yjBills.size()>0){
            // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金
            for(YwContractBill bill : yjBills){
                if(!Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
//                    YwContractBill b = new YwContractBill();
//                    //付款状态:0=待收款;1=已结清;2=部分结清;3=待付款;4=待退款;5=已关闭
//                    //如果账单信息做了编辑,金额计算 实收金额 和 修改后应收金额作对比,判断是否应该退款
//                    BigDecimal fee = Constants.formatBigdecimal(bill.getActReceivableFee()).subtract(bill.getReceivableFee());
//                    if(fee.compareTo(new BigDecimal(0))== 0){
//                        //如果费用正好,则修改账单信息为已结清
//                        b.setPayStatus(Constants.ONE);
//                    }else if(fee.compareTo(new BigDecimal(0))> 0){
//                        //如果需要进行退款,更新账单信息为待退款
//                        b.setPayStatus(Constants.FOUR);
//                    }
//                    b.setId(bill.getId());
//                    b.setEditDate(param.getEditDate());
//                    b.setEditor(param.getEditor());
//                    b.setReceivableFee(BigDecimal.ZERO);
//                    ywContractBillMapper.updateById(b);
                    //如果是未结清押金
                    yjNoBills ++;
                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(param.getCanBackRentBills())){
                    List<YwContractBill> optional = param.getCanBackRentBills().stream().filter(i->Constants.equalsInteger(bill.getId(),i.getId())).collect(Collectors.toList());
                    if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(optional)){
                        YwContractBill canBill = optional.get(Constants.ZERO);
                        YwContractBill yjBill = new YwContractBill();
                        yjBill.setId(bill.getId());
                        yjBill.setEditDate(param.getEditDate());
                        yjBill.setEditor(param.getEditor());
                        yjBill.setReceivableFee(BigDecimal.ZERO);
                        yjBill.setPayStatus(Constants.FOUR);
                        yjBill.setPlanPayDate(canBill.getPlanPayDate());
                        ywContractBillMapper.updateById(yjBill);
                    }
                }
                yjNoBills ++;
            }
        }
        param.setBtWaitBill(canBills.size() + newBills.size()+yjNoBills);//未清算的账单数量
@@ -641,15 +648,12 @@
        }
        int num =1;
        for(int i=0;i<billList1.size();i++){
            if(Constants.equalsInteger( billList1.get(i).getCostType(),Constants.ZERO)){
                billList1.get(i).setSortnum(num++);
            }
            billList1.get(i).setSortnum(num);
            num++;
        }
          num =1;
        for(int i=0;i<billList2.size();i++){
            if(Constants.equalsInteger( billList2.get(i).getCostType(),Constants.ONE)){
                billList2.get(i).setSortnum(num++);
            }
            billList2.get(i).setSortnum(num);
            num++;
        }
        if(model.getId()!=null){
            ywContractBillMapper.insert(billList1);
@@ -1227,9 +1231,15 @@
            //查询账单集合
            model.setBillList(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  ")
                            .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()));
            }
            model.setCanBackRentBills(new ArrayList<>());
            long nowStart = Utils.Date.getStart(new Date()).getTime();
            long nowEnd = Utils.Date.getEnd(new Date()).getTime();