ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
@@ -37,6 +37,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -72,12 +73,15 @@ private TCheckAcceptRecordService checkAcceptRecordService; @ApiOperation(value = "获取合同分页列表") @PostMapping(value = "/contractList") @PreAuthorize("@ss.hasPermi('system:contract:list')") public R<PageInfo<TContract>> contractList(@RequestBody TContractQuery query) { return R.ok(contractService.contractList(query)); } @Log(title = "合同管理-新增合同", businessType = BusinessType.INSERT) @ApiOperation(value = "新增合同") @PostMapping(value = "/addContract") @PreAuthorize("@ss.hasPermi('system:contract:add')") public R<Boolean> addContract(@Validated @RequestBody TContractDTO dto) { contractService.save(dto); if (dto.getIsIncreasing()){ ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDeptController.java
@@ -6,7 +6,6 @@ import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.dto.TDeptUpAndDownDTO; ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/THouseController.java
@@ -22,6 +22,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -45,18 +46,21 @@ @Log(title = "房屋基础信息管理-新增房屋", businessType = BusinessType.INSERT) @ApiOperation(value = "新增房屋") @PostMapping(value = "/addHouse") @PreAuthorize("@ss.hasPermi('system:house:add')") public R<Boolean> addHouse(@Validated @RequestBody THouseDTO dto) { return R.ok(tHouseService.save(dto)); } @Log(title = "房屋基础信息管理-编辑房屋", businessType = BusinessType.UPDATE) @ApiOperation(value = "编辑房屋") @PostMapping(value = "/updateHouse") @PreAuthorize("@ss.hasPermi('system:house:edit')") public R<Boolean> updateHouse(@Validated @RequestBody THouseDTO dto) { return R.ok(tHouseService.updateById(dto)); } @Log(title = "房屋基础信息管理-查询房屋信息", businessType = BusinessType.DELETE) @ApiOperation(value = "查询房屋信息") @GetMapping(value = "/getHouseById") @PreAuthorize("@ss.hasPermi('system:house:detail')") public R<THouse> getHouseById(@RequestParam String id) { THouse tHouse = tHouseService.getById(id); tHouse.setLeaseStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_LEASE_STATUS,tHouse.getLeaseStatus())); @@ -66,16 +70,21 @@ @Log(title = "房屋基础信息管理-删除房屋", businessType = BusinessType.DELETE) @ApiOperation(value = "删除房屋") @DeleteMapping(value = "/deleteHouseById") @PreAuthorize("@ss.hasPermi('system:house:delete')") public R<Boolean> deleteHouseById(@RequestParam String id) { return R.ok(tHouseService.removeById(id)); } @ApiOperation(value = "获取房屋分页列表") @PostMapping(value = "/houseList") @PreAuthorize("@ss.hasPermi('system:house:list')") public R<PageInfo<THouse>> houseList(@RequestBody THouseQuery query) { return R.ok(tHouseService.houseList(query)); } @ApiOperation(value = "历史租户列表") @PostMapping(value = "/userHistoryList") @PreAuthorize("@ss.hasPermi('system:house:historyList')") public R<PageInfo<HouseVO>> userHistoryList(@RequestBody TUserHistoryQuery query) { return R.ok(tHouseService.userHistoryList(query)); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
@@ -64,13 +64,14 @@ if (days<30){ rentBill.setPayableFeesMoney(contract.getMonthRent().divide(new BigDecimal("30"),2,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(days))); }else{ rentBill.setPayableFeesMoney(contract.getMonthRent()); 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()); if (contract.getEndTime().getYear() == contract.getStartTime().getYear() && contract.getEndTime().getMonth() == contract.getStartTime().getMonth()) { if ((contract.getEndTime().getYear() == contract.getStartTime().getYear()) && (contract.getEndTime().getMonth() == contract.getStartTime().getMonth())) { // 如果同年同月 那么账单周期为合同结束时间 rentBill.setEndTime(contract.getEndTime()); } else { @@ -96,74 +97,64 @@ e.printStackTrace(); } } // 每天凌晨00点执行的定时任务 用于生成合同期最后一笔账单 @Scheduled(cron = "0 0 0 * * ?") public void dayOfEndBill() { try { // 查询所有已签订的合同并且已经生成第一笔账单的 List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4).isNotNull(TContract::getFirstPayTime).list(); List<TBill> bills = new ArrayList<>(); for (TContract contract : list) { TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime) .last("limit 1").one(); if (!(beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate()))&&beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).isAfter(contract.getEndTime())){ TBill tBill = new TBill(); tBill.setContractId(contract.getId()); tBill.setContractNumber(contract.getContractNumber()); tBill.setPayableFeesMoney(contract.getMonthRent()); tBill.setPayableFeesTime(LocalDateTime.now()); tBill.setPayFeesStatus("1"); tBill.setBillType("1"); tBill.setStartTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth())); tBill.setEndTime(contract.getEndTime()); bills.add(tBill); } } billService.saveBatch(bills); } catch (Exception e) { e.printStackTrace(); } } // 每月15号凌晨执行的定时任务 用于生成租金账单 @Scheduled(cron = "0 0 0 15 * ?") public void monthOfBill() { try { // 查询所有已签订的合同 List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4).isNotNull(TContract::getFirstPayTime).list(); // 查询所有已签订的合同 且合同时间大于15号 List<TContract> list = contractService.lambdaQuery().eq(TContract::getStatus, 4) .isNotNull(TContract::getFirstPayTime) .ge(TContract::getEndTime, LocalDateTime.now()) .list(); List<TBill> bills = new ArrayList<>(); for (TContract contract : list) { TBill beforeBill = billService.lambdaQuery().eq(TBill::getContractId, contract.getId()).eq(TBill::getBillType, 1).orderByDesc(TBill::getCreateTime) .last("limit 1").one(); if (beforeBill.getEndTime().toLocalDate().equals(contract.getEndTime().toLocalDate()))continue; if (beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).isBefore(contract.getEndTime())){ TBill tBill = new TBill(); LocalDateTime endTime = contract.getEndTime(); if (endTime.isBefore(LocalDateTime.now())){ // 最后缴费日期是当天 tBill.setContractId(contract.getId()); tBill.setContractNumber(contract.getContractNumber()); tBill.setPayableFeesMoney(contract.getMonthRent()); // tBill.setPayableFeesTime(); tBill.setPayableFeesTime(LocalDateTime.now()); tBill.setPayFeesStatus("1"); tBill.setBillType("1"); tBill.setStartTime(contract.getStartPayTime()); // 如果同年同月 那么账单周期为合同结束时间 tBill.setEndTime(contract.getEndTime()); tBill.setStartTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth())); tBill.setEndTime(beforeBill.getEndTime().plusMonths(1).with(TemporalAdjusters.lastDayOfMonth())); bills.add(tBill); } contract.setFirstPayTime(contract.getStartTime().plusDays(10)); // 第一次应缴费日期 LocalDateTime firstPayTime = contract.getStartTime().plusDays(10); LocalDate localDate = contract.getStartTime().plusDays(10).toLocalDate(); LocalDate now = LocalDate.now(); switch (contract.getPayType()){ case "1": break; case "2": break; case "3": break; } if (!localDate.equals(now)) { continue; } TBill rentBill = new TBill(); rentBill.setContractId(contract.getId()); rentBill.setContractNumber(contract.getContractNumber()); rentBill.setPayableFeesMoney(contract.getMonthRent()); rentBill.setPayableFeesTime(firstPayTime); rentBill.setPayFeesStatus("1"); rentBill.setBillType("1"); rentBill.setStartTime(contract.getStartPayTime()); if (contract.getEndTime().getYear() == contract.getStartTime().getYear() && contract.getEndTime().getMonth() == contract.getStartTime().getMonth()) { // 如果同年同月 那么账单周期为合同结束时间 rentBill.setEndTime(contract.getEndTime()); } else { // 否则 取当月最后一天 // LocalDateTime endTime = contract.getStartTime().with(TemporalAdjusters.lastDayOfMonth()).withSecond(59).withHour(23).withMinute(59); rentBill.setEndTime(endTime); } // 租金账单 bills.add(rentBill); // 押金账单 TBill depositBill = new TBill(); depositBill.setContractId(contract.getId()); depositBill.setContractNumber(contract.getContractNumber()); depositBill.setPayableFeesMoney(contract.getDeposit()); depositBill.setPayableFeesTime(firstPayTime); depositBill.setPayFeesStatus("1"); depositBill.setBillType("2"); bills.add(depositBill); } contractService.updateBatchById(list); billService.saveBatch(bills); } catch (Exception e) { e.printStackTrace(); @@ -172,7 +163,11 @@ public static void main(String[] args) { LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now().minusMonths(1).withDayOfMonth(31); System.err.println(now); LocalDateTime now2 = now.plusMonths(1); System.err.println(now2); LocalDateTime now1 = LocalDateTime.now(); long days = ChronoUnit.DAYS.between(now, now1); long days2 = ChronoUnit.DAYS.between(now.plusDays(1), now1); ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java
@@ -52,7 +52,7 @@ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @TableField("end_time") private LocalDateTime endTime; @ApiModelProperty(value = "开始计费事件") @ApiModelProperty(value = "开始计费时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @TableField("start_pay_time") private LocalDateTime startPayTime; ruoyi-system/src/main/java/com/ruoyi/system/service/TDeptService.java
@@ -1,7 +1,6 @@ package com.ruoyi.system.service; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.system.dto.TDeptUpAndDownDTO; import com.ruoyi.system.model.TDept; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.system.query.TDeptQuery; ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDeptServiceImpl.java
@@ -3,7 +3,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.dto.TDeptUpAndDownDTO; import com.ruoyi.system.mapper.SysMenuMapper; import com.ruoyi.system.model.TDept; import com.ruoyi.system.mapper.TDeptMapper; import com.ruoyi.system.query.TDeptQuery; @@ -13,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; /** @@ -27,6 +26,8 @@ @Service public class TDeptServiceImpl extends ServiceImpl<TDeptMapper, TDept> implements TDeptService { @Autowired private SysMenuMapper sysMenuMapper; @Override public boolean isExit(TDept dto) { if(StringUtils.isNotEmpty(dto.getDeptId())){ @@ -46,4 +47,5 @@ return pageInfo; } }