renkang
2024-11-27 b9632baaa11d6e9df2b8fea79f259314bfac1676
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
@@ -45,6 +45,8 @@
    @Autowired
    private YwContractMapper ywContractMapper;
    @Autowired
    private YwContractRoomMapper ywContractRoomMapper;
    @Autowired
    private YwContractDetailMapper ywContractDetailMapper;
    @Autowired
    private YwContractBillMapper ywContractBillMapper;
@@ -82,9 +84,29 @@
        ywContractMapper.insert(model);
        dealDetailListBiz(model);//处理条款信息
        dealMultifileBiz(model);//处理附件信息
        dealLogBiz(model,Constants.YwLogType.CONTRACT_CREATE,null,null);//记录新建日志
        dealRoomsForContract(model);//处理房源关联表
        dealLogBiz(model,Constants.YwLogType.CONTRACT_CREATE,model.getLoginUserInfo().getRealname(),"【"+model.getRemark().replace("合同摘要:","")+"】");//记录新建日志
        return model.getId();
    }
    private void dealRoomsForContract(YwContract model) {
        List<YwContractRoom> list = new ArrayList<>();
        for(YwRoom room :model.getRoomList()){
            YwContractRoom t = new YwContractRoom();
            t.setContractId(model.getId());
            t.setRoomId(room.getId());
            t.setCreator(model.getCreator());
            t.setIsdeleted(Constants.ZERO);
            t.setCreateDate(model.getCreateDate());
            t.setEditDate(model.getCreateDate());
            t.setEditor(model.getCreator());
            t.setType(Constants.ZERO);
            list.add(t);
        }
        ywContractRoomMapper.insert(list);
    }
    @Override
    public   List<YwContractBill> getBillList(YwContract model){
@@ -247,6 +269,14 @@
                        :(Constants.formatBigdecimal(model.getBtFee()).intValue() * -1))+"" );
        return  str;
    }
    private String getbackRentLogByParam(YwContract model) {
        BigDecimal fee = Constants.formatBigdecimal(model.getBtFee());
        String str = "【退租日{param1},退租原因:{param2},退租协议中统计的费用总计{param3}元。】";
        str = str.replace("{param1}",DateUtil.getDateLongSlash(model.getBtDate()))
                .replace("{param2}",StringUtils.defaultString(model.getBtInfo(),""))
                .replace("{param3}",Constants.formatBigdecimal2Float(model.getBtFee()).doubleValue()+"");
        return  str;
    }
@@ -276,7 +306,7 @@
        update.setBtFee(param.getBtFee());
        update.setBtRemark(getbackRentRemarkByParam(param));
        ywContractMapper.updateById(update);
        dealLogBiz(param,Constants.YwLogType.CONTRACT_BACK,null,null);
        dealLogBiz(param,Constants.YwLogType.CONTRACT_BACK, param.getLoginUserInfo().getRealname(),getbackRentLogByParam(param));
        return param.getId();
    }
@@ -508,7 +538,7 @@
            //如果有租赁条款
            if(Constants.formatBigdecimal(model.getZlDeposit()).compareTo(new BigDecimal(0))>0){
                    //如果有租赁押金
                billList1.add(initDepoistBill(Constants.THREE,model));
                billList1.add(initDepoistBill(Constants.THREE,model,details));
            }
            if(Constants.equalsInteger(model.getZlPayType(), Constants.ZERO)){
                //如果是一次性付清
@@ -529,7 +559,7 @@
            //如果物业条款
            if(Constants.formatBigdecimal(model.getWyDeposit()).compareTo(new BigDecimal(0))>0){
                //如果有租赁押金
                billList2.add(initDepoistBill(Constants.FOUR,model));
                billList2.add(initDepoistBill(Constants.FOUR,model,details));
            }
            if(Constants.equalsInteger(model.getWyPayType(), Constants.ZERO)){
                //如果是一次性付清
@@ -569,7 +599,7 @@
        }
    }
    private YwContractBill initDepoistBill(int type,  YwContract model) {
    private YwContractBill initDepoistBill(int type,  YwContract model, List<YwContractDetail> details) {
        YwContractBill bill  = new YwContractBill();
        bill.setCreateDate(model.getEditDate());
        bill.setCreator(model.getEditor());
@@ -582,10 +612,18 @@
        bill.setEndDate(model.getEndDate());
        bill.setType(Constants.ZERO);
        bill.setCostType(type);
        YwContractDetail d = details.get(Constants.ZERO);
        if(Objects.isNull(d)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"条款数据异常");
        }
        Date planPayDate = DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1);
        bill.setPlanPayDate(planPayDate.getTime()>System.currentTimeMillis()?planPayDate:new Date());
        bill.setTotleFee(type==Constants.THREE?model.getZlDeposit():model.getWyDeposit());//押金费用
        bill.setReceivableFee(bill.getTotleFee());
        bill.setBillType(Constants.ZERO);
        bill.setPayStatus(Constants.ZERO);
        bill.setSortnum(0);
        bill.setCompanyId(model.getCompanyId());
        return bill;
    }
@@ -687,12 +725,13 @@
            YwContractBill bill = initCreateBillModel(model,d );
            bill.setStartDate(start);//账单开始
            bill.setEndDate(end);//账单结束
            bill.setPlanPayDate(DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1));
            Date planPayDate = DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1);
            bill.setPlanPayDate(planPayDate.getTime()>System.currentTimeMillis()?planPayDate:new Date());
            BigDecimal totalFee =getTotalFeeByStartEnd(model,d,freeStart,freeEnd);
            bill.setTotleFee(totalFee);
            bill.setReceivableFee(totalFee);
            bill.setBillType(Constants.ZERO);
            bill.setCompanyId(model.getCompanyId());
            list.add(bill);
        }
    }
@@ -810,8 +849,11 @@
    }
    private void initFiles(YwContract model) {
        List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId, model.getId() )
        List<Multifile> multifiles = multifileMapper.selectJoinList(Multifile.class,new MPJLambdaWrapper<Multifile>()
                .selectAll(Multifile.class)
                .selectAs(SystemUser::getRealname,Multifile::getUserName)
                .leftJoin(SystemUser.class,SystemUser::getId,Multifile::getCreator)
                .eq(Multifile::getObjId,model.getId())
                .in(Multifile::getObjType, Arrays.asList(new Integer[]{Constants.MultiFile.YW_CONTRACT_FILE.getKey()}))
                .eq(Multifile::getIsdeleted,Constants.ZERO));
        if(multifiles!=null){
@@ -1047,6 +1089,7 @@
        log.setObjType(type.getKey());
        log.setParam1(param1);
        log.setParam2(param2);
        log.setContent(param2);
        log.setTitle(type.getNoteinfo());
        ywWorkorderLogMapper.insert(log);
    }
@@ -1058,12 +1101,13 @@
                .selectAs(SystemUser::getRealname,YwContract::getUserName )
                .selectAs(YwCustomer::getName,YwContract::getRenterName )
                .selectAs(YwProject::getName,YwContract::getProjectName )
                .select("t4.realname",YwContract::getCreatorName )
                .select("t3.realname",YwContract::getCreatorName )
                .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);
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .eq( YwContract::getId,id);
        YwContract model = ywContractMapper.selectJoinOne(YwContract.class,queryWrapper);
        if(model != null){
            //合同附件
@@ -1078,7 +1122,7 @@
                    .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                    .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
                    .eq(YwRoom::getIsdeleted,Constants.ZERO)
                    .exists("(select a.id from yw_contract_room a where a.isdeleted=1 and a.room_id=t.id and a.contract_id="+model.getId()+")");
                    .exists("(select a.id from yw_contract_room a where a.isdeleted=0 and a.type=0 and a.room_id=t.id and a.contract_id="+model.getId()+")");
            model.setRoomList(roomMapper.selectJoinList(YwRoom.class,rw));
            model.setWyFirstCircleStr(Constants.getUnitTypeByNum(model.getWyFirstCircle()));
            model.setZlFirstCircleStr(Constants.getUnitTypeByNum(model.getZlFirstCircle()));
@@ -1167,8 +1211,10 @@
        MPJLambdaWrapper<YwContract> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwContract.class )
                .selectAs(Company::getName,YwContract::getCompanyName )
                .selectAs(YwCustomer::getName,YwContract::getRenterName )
                .select("(select sum(r.area) from yw_contract_room cr left join yw_room r on r.id = cr.room_id where r.isdeleted=0 and cr.contract_id =t.id)",YwContract::getTotalArea )
                .leftJoin(Company.class,Company::getId,YwContract::getCompanyId);
                .leftJoin(Company.class,Company::getId,YwContract::getCompanyId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId);
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.eq(YwContract::getId, pageWrap.getModel().getId());