潘志宝
2024-12-16 df99e46312fdd5ee830f1451e478f6658e09f9ed
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.controller.admin.sms;
H 2
3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageParam;
6 import com.iailab.framework.common.pojo.PageResult;
7 import com.iailab.framework.common.util.object.BeanUtils;
8 import com.iailab.framework.excel.core.util.ExcelUtils;
9 import com.iailab.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO;
10 import com.iailab.module.system.controller.admin.sms.vo.template.SmsTemplateRespVO;
11 import com.iailab.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO;
12 import com.iailab.module.system.controller.admin.sms.vo.template.SmsTemplateSendReqVO;
13 import com.iailab.module.system.dal.dataobject.sms.SmsTemplateDO;
14 import com.iailab.module.system.service.sms.SmsSendService;
15 import com.iailab.module.system.service.sms.SmsTemplateService;
16 import io.swagger.v3.oas.annotations.Operation;
17 import io.swagger.v3.oas.annotations.Parameter;
18 import io.swagger.v3.oas.annotations.tags.Tag;
19 import org.springframework.security.access.prepost.PreAuthorize;
20 import org.springframework.web.bind.annotation.*;
21
22 import javax.annotation.Resource;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.validation.Valid;
25 import java.io.IOException;
26 import java.util.List;
27
28 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
29 import static com.iailab.framework.common.pojo.CommonResult.success;
30
31 @Tag(name = "管理后台 - 短信模板")
32 @RestController
33 @RequestMapping("/system/sms-template")
34 public class SmsTemplateController {
35
36     @Resource
37     private SmsTemplateService smsTemplateService;
38     @Resource
39     private SmsSendService smsSendService;
40
41     @PostMapping("/create")
42     @Operation(summary = "创建短信模板")
43     @PreAuthorize("@ss.hasPermission('system:sms-template:create')")
44     public CommonResult<Long> createSmsTemplate(@Valid @RequestBody SmsTemplateSaveReqVO createReqVO) {
45         return success(smsTemplateService.createSmsTemplate(createReqVO));
46     }
47
48     @PutMapping("/update")
49     @Operation(summary = "更新短信模板")
50     @PreAuthorize("@ss.hasPermission('system:sms-template:update')")
51     public CommonResult<Boolean> updateSmsTemplate(@Valid @RequestBody SmsTemplateSaveReqVO updateReqVO) {
52         smsTemplateService.updateSmsTemplate(updateReqVO);
53         return success(true);
54     }
55
56     @DeleteMapping("/delete")
57     @Operation(summary = "删除短信模板")
58     @Parameter(name = "id", description = "编号", required = true)
59     @PreAuthorize("@ss.hasPermission('system:sms-template:delete')")
60     public CommonResult<Boolean> deleteSmsTemplate(@RequestParam("id") Long id) {
61         smsTemplateService.deleteSmsTemplate(id);
62         return success(true);
63     }
64
65     @GetMapping("/get")
66     @Operation(summary = "获得短信模板")
67     @Parameter(name = "id", description = "编号", required = true, example = "1024")
68     @PreAuthorize("@ss.hasPermission('system:sms-template:query')")
69     public CommonResult<SmsTemplateRespVO> getSmsTemplate(@RequestParam("id") Long id) {
70         SmsTemplateDO template = smsTemplateService.getSmsTemplate(id);
71         return success(BeanUtils.toBean(template, SmsTemplateRespVO.class));
72     }
73
74     @GetMapping("/page")
75     @Operation(summary = "获得短信模板分页")
76     @PreAuthorize("@ss.hasPermission('system:sms-template:query')")
77     public CommonResult<PageResult<SmsTemplateRespVO>> getSmsTemplatePage(@Valid SmsTemplatePageReqVO pageVO) {
78         PageResult<SmsTemplateDO> pageResult = smsTemplateService.getSmsTemplatePage(pageVO);
79         return success(BeanUtils.toBean(pageResult, SmsTemplateRespVO.class));
80     }
81
82     @GetMapping("/export-excel")
83     @Operation(summary = "导出短信模板 Excel")
84     @PreAuthorize("@ss.hasPermission('system:sms-template:export')")
85     @ApiAccessLog(operateType = EXPORT)
86     public void exportSmsTemplateExcel(@Valid SmsTemplatePageReqVO exportReqVO,
87                                        HttpServletResponse response) throws IOException {
88         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
89         List<SmsTemplateDO> list = smsTemplateService.getSmsTemplatePage(exportReqVO).getList();
90         // 导出 Excel
91         ExcelUtils.write(response, "短信模板.xls", "数据", SmsTemplateRespVO.class,
92                 BeanUtils.toBean(list, SmsTemplateRespVO.class));
93     }
94
95     @PostMapping("/send-sms")
96     @Operation(summary = "发送短信")
97     @PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')")
98     public CommonResult<Long> sendSms(@Valid @RequestBody SmsTemplateSendReqVO sendReqVO) {
99         return success(smsSendService.sendSingleSmsToAdmin(sendReqVO.getMobile(), null,
100                 sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
101     }
102
103 }