潘志宝
2024-12-16 df99e46312fdd5ee830f1451e478f6658e09f9ed
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.controller.admin.sms;
H 2
3 import com.iailab.framework.common.pojo.CommonResult;
4 import com.iailab.framework.common.pojo.PageResult;
5 import com.iailab.framework.common.util.object.BeanUtils;
6 import com.iailab.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
7 import com.iailab.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO;
8 import com.iailab.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO;
9 import com.iailab.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO;
10 import com.iailab.module.system.dal.dataobject.sms.SmsChannelDO;
11 import com.iailab.module.system.service.sms.SmsChannelService;
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.web.bind.annotation.*;
17
18 import javax.annotation.Resource;
19 import javax.validation.Valid;
20 import java.util.Comparator;
21 import java.util.List;
22
23 import static com.iailab.framework.common.pojo.CommonResult.success;
24
25 @Tag(name = "管理后台 - 短信渠道")
26 @RestController
27 @RequestMapping("system/sms-channel")
28 public class SmsChannelController {
29
30     @Resource
31     private SmsChannelService smsChannelService;
32
33     @PostMapping("/create")
34     @Operation(summary = "创建短信渠道")
35     @PreAuthorize("@ss.hasPermission('system:sms-channel:create')")
36     public CommonResult<Long> createSmsChannel(@Valid @RequestBody SmsChannelSaveReqVO createReqVO) {
37         return success(smsChannelService.createSmsChannel(createReqVO));
38     }
39
40     @PutMapping("/update")
41     @Operation(summary = "更新短信渠道")
42     @PreAuthorize("@ss.hasPermission('system:sms-channel:update')")
43     public CommonResult<Boolean> updateSmsChannel(@Valid @RequestBody SmsChannelSaveReqVO updateReqVO) {
44         smsChannelService.updateSmsChannel(updateReqVO);
45         return success(true);
46     }
47
48     @DeleteMapping("/delete")
49     @Operation(summary = "删除短信渠道")
50     @Parameter(name = "id", description = "编号", required = true)
51     @PreAuthorize("@ss.hasPermission('system:sms-channel:delete')")
52     public CommonResult<Boolean> deleteSmsChannel(@RequestParam("id") Long id) {
53         smsChannelService.deleteSmsChannel(id);
54         return success(true);
55     }
56
57     @GetMapping("/get")
58     @Operation(summary = "获得短信渠道")
59     @Parameter(name = "id", description = "编号", required = true, example = "1024")
60     @PreAuthorize("@ss.hasPermission('system:sms-channel:query')")
61     public CommonResult<SmsChannelRespVO> getSmsChannel(@RequestParam("id") Long id) {
62         SmsChannelDO channel = smsChannelService.getSmsChannel(id);
63         return success(BeanUtils.toBean(channel, SmsChannelRespVO.class));
64     }
65
66     @GetMapping("/page")
67     @Operation(summary = "获得短信渠道分页")
68     @PreAuthorize("@ss.hasPermission('system:sms-channel:query')")
69     public CommonResult<PageResult<SmsChannelRespVO>> getSmsChannelPage(@Valid SmsChannelPageReqVO pageVO) {
70         PageResult<SmsChannelDO> pageResult = smsChannelService.getSmsChannelPage(pageVO);
71         return success(BeanUtils.toBean(pageResult, SmsChannelRespVO.class));
72     }
73
74     @GetMapping({"/list-all-simple", "/simple-list"})
75     @Operation(summary = "获得短信渠道精简列表", description = "包含被禁用的短信渠道")
76     public CommonResult<List<SmsChannelSimpleRespVO>> getSimpleSmsChannelList() {
77         List<SmsChannelDO> list = smsChannelService.getSmsChannelList();
78         list.sort(Comparator.comparing(SmsChannelDO::getId));
79         return success(BeanUtils.toBean(list, SmsChannelSimpleRespVO.class));
80     }
81
82 }