潘志宝
2024-09-03 f7e880deb0612ba5efe96e6ce229abd8c19bc6e7
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.ind.controller.admin;
H 2
3 import com.iailab.framework.common.annotation.AutoDict;
4 import com.iailab.framework.common.constant.Constant;
5 import com.iailab.framework.common.page.PageData;
6 import com.iailab.framework.common.pojo.CommonResult;
7 import com.iailab.framework.common.util.validation.ValidationUtils;
8 import com.iailab.framework.common.validation.group.AddGroup;
9 import com.iailab.framework.common.validation.group.DefaultGroup;
10 import com.iailab.module.data.ind.service.IndItemService;
11 import com.iailab.module.data.ind.dto.IndItemDTO;
12 import io.swagger.v3.oas.annotations.Operation;
13 import io.swagger.v3.oas.annotations.Parameter;
14 import io.swagger.v3.oas.annotations.Parameters;
15 import javax.annotation.Resource;
16 import org.springframework.security.access.prepost.PreAuthorize;
17 import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.web.bind.annotation.*;
19
20 import java.util.List;
21 import java.util.Map;
22
23 /**
24  * @author PanZhibao
25  * @Description
26  * @createTime 2024年05月25日
27  */
28 @RestController
29 @RequestMapping("/ind/item")
30 public class IndItemController {
31
32     @Resource
33     private IndItemService indItemService;
34
35     @GetMapping("page")
36     @Operation(summary = "分页")
37     @Parameters({
38             @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
39             @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
40             @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
41             @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)")
42     })
43     @AutoDict
44     public CommonResult<PageData<IndItemDTO>> page(@RequestParam Map<String, Object> params) {
45         PageData<IndItemDTO> page = indItemService.page(params);
46
47         return new CommonResult<PageData<IndItemDTO>>().setData(page);
48     }
49
50     @GetMapping("list")
51     @AutoDict
52     public CommonResult<List<IndItemDTO>> list(@RequestParam Map<String, Object> params) {
53         List<IndItemDTO> list = indItemService.getList(params);
54         return new CommonResult<List<IndItemDTO>>().setData(list);
55     }
56
57     @GetMapping("{id}")
58     @Operation(summary = "信息")
59     public CommonResult<IndItemDTO> get(@PathVariable("id") String id) {
60         IndItemDTO data = indItemService.get(id);
61
62         return new CommonResult<IndItemDTO>().setData(data);
63     }
64
65     @PostMapping
66     @Operation(summary = "保存")
67     @PreAuthorize("@ss.hasPermission('ind:item:save')")
68     public CommonResult save(@RequestBody IndItemDTO dto){
69         //效验数据
70         ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class);
71         IndItemDTO data = indItemService.getItemByItemNo(dto.getItemNo());
72         if(data != null){
73             return new CommonResult().setMsg("指标编码已经存在,请重新定义指标编码!");
74         }
75         indItemService.save(dto);
76         return new CommonResult();
77     }
78
79     @PutMapping
80     @Operation(summary = "修改")
81     @PreAuthorize("@ss.hasPermission('ind:item:update')")
82     public CommonResult update(@RequestBody IndItemDTO dto){
83         //效验数据
84         ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class);
85         indItemService.update(dto);
86         return new CommonResult();
87     }
88
89     @DeleteMapping
90     @Operation(summary = "删除")
91     @PreAuthorize("@ss.hasPermission('ind:item:delete')")
92     public CommonResult delete(@RequestBody String[] ids){
93         indItemService.delete(ids);
94         return new CommonResult();
95     }
96
97     @PutMapping("/enable")
98     @Operation(summary = "启用")
99     @Transactional
100     public CommonResult enable(@RequestBody String[] ids) {
101         indItemService.enableByIds(ids);
102         return new CommonResult();
103     }
104
105     @PutMapping("/disable")
106     @Operation(summary = "禁用")
107     @Transactional
108     public CommonResult disable(@RequestBody String[] ids) {
109         indItemService.disableByIds(ids);
110         return new CommonResult();
111     }
112 }