无关风月
2025-01-22 7f526d5cb45584c35653f136483e40cb60b5d0bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.dto.TContractDTO;
import com.ruoyi.system.dto.THouseDTO;
import com.ruoyi.system.model.TContract;
import com.ruoyi.system.model.TContractRentType;
import com.ruoyi.system.model.THouse;
import com.ruoyi.system.query.TContractQuery;
import com.ruoyi.system.query.THouseQuery;
import com.ruoyi.system.query.TUserHistoryQuery;
import com.ruoyi.system.service.TContractRentTypeService;
import com.ruoyi.system.service.TContractService;
import com.ruoyi.system.service.THouseService;
import com.ruoyi.system.vo.HouseVO;
import io.swagger.annotations.Api;
import com.ruoyi.system.vo.TContractVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
 
/**
 * <p>
 * 合同管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-01-17
 */
@Api(tags = "合同管理")
@RestController
@RequestMapping("/t-contract")
public class TContractController {
    @Autowired
    private TContractService contractService;
    @Autowired
    private TContractRentTypeService contractRentTypeService;
    @Autowired
    private THouseService houseService;
    @ApiOperation(value = "获取合同分页列表")
    @PostMapping(value = "/contractList")
    public R<PageInfo<TContract>> contractList(@RequestBody TContractQuery query) {
        return R.ok(contractService.contractList(query));
    }
    @Log(title = "合同管理-新增合同", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增合同")
    @PostMapping(value = "/addContract")
    public R<Boolean> addContract(@Validated @RequestBody TContractDTO dto) {
        contractService.save(dto);
        if (dto.getIsIncreasing()==1){
            TContractRentType tContractRentType = new TContractRentType();
            tContractRentType.setContractId(dto.getId());
            tContractRentType.setIncreasingDecreasing(dto.getIncreasingDecreasing());
            tContractRentType.setIncreasingDecreasingType(dto.getIncreasingDecreasingType());
            tContractRentType.setNumericalValue(dto.getNumericalValue());
            tContractRentType.setChangeTime(dto.getChangeTime());
            contractRentTypeService.save(tContractRentType);
        }
        return R.ok();
    }
    @Log(title = "合同管理-编辑合同", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "编辑合同")
    @PostMapping(value = "/updateContract")
    public R<Boolean> updateContract(@Validated @RequestBody TContractDTO dto) {
        contractService.updateById(dto);
        contractRentTypeService.remove(new LambdaQueryWrapper<TContractRentType>()
                .eq(TContractRentType::getContractId,dto.getId()));
        if (dto.getIsIncreasing()==1){
            TContractRentType tContractRentType = new TContractRentType();
            tContractRentType.setContractId(dto.getId());
            tContractRentType.setIncreasingDecreasing(dto.getIncreasingDecreasing());
            tContractRentType.setIncreasingDecreasingType(dto.getIncreasingDecreasingType());
            tContractRentType.setNumericalValue(dto.getNumericalValue());
            tContractRentType.setChangeTime(dto.getChangeTime());
            contractRentTypeService.save(tContractRentType);
        }
        return R.ok();
    }
    @Log(title = "合同管理-批量删除合同", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除合同")
    @DeleteMapping(value = "/deleteContractByIds")
    public R<Boolean> deleteContractByIds3
            (@RequestParam String ids) {
        if (StringUtils.isNotEmpty(ids)){
            contractService.removeBatchByIds(Arrays.asList(ids.split(",")));
        }
        return R.ok();
    }
 
    @ApiOperation(value = "查询合同信息信息")
    @GetMapping(value = "/getContractById")
    public R<TContractVO> getContractById(@RequestParam Long id) {
        TContractVO res = new TContractVO();
        TContract contract = contractService.getById(id);
        BeanUtils.copyProperties(contract,res);
        TContractRentType contractRentType = contractRentTypeService.lambdaQuery().eq(TContractRentType::getContractId, id).one();
        if (contractRentType!=null){
            BeanUtils.copyProperties(contractRentType,res);
        }
        TContract oldContract = contractService.getOne(new LambdaQueryWrapper<TContract>()
                        .eq(TContract::getHouseId,contract.getHouseId())
                .eq(TContract::getStatus, 4)
                .le(TContract::getStartTime, LocalDateTime.now())
                .ge(TContract::getEndTime, LocalDateTime.now()));
        THouse house = houseService.getById(contract.getHouseId());
        if (oldContract!=null){
            house.setTenantType(oldContract.getPayType());
        }
        res.setHouse(house);
        return R.ok(res);
    }
 
}