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{
@@ -394,16 +405,7 @@
                ywContractBillMapper.updateById(b);
            }
        }
        int yjNoBills =0;
        if(yjBills.size()>0){
            // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金
            for(YwContractBill bill : yjBills){
               if(!Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
                   //如果是未结清押金
                   yjNoBills ++;
               }
            }
        }
        BigDecimal totalBackFee = new BigDecimal(0);
        if(canBills.size()>0){
            //直接关闭关闭账单
@@ -416,14 +418,15 @@
                    fee = Constants.formatBigdecimal(b.getActReceivableFee()).subtract(editBill.getReceivableFee());
                    if(fee.compareTo(new BigDecimal(0))== 0){
                        //如果费用正好,则修改账单信息为已结清
                        b.setStatus(Constants.ONE);
                        b.setPayStatus(Constants.ONE);
                    }else if(fee.compareTo(new BigDecimal(0))> 0){
                        //如果需要进行退款,更新账单信息为待退款
                        b.setStatus(Constants.FOUR);
                        b.setPayStatus(Constants.FOUR);
                    }else if(fee.compareTo(new BigDecimal(0)) < 0){
                        //如果账单还有款待收,则保持状态不变
                    }
                }
                b.setReceivableFee(editBill.getReceivableFee());
                b.setEditDate(param.getEditDate());
                b.setEditor(param.getEditor());
                b.setBtActDate(param.getBtActDate());
@@ -444,6 +447,10 @@
                addBill.setContractId(param.getId());
                addBill.setType(Constants.ONE);
                addBill.setStatus(Constants.ZERO);
                if(Constants.equalsInteger(addBill.getFeeType(),Constants.ONE)){
                    addBill.setStartDate(addBill.getPlanPayDate());
                    addBill.setEndDate(addBill.getPlanPayDate());
                }
                if(Constants.equalsInteger(addBill.getBillType(),Constants.ZERO)){
                    //如果是收款
                    totalBackFee = totalBackFee.add(Constants.formatBigdecimal(addBill.getActReceivableFee()));
@@ -466,6 +473,28 @@
                newBills.add(addBill);
            }
            ywContractBillMapper.insert(param.getAddBillList());//批量插入数据
        }
        int yjNoBills =0;
        if(yjBills.size()>0){
            // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金
            for(YwContractBill bill : yjBills){
                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);//未清算的账单数量
        param.setBtCLoseBill(closeBills.size());
@@ -619,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);
@@ -649,7 +675,10 @@
        bill.setType(Constants.ZERO);
        bill.setCostType(type);
        bill.setPlanPayDate(bill.getStartDate());
        bill.setTotleFee(type==Constants.THREE?model.getZlDeposit():model.getWyDeposit());//押金费用
        bill.setTotleFee(type==Constants.TWO?
                Objects.isNull(model.getZlDeposit())?BigDecimal.ZERO:model.getZlDeposit()
                :
                Objects.isNull(model.getWyDeposit())?BigDecimal.ZERO:model.getWyDeposit());//押金费用
        bill.setReceivableFee(bill.getTotleFee());
        bill.setBillType(Constants.ZERO);
        bill.setPayStatus(Constants.ZERO);
@@ -762,14 +791,10 @@
            bill.setTotleFee(totalFee);
            bill.setReceivableFee(totalFee);
            bill.setBillType(Constants.ZERO);
            bill.setCompanyId(model.getCompanyId());
            list.add(bill);
        }
    }
    private BigDecimal getTotalFeeByStartEnd(YwContract model, YwContractDetail d, YwContractBill bill,Date freeStart,Date freeEnd) {
        BigDecimal totalFee = new BigDecimal(0);
        DateCompare dateCompare =   DateCompare.dayCompare(bill.getStartDate(),DateUtil.addDaysToDate(bill.getEndDate(),1),freeStart,DateUtil.addDaysToDate(freeEnd,1));
@@ -1206,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();
@@ -1226,7 +1257,7 @@
                    }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
                        if(bill.getEndDate().getTime()<nowStart){
                            //如果已结清,账单直接关闭
                          continue;
                            continue;
                        }
                        model.getCanBackRentBills().add(bill);
                    }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.TWO) ){
@@ -1248,10 +1279,18 @@
    @Override
    public List<YwContract> findList(YwContract ywContract) {
        QueryWrapper<YwContract> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(YwContract::getIsdeleted,Constants.ZERO);
        wrapper.lambda().in(YwContract::getStatus,Constants.ZERO,Constants.ONE,Constants.TWO);
        return ywContractMapper.selectList(wrapper);
        return ywContractMapper.selectJoinList(YwContract.class,new MPJLambdaWrapper<YwContract>().selectAll(YwContract.class )
                .selectAs(Company::getName,YwContract::getCompanyName )
                .selectAs(SystemUser::getRealname,YwContract::getUserName )
                .selectAs(YwCustomer::getName,YwContract::getRenterName )
                .selectAs(YwProject::getName,YwContract::getProjectName )
                .leftJoin(Company.class,Company::getId,YwContract::getCompanyId)
                .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getUserId)
                .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getCreator)
                .leftJoin(YwProject.class,YwProject::getId,YwContract::getProjectId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .eq(YwContract::getIsdeleted,Constants.ZERO)
                .in(YwContract::getStatus,Constants.ZERO,Constants.ONE,Constants.TWO));
    }
  
    @Override