xuhy
2025-07-16 4708af66b7eb6246e5ffdc3c7957f12ceaa7e567
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
128
129
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.model.YcFinancialManagement;
import com.ruoyi.system.model.YcRevenueExpenditureType;
import com.ruoyi.system.service.YcFinancialManagementService;
import com.ruoyi.system.service.YcRevenueExpenditureTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 收支类型表 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-07-15
 */
@Api(tags = "收支类型表")
@RestController
@RequestMapping("/yc-revenue-expenditure-type")
public class YcRevenueExpenditureTypeController {
 
    private final YcRevenueExpenditureTypeService ycRevenueExpenditureTypeService;
    private final YcFinancialManagementService ycFinancialManagementService;
 
    @Autowired
    public YcRevenueExpenditureTypeController(YcRevenueExpenditureTypeService ycRevenueExpenditureTypeService, YcFinancialManagementService ycFinancialManagementService) {
        this.ycRevenueExpenditureTypeService = ycRevenueExpenditureTypeService;
        this.ycFinancialManagementService = ycFinancialManagementService;
    }
 
    /**
     * 查询收支类型列表
     */
    @ApiOperation( value = "查询收支类型分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<YcRevenueExpenditureType>> pageList(@RequestBody BasePage query) {
        return R.ok(ycRevenueExpenditureTypeService.pageList(query));
    }
 
    /**
     * 查询收支类型列表
     */
    @ApiOperation( value = "查询收支类型列表,类型查询必传")
    @GetMapping(value = "/typeList")
    public R<List<YcRevenueExpenditureType>> list(@RequestParam(value = "typeName",required = false) String typeName,
                                                          @RequestParam(value = "revenueType") Integer revenueType) {
        LambdaQueryWrapper<YcRevenueExpenditureType> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.hasLength(typeName)){
            wrapper.like(YcRevenueExpenditureType::getTypeName, typeName);
        }
        wrapper.eq(YcRevenueExpenditureType::getRevenueType, revenueType);
        List<YcRevenueExpenditureType> list = ycRevenueExpenditureTypeService.list(wrapper);
        return R.ok(list);
    }
 
    /**
     * 查询收支类型列表
     */
    @ApiOperation( value = "查询收支类型列表,不传类型")
    @GetMapping(value = "/list")
    public R<List<YcRevenueExpenditureType>> pageList(@RequestParam(value = "typeName",required = false) String typeName) {
        LambdaQueryWrapper<YcRevenueExpenditureType> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.hasLength(typeName)){
            wrapper.like(YcRevenueExpenditureType::getTypeName, typeName);
        }
        List<YcRevenueExpenditureType> list = ycRevenueExpenditureTypeService.list(wrapper);
        return R.ok(list);
    }
 
    /**
     * 添加收支类型管理
     */
    @ApiOperation( value = "添加收支类型")
    @Log(title = "收支类型-添加", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public R<Boolean> add(@RequestBody YcRevenueExpenditureType dto) {
        return R.ok(ycRevenueExpenditureTypeService.save(dto));
    }
 
    /**
     * 修改收支类型
     */
    @ApiOperation( value = "修改收支类型")
    @Log(title = "收支类型-修改", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public R<Boolean> update(@RequestBody YcRevenueExpenditureType dto) {
        return R.ok(ycRevenueExpenditureTypeService.updateById(dto));
    }
 
    /**
     * 查看收支类型详情
     */
    @ApiOperation( value = "查看收支类型详情")
    @GetMapping(value = "/getDetailById")
    public R<YcRevenueExpenditureType> getDetailById(@RequestParam("id") Long id) {
        return R.ok(ycRevenueExpenditureTypeService.getById(id));
    }
 
    /**
     * 删除收支类型
     */
    @ApiOperation( value = "删除收支类型")
    @Log(title = "收支类型-删除", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam("id") Long id) {
        // 查询分类是否在财务管理里面存在
        long count = ycFinancialManagementService.count(Wrappers.lambdaQuery(YcFinancialManagement.class)
                .eq(YcFinancialManagement::getTypeId, id));
        if(count>0){
            return R.fail("该分类在财务管理中正在使用,无法删除");
        }
        return R.ok(ycRevenueExpenditureTypeService.removeById(id));
    }
 
}