| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.aizuda.bpm.engine.entity.FlwHisTask; |
| | | import com.aizuda.bpm.mybatisplus.mapper.FlwHisTaskMapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.constant.DictConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.ProcessCategoryEnum; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.bo.ProcessStartBO; |
| | | import com.ruoyi.system.dto.SignContractDTO; |
| | | import com.ruoyi.system.dto.TerminateContractDTO; |
| | | import com.ruoyi.system.mapper.TBillMapper; |
| | | import com.ruoyi.system.mapper.TCheckAcceptRecordMapper; |
| | | import com.ruoyi.system.mapper.TContractMapper; |
| | | import com.ruoyi.system.mapper.THouseMapper; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.model.TCheckAcceptRecord; |
| | | import com.ruoyi.system.model.TContract; |
| | | import com.ruoyi.system.model.THouse; |
| | | import com.ruoyi.system.query.TContractAppletQuery; |
| | | import com.ruoyi.system.query.TContractBillQuery; |
| | | import com.ruoyi.system.query.TContractQuery; |
| | | import com.ruoyi.system.service.StateProcessTemplateService; |
| | | import com.ruoyi.system.service.TBillService; |
| | | import com.ruoyi.system.service.TContractRentTypeService; |
| | | import com.ruoyi.system.service.TContractService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.vo.BillVO; |
| | | import com.ruoyi.system.vo.CheckAcceptRecordVO; |
| | | import com.ruoyi.system.vo.ScreenRentIncomeTrendVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private TBillService billService; |
| | | @Resource |
| | | private TContractMapper contractMapper; |
| | | @Autowired |
| | | private StateProcessTemplateService stateProcessTemplateService; |
| | | @Autowired |
| | | private FlwHisTaskMapper flwHisTaskMapper; |
| | | |
| | | @Override |
| | | public PageInfo<TContract> contractList(TContractQuery query) { |
| | | PageInfo<TContract> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TContract> list = this.baseMapper.contractList(query,pageInfo); |
| | | //获取当前登录用户信息 |
| | | String businessDeptId = SecurityUtils.getBusinessDeptId(); |
| | | List<TContract> list = this.baseMapper.contractList(query,pageInfo,businessDeptId); |
| | | for (TContract tContract : list) { |
| | | tContract.setPayType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_PAY_TYPE,tContract.getPayType())); |
| | | tContract.setStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_STATUS,tContract.getStatus())); |
| | | FlwHisTask flwHisTask = flwHisTaskMapper.selectOne(new LambdaQueryWrapper<FlwHisTask>() |
| | | .like(FlwHisTask::getVariable, tContract.getId()) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(flwHisTask)){ |
| | | tContract.setInstanceId(Objects.nonNull(flwHisTask.getInstanceId())?String.valueOf(flwHisTask.getInstanceId()):""); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | |
| | | PageInfo<TContract> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TContract> list = this.baseMapper.contractAppletList(query,pageInfo); |
| | | for (TContract tContract : list) { |
| | | tContract.setPayType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_PAY_TYPE,tContract.getPayType())); |
| | | tContract.setPayType( |
| | | DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_PAY_TYPE, tContract.getPayType()) |
| | | ); |
| | | tContract.setStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_CONTRACT_STATUS,tContract.getStatus())); |
| | | FlwHisTask flwHisTask = flwHisTaskMapper.selectOne(new LambdaQueryWrapper<FlwHisTask>() |
| | | .like(FlwHisTask::getVariable, tContract.getId()) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(flwHisTask)){ |
| | | tContract.setInstanceId(Objects.nonNull(flwHisTask.getInstanceId())?String.valueOf(flwHisTask.getInstanceId()):""); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | |
| | | public void terminateContract(TerminateContractDTO dto) { |
| | | TContract contract = this.baseMapper.selectById(dto.getId()); |
| | | contract.setTerminateRemark(dto.getTerminateRemark()); |
| | | contract.setStatus("4"); |
| | | contract.setTerminateTime(dto.getTerminateTime()); |
| | | this.baseMapper.updateById(contract); |
| | | // 生成验收记录 |
| | | TCheckAcceptRecord tCheckAcceptRecord = new TCheckAcceptRecord(); |
| | | tCheckAcceptRecord.setContractId(dto.getId()); |
| | | tCheckAcceptRecord.setHouseId(contract.getHouseId()); |
| | | tCheckAcceptRecord.setLeaseReason("后台终止"); |
| | | tCheckAcceptRecord.setStatus("1"); |
| | | checkAcceptRecordMapper.insert(tCheckAcceptRecord); |
| | | // 将所有未缴费账单设置未已失效 |
| | | List<TBill> tBills = billMapper.selectList(new LambdaQueryWrapper<TBill>() |
| | | .in(TBill::getPayFeesStatus, Arrays.asList("1,4")) |
| | | .eq(TBill::getContractId, dto.getId())); |
| | | for (TBill tBill : tBills) { |
| | | tBill.setPayFeesStatus("5"); |
| | | } |
| | | billService.updateBatchById(tBills); |
| | | // 进入合同提前终止审批流程 |
| | | ProcessStartBO processStartBO = new ProcessStartBO(); |
| | | processStartBO.setCategory(ProcessCategoryEnum.CATEGORY3.getValue().toString()); |
| | | processStartBO.setModuleName("合同提前终止审批"); |
| | | processStartBO.setName(contract.getContractName()); |
| | | processStartBO.setRemark(""); |
| | | Map<String, Object> variable = new HashMap<>(); |
| | | variable.put("projectId", dto.getId()); |
| | | processStartBO.setVariable(variable); |
| | | //开启工作流程 |
| | | stateProcessTemplateService.start(processStartBO); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String t = "1000438"; |
| | | System.err.println("XN" + String.valueOf(t).substring(1)); |
| | | } |
| | | @Override |
| | | public CheckAcceptRecordVO getCheckByContractId(String id) { |
| | | CheckAcceptRecordVO checkAcceptRecordVO = new CheckAcceptRecordVO(); |
| | |
| | | if (contract==null)return R.fail("合同不存在"); |
| | | if (contract.getStatus().equals("4"))return R.fail("该合同已签订"); |
| | | contract.setSignature(dto.getSignature()); |
| | | contract.setStatus("2"); |
| | | contractMapper.updateById(contract); |
| | | contract.setFirstPayTime(contract.getStartTime().plusDays(10)); |
| | | List<TBill> bills = new ArrayList<>(); |
| | | List<TContractRentType> contractRentTypes = contractRentTypeService.list(); |
| | | // 第一次应缴费日期 |
| | | LocalDateTime firstPayTime = contract.getStartTime().plusDays(10).withHour(0).withMinute(0).withSecond(0); |
| | | LocalDate localDate = contract.getStartTime().plusDays(10).toLocalDate(); |
| | | LocalDate now = LocalDate.now(); |
| | | contract.setStatus("9"); |
| | | contractMapper.updateById(contract); |
| | | |
| | | TBill rentBill = new TBill(); |
| | | rentBill.setContractId(contract.getId()); |
| | | rentBill.setContractNumber(contract.getContractNumber()); |
| | | LocalDateTime startPayTime = contract.getStartPayTime(); |
| | | LocalDateTime endTime1 = contract.getEndTime(); |
| | | // // 计算两个时间相差多少天 |
| | | // // 如果时间小于30天 需要计算每日租金 |
| | | // if (days<30){ |
| | | // rentBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(days))); |
| | | // }else{ |
| | | // rentBill.setPayableFeesMoney(contract.getPayType().equals("1")?contract.getMonthRent(): |
| | | // contract.getPayType().equals("2")?contract.getMonthRent().multiply(new BigDecimal("3")):contract.getMonthRent().multiply(new BigDecimal("12")).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | // } |
| | | rentBill.setPayableFeesTime(firstPayTime); |
| | | rentBill.setPayFeesStatus("1"); |
| | | rentBill.setBillType("1"); |
| | | rentBill.setStartTime(contract.getStartPayTime()); |
| | | TContractRentType tContractRentType = contractRentTypes.stream().filter(e -> e.getContractId().equals(contract.getId())).findFirst().orElse(null); |
| | | // 进入签订审批流程 |
| | | ProcessStartBO processStartBO = new ProcessStartBO(); |
| | | processStartBO.setCategory(ProcessCategoryEnum.CATEGORY2.getValue().toString()); |
| | | processStartBO.setModuleName("合同签订审批"); |
| | | processStartBO.setName(contract.getContractName()); |
| | | processStartBO.setRemark(""); |
| | | Map<String, Object> variable = new HashMap<>(); |
| | | variable.put("projectId", dto.getId()); |
| | | processStartBO.setVariable(variable); |
| | | //开启工作流程 |
| | | stateProcessTemplateService.startApplet(processStartBO); |
| | | |
| | | if (tContractRentType!=null && contract.getStartPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).isAfter(tContractRentType.getChangeTime())){ |
| | | // 计算租金变动的天数 |
| | | long moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), contract.getStartPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12))+1L; |
| | | contract.setChangeTime(LocalDateTime.now()); |
| | | // 递增递减的租金 |
| | | BigDecimal contractRentTypeMoney = new BigDecimal("0"); |
| | | // 不递增递减的租金 |
| | | BigDecimal originalMoney = new BigDecimal("0"); |
| | | // 原租金 |
| | | switch (tContractRentType.getIncreasingDecreasingType()){ |
| | | case 1: |
| | | switch (tContractRentType.getIncreasingDecreasing()){ |
| | | case 1: |
| | | contractRentTypeMoney =contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN)).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays))); |
| | | contract.setChangeRent(contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).add(tContractRentType.getNumericalValue()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN)))); |
| | | break; |
| | | case 2: |
| | | contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).subtract(tContractRentType.getNumericalValue()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN)).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays))); |
| | | contract.setChangeRent(contractRentTypeMoney.add(contract.getChangeRent().multiply(new BigDecimal(100).subtract(tContractRentType.getNumericalValue()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN)))); |
| | | break; |
| | | } |
| | | break; |
| | | case 2: |
| | | switch (tContractRentType.getIncreasingDecreasing()){ |
| | | case 1: |
| | | contractRentTypeMoney =contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)); |
| | | contract.setChangeRent(contractRentTypeMoney.add(contract.getChangeRent().add(tContractRentType.getNumericalValue()))); |
| | | break; |
| | | case 2: |
| | | contractRentTypeMoney = contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue())).divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(moneyDays)); |
| | | contract.setChangeRent(contractRentTypeMoney.add(contract.getChangeRent().subtract(tContractRentType.getNumericalValue()))); |
| | | |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | // 不需要涨租金的时间段 |
| | | long originalDays = ChronoUnit.DAYS.between(contract.getFirstPayTime(), tContractRentType.getChangeTime()); |
| | | originalMoney=originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN)) |
| | | .multiply(new BigDecimal(originalDays)); |
| | | rentBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney)); |
| | | rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney()); |
| | | if (contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).isAfter(contract.getEndTime())){ |
| | | rentBill.setEndTime(contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12)); |
| | | }else{ |
| | | rentBill.setEndTime(contract.getEndTime()); |
| | | } |
| | | }else{ |
| | | if (contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12).isAfter(contract.getEndTime())){ |
| | | rentBill.setEndTime(contract.getFirstPayTime().plusMonths(contract.getPayType().equals("1")? 1:contract.getPayType().equals("2")? 3:12)); |
| | | }else{ |
| | | rentBill.setEndTime(contract.getEndTime()); |
| | | } |
| | | // 不走递增递减 |
| | | long allDays = ChronoUnit.DAYS.between(contract.getFirstPayTime(), rentBill.getEndTime()); |
| | | rentBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(allDays))); |
| | | rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney()); |
| | | |
| | | } |
| | | // 租金账单 |
| | | bills.add(rentBill); |
| | | // 押金账单 |
| | | TBill depositBill = new TBill(); |
| | | depositBill.setContractId(contract.getId()); |
| | | depositBill.setContractNumber(contract.getContractNumber()); |
| | | depositBill.setPayableFeesMoney(contract.getDeposit()); |
| | | depositBill.setOutstandingMoney(depositBill.getPayableFeesMoney()); |
| | | |
| | | depositBill.setPayableFeesTime(firstPayTime); |
| | | depositBill.setPayFeesStatus("1"); |
| | | depositBill.setBillType("2"); |
| | | bills.add(depositBill); |
| | | this.updateById(contract); |
| | | billService.saveBatch(bills); |
| | | // 用户签订合同后 生成第一批账单包含租金账单和押金账单 后续账单通过定时任务生成 |
| | | // TBill rent = new TBill(); |
| | | // rent.setContractId(contract.getId()); |
| | | // // 应缴费租金 |
| | | // BigDecimal payableFeesMoney = new BigDecimal("0"); |
| | | // LocalDateTime startTime = contract.getStartTime(); |
| | | // LocalDateTime endTime = contract.getEndTime(); |
| | | // // 计算相差多少天 |
| | | // long days = ChronoUnit.DAYS.between(startTime, endTime); |
| | | // // 计算相差多少个月 |
| | | // long months = ChronoUnit.MONTHS.between(startTime, endTime); |
| | | // if (months<=31){ |
| | | // // 小于等于一个月 合计租金就是首笔账单金额 |
| | | // payableFeesMoney = contract.getTotalRent(); |
| | | // }else{ |
| | | // switch (contract.getPayType()){ |
| | | // case "1": |
| | | // break; |
| | | // case "2": |
| | | // break; |
| | | // case "3": |
| | | // break; |
| | | // } |
| | | // } |
| | | // |
| | | // rent.setPayableFeesMoney(payableFeesMoney); |
| | | // rent.setPayableFeesTime(contract.getFirstPayTime()); |
| | | // rent.setPayFeesStatus("1"); |
| | | // rent.setBillType("1"); |
| | | // |
| | | // TBill deposit = new TBill(); |
| | | // deposit.setContractId(contract.getId()); |
| | | // deposit.setPayableFeesMoney(contract.getDeposit()); |
| | | // deposit.setPayableFeesTime(contract.getFirstPayTime()); |
| | | // deposit.setPayFeesStatus("1"); |
| | | // deposit.setBillType("2"); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateContractAuditStatus(String projectId, Integer status) { |
| | | LambdaUpdateWrapper<TContract> contractLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); |
| | | contractLambdaUpdateWrapper |
| | | .eq(TContract::getId, projectId) |
| | | .set(TContract::getStatus, status) |
| | | .set(TContract::getSignTime, LocalDateTime.now()); |
| | | return this.update(contractLambdaUpdateWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 本月新增租户数 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getCurrentMonthRentCount(String businessDeptId) { |
| | | return baseMapper.getCurrentMonthRentCount(businessDeptId); |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<TContract> queryPage(TContractQuery query) { |
| | | PageInfo<TContract> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | pageInfo = this.baseMapper.page(pageInfo,query); |
| | | return pageInfo; |
| | | } |
| | | |
| | | } |