潘志宝
2024-11-01 8c16467e31803d9e9873b4e34c307f5e242da1f8
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.plan.category.controller.admin;
 
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.data.plan.category.entity.PlanItemCategoryEntity;
import com.iailab.module.data.plan.category.service.PlanItemCategoryService;
import com.iailab.module.data.plan.category.vo.PlanItemCategoryReqVO;
import com.iailab.module.data.plan.category.vo.PlanItemCategoryRespVO;
import com.iailab.module.data.plan.category.vo.PlanItemCategorySaveReqVO;
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年11月01日
 */
@Tag(name = "数据平台 - 计划分类")
@RestController
@RequestMapping("/data/plan/category")
@Validated
public class PlanItemCategoryController {
 
    @Autowired
    private PlanItemCategoryService indItemCategoryService;
 
    @GetMapping("/list")
    @Operation(summary = "获取计划分类列表", description = "用于【计划分类】界面")
    @PreAuthorize("@ss.hasPermission('data:plan-item-category:query')")
    public CommonResult<List<PlanItemCategoryRespVO>> getList(PlanItemCategoryReqVO reqVO) {
        List<PlanItemCategoryEntity> list = indItemCategoryService.getList(reqVO);
        list.sort(Comparator.comparing(PlanItemCategoryEntity::getSort));
        return success(BeanUtils.toBean(list, PlanItemCategoryRespVO.class));
    }
 
    @GetMapping("/list-all-simple")
    @Operation(summary = "获取计划分类列表", description = "用于【计划分类】界面")
    @PreAuthorize("@ss.hasPermission('data:plan-item-category:query')")
    public CommonResult<List<PlanItemCategoryRespVO>> getList() {
        List<PlanItemCategoryEntity> list = indItemCategoryService.getSimpleList();
        list.sort(Comparator.comparing(PlanItemCategoryEntity::getSort));
        return success(BeanUtils.toBean(list, PlanItemCategoryRespVO.class));
    }
 
    @PostMapping("/create")
    @Operation(summary = "创建计划分类")
    @PreAuthorize("@ss.hasPermission('data:plan-item-category:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody PlanItemCategorySaveReqVO createReqVO) {
        indItemCategoryService.create(createReqVO);
        return success(true);
    }
 
    @PutMapping("/update")
    @Operation(summary = "修改计划分类")
    @PreAuthorize("@ss.hasPermission('data:plan-item-category:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody PlanItemCategorySaveReqVO updateReqVO) {
        indItemCategoryService.update(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除计划分类")
    @Parameter(name = "id", description = "计划分类编号", required= true, example = "1024")
    @PreAuthorize("@ss.hasPermission('data:plan-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:plan-item-category:query')")
    public CommonResult<PlanItemCategoryRespVO> get(String id) {
        PlanItemCategoryEntity entity = indItemCategoryService.get(id);
        return success(BeanUtils.toBean(entity, PlanItemCategoryRespVO.class));
    }
}