提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.controller.admin.definition;
H 2
3 import com.iailab.framework.common.enums.CommonStatusEnum;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.util.object.BeanUtils;
7 import com.iailab.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
8 import com.iailab.module.bpm.controller.admin.definition.vo.category.BpmCategoryRespVO;
9 import com.iailab.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
10 import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO;
11 import com.iailab.module.bpm.service.definition.BpmCategoryService;
12 import io.swagger.v3.oas.annotations.Operation;
13 import io.swagger.v3.oas.annotations.Parameter;
14 import io.swagger.v3.oas.annotations.tags.Tag;
15 import org.springframework.security.access.prepost.PreAuthorize;
16 import org.springframework.validation.annotation.Validated;
17 import org.springframework.web.bind.annotation.*;
18
19 import javax.annotation.Resource;
20 import javax.validation.Valid;
21 import java.util.Comparator;
22 import java.util.List;
23
24 import static com.iailab.framework.common.pojo.CommonResult.success;
25 import static com.iailab.framework.common.util.collection.CollectionUtils.convertList;
26
27 @Tag(name = "管理后台 - BPM 流程分类")
28 @RestController
29 @RequestMapping("/bpm/category")
30 @Validated
31 public class BpmCategoryController {
32
33     @Resource
34     private BpmCategoryService categoryService;
35
36     @PostMapping("/create")
37     @Operation(summary = "创建流程分类")
38     @PreAuthorize("@ss.hasPermission('bpm:category:create')")
39     public CommonResult<Long> createCategory(@Valid @RequestBody BpmCategorySaveReqVO createReqVO) {
40         return success(categoryService.createCategory(createReqVO));
41     }
42
43     @PutMapping("/update")
44     @Operation(summary = "更新流程分类")
45     @PreAuthorize("@ss.hasPermission('bpm:category:update')")
46     public CommonResult<Boolean> updateCategory(@Valid @RequestBody BpmCategorySaveReqVO updateReqVO) {
47         categoryService.updateCategory(updateReqVO);
48         return success(true);
49     }
50
bb2880 51     @PutMapping("/update-sort-batch")
H 52     @Operation(summary = "批量更新流程分类的排序")
53     @Parameter(name = "ids", description = "分类编号列表", required = true, example = "1,2,3")
54     @PreAuthorize("@ss.hasPermission('bpm:category:update')")
55     public CommonResult<Boolean> updateCategorySortBatch(@RequestParam("ids") List<Long> ids) {
56         categoryService.updateCategorySortBatch(ids);
57         return success(true);
58     }
59
e7c126 60     @DeleteMapping("/delete")
H 61     @Operation(summary = "删除流程分类")
62     @Parameter(name = "id", description = "编号", required = true)
63     @PreAuthorize("@ss.hasPermission('bpm:category:delete')")
64     public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
65         categoryService.deleteCategory(id);
66         return success(true);
67     }
68
69     @GetMapping("/get")
70     @Operation(summary = "获得流程分类")
71     @Parameter(name = "id", description = "编号", required = true, example = "1024")
72     @PreAuthorize("@ss.hasPermission('bpm:category:query')")
73     public CommonResult<BpmCategoryRespVO> getCategory(@RequestParam("id") Long id) {
74         BpmCategoryDO category = categoryService.getCategory(id);
75         return success(BeanUtils.toBean(category, BpmCategoryRespVO.class));
76     }
77
78     @GetMapping("/page")
79     @Operation(summary = "获得流程分类分页")
80     @PreAuthorize("@ss.hasPermission('bpm:category:query')")
81     public CommonResult<PageResult<BpmCategoryRespVO>> getCategoryPage(@Valid BpmCategoryPageReqVO pageReqVO) {
82         PageResult<BpmCategoryDO> pageResult = categoryService.getCategoryPage(pageReqVO);
83         return success(BeanUtils.toBean(pageResult, BpmCategoryRespVO.class));
84     }
85
86     @GetMapping("/simple-list")
87     @Operation(summary = "获取流程分类的精简信息列表", description = "只包含被开启的分类,主要用于前端的下拉选项")
88     public CommonResult<List<BpmCategoryRespVO>> getCategorySimpleList() {
89         List<BpmCategoryDO> list = categoryService.getCategoryListByStatus(CommonStatusEnum.ENABLE.getStatus());
90         list.sort(Comparator.comparingInt(BpmCategoryDO::getSort));
91         return success(convertList(list, category -> new BpmCategoryRespVO().setId(category.getId())
92                 .setName(category.getName()).setCode(category.getCode())));
93     }
94
95 }