潘志宝
2024-12-15 bbe7acfbe5a4c08d6edc91eaf81dcecf9d630e18
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
package com.iailab.module.data.ind.category.controller.admin;
 
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.data.ind.category.entity.IndItemCategoryEntity;
import com.iailab.module.data.ind.category.service.IndItemCategoryService;
import com.iailab.module.data.ind.category.vo.IndItemCategoryReqVO;
import com.iailab.module.data.ind.category.vo.IndItemCategoryRespVO;
import com.iailab.module.data.ind.category.vo.IndItemCategorySaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
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.*;
 
import javax.validation.Valid;
import java.util.Comparator;
import java.util.List;
 
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年09月10日
 */
@Tag(name = "数据平台 - 指标分类")
@RestController
@RequestMapping("/data/ind/category")
@Validated
public class IndItemCategoryController {
 
    @Autowired
    private IndItemCategoryService indItemCategoryService;
 
    @GetMapping("/list")
    @Operation(summary = "获取指标分类列表", description = "用于【指标分类】界面")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:query')")
    public CommonResult<List<IndItemCategoryRespVO>> getList(IndItemCategoryReqVO reqVO) {
        List<IndItemCategoryEntity> list = indItemCategoryService.getList(reqVO);
        list.sort(Comparator.comparing(IndItemCategoryEntity::getSort));
        return success(BeanUtils.toBean(list, IndItemCategoryRespVO.class));
    }
 
    @GetMapping("/list-all-simple")
    @Operation(summary = "获取指标分类列表", description = "用于【指标分类】界面")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:query')")
    public CommonResult<List<IndItemCategoryRespVO>> getList() {
        List<IndItemCategoryEntity> list = indItemCategoryService.getSimpleList();
        list.sort(Comparator.comparing(IndItemCategoryEntity::getSort));
        return success(BeanUtils.toBean(list, IndItemCategoryRespVO.class));
    }
 
    @PostMapping("/create")
    @Operation(summary = "创建指标分类")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody IndItemCategorySaveReqVO createReqVO) {
        indItemCategoryService.create(createReqVO);
        return success(true);
    }
 
    @PutMapping("/update")
    @Operation(summary = "修改指标分类")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody IndItemCategorySaveReqVO updateReqVO) {
        indItemCategoryService.update(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除指标分类")
    @Parameter(name = "id", description = "指标分类编号", required= true, example = "1024")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
        indItemCategoryService.delete(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获取指标分类信息")
    @PreAuthorize("@ss.hasPermission('data:ind-item-category:query')")
    public CommonResult<IndItemCategoryRespVO> get(String id) {
        IndItemCategoryEntity entity = indItemCategoryService.get(id);
        return success(BeanUtils.toBean(entity, IndItemCategoryRespVO.class));
    }
}