潘志宝
2024-08-21 4d3533b6e75e6afa5af325288b03915715add4b6
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.point.controller.admin;
H 2
3 import com.iailab.framework.common.constant.Constant;
4 import com.iailab.framework.common.page.PageData;
5 import com.iailab.framework.common.pojo.CommonResult;
6 import com.iailab.framework.common.util.validation.ValidationUtils;
7 import com.iailab.framework.common.validation.group.AddGroup;
8 import com.iailab.framework.common.validation.group.UpdateGroup;
9 import com.iailab.framework.common.validation.group.DefaultGroup;
10 import com.iailab.module.data.point.dto.DaPointDTO;
11 import com.iailab.module.data.point.service.DaPointService;
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 javax.annotation.security.PermitAll;
17 import javax.validation.Valid;
18
19 import io.swagger.v3.oas.annotations.tags.Tag;
20 import org.springframework.security.access.prepost.PreAuthorize;
21 import org.springframework.transaction.annotation.Transactional;
22 import org.springframework.validation.annotation.Validated;
23 import org.springframework.web.bind.annotation.*;
24
25 import java.util.List;
26 import java.util.Map;
27
28 import static com.iailab.framework.common.pojo.CommonResult.success;
29
30
31 /**
32  * @author PanZhibao
33  * @Description
34  * @createTime 2024年05月12日
35  */
36 @Tag(name = "数据采集,测点")
37 @RestController
38 @RequestMapping("/data/da/point")
39 @Validated
40 public class DaPointController {
41
42     @Resource
43     private DaPointService daPointService;
44
45     @GetMapping("page")
46     @Operation(summary = "分页")
47     @Parameters({
48             @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) ,
49             @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) ,
50             @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") ,
51             @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)")
52     })
53     @PreAuthorize("@ss.hasPermission('data:point:query')")
54     public CommonResult<PageData<DaPointDTO>> page(@RequestParam Map<String, Object> params){
55         PageData<DaPointDTO> page = daPointService.page(params);
56
57         return success(page);
58     }
59
60     @GetMapping("{id}")
61     @Operation(summary = "信息")
62     @PreAuthorize("@ss.hasPermission('data:point:query')")
63     public CommonResult<DaPointDTO> get(@PathVariable("id") String id){
64         DaPointDTO data = daPointService.get(id);
65
66         return new CommonResult<DaPointDTO>().setData(data);
67     }
68
69     @GetMapping("/list")
70     @Operation(summary = "列表")
71     @PreAuthorize("@ss.hasPermission('data:point:query')")
72     public CommonResult<List<DaPointDTO>> list(@Valid @RequestParam Map<String, Object> params) {
73         List<DaPointDTO> list = daPointService.list(params);
74         return success(list);
75     }
76
77     @PostMapping
78     @Operation(summary = "保存")
79     @PreAuthorize("@ss.hasPermission('data:point:save')")
80     public CommonResult save(@RequestBody DaPointDTO dto){
81         //效验数据
82         ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class);
83         daPointService.add(dto);
84
85         return new CommonResult();
86     }
87
88     @PutMapping
89     @Operation(summary = "修改")
90     @PreAuthorize("@ss.hasPermission('data:point:update')")
91     public CommonResult update(@RequestBody DaPointDTO dto){
92         //效验数据
93         ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class);
94
95         daPointService.update(dto);
96
97         return new CommonResult();
98     }
99
100     @DeleteMapping
101     @Operation(summary = "删除")
102     @PreAuthorize("@ss.hasPermission('data:point:delete')")
103     public CommonResult delete(@RequestBody String[] ids){
104         daPointService.delete(ids);
105         return new CommonResult();
106     }
107
108     @GetMapping("pointNo")
109     public CommonResult<List<DaPointDTO>> getpoint(@RequestParam Map<String, Object> params){
110         List<DaPointDTO> list = daPointService.list(params);
111
112         return new CommonResult<List<DaPointDTO>>().setData(list);
113     }
114
115     @PutMapping("/enable")
116     @Operation(summary = "启用")
117     @Transactional
118     public CommonResult enable(@RequestBody String[] ids) {
119         daPointService.enableByIds(ids);
120         return new CommonResult();
121     }
122
123     @PutMapping("/disable")
124     @Operation(summary = "禁用")
125     @Transactional
126     public CommonResult disable(@RequestBody String[] ids) {
127         daPointService.disableByIds(ids);
128         return new CommonResult();
129     }
130
131 }