From 58d368cfdc7ce56b94be67d4cb2d88c0be11056b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 5 Apr 2021 22:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9A=84=E5=9F=BA=E7=A1=80=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/sms/SmsTemplateController.java | 14 -- ...ller.java => SysSmsChannelController.java} | 2 +- .../sms/SysSmsTemplateController.java | 87 ++++++++ .../sms/vo/template/SysSmsTemplateBaseVO.java | 46 +++++ .../template/SysSmsTemplateCreateReqVO.java | 14 ++ .../vo/template/SysSmsTemplateExcelVO.java | 56 +++++ .../template/SysSmsTemplateExportReqVO.java | 42 ++++ .../vo/template/SysSmsTemplatePageReqVO.java | 47 +++++ .../sms/vo/template/SysSmsTemplateRespVO.java | 26 +++ .../template/SysSmsTemplateUpdateReqVO.java | 21 ++ .../convert/sms/SmsTemplateConvert.java | 26 --- .../convert/sms/SysSmsTemplateConvert.java | 31 +++ .../dal/mysql/sms/SysSmsTemplateMapper.java | 50 ++--- .../system/enums/dict/SysDictTypeEnum.java | 1 + .../service/sms/SysSmsTemplateService.java | 62 ++++++ .../sms/impl/SysSmsTemplateServiceImpl.java | 63 ++++++ .../sms/SysSmsTemplateServiceTest.java | 194 ++++++++++++++++++ 17 files changed, 717 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsTemplateController.java rename src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/{SmsChannelController.java => SysSmsChannelController.java} (98%) create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsTemplateController.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateBaseVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateCreateReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExcelVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExportReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplatePageReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateRespVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateUpdateReqVO.java delete mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SysSmsTemplateConvert.java create mode 100644 src/test/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateServiceTest.java diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsTemplateController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsTemplateController.java deleted file mode 100644 index 53eefad46..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsTemplateController.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.dashboard.modules.system.controller.sms; - -import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Api("认证 API") -@RestController -@RequestMapping("/sms/template") -public class SmsTemplateController { - - - -} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsChannelController.java similarity index 98% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsChannelController.java index 1000a9b02..cc7b496aa 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsChannelController.java @@ -23,7 +23,7 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success; @Api(tags = "短信渠道") @RestController @RequestMapping("system/sms-channel") -public class SmsChannelController { +public class SysSmsChannelController { @Resource private SysSmsChannelService smsChannelService; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsTemplateController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsTemplateController.java new file mode 100644 index 000000000..c70cbc9f8 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SysSmsTemplateController.java @@ -0,0 +1,87 @@ +package cn.iocoder.dashboard.modules.system.controller.sms; + +import cn.iocoder.dashboard.common.pojo.CommonResult; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; +import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.*; +import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsTemplateConvert; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.dashboard.common.pojo.CommonResult.success; +import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Api("短信模板") +@RestController +@RequestMapping("/system/sms-template") +public class SysSmsTemplateController { + + @Resource + private SysSmsTemplateService smsTemplateService; + + @PostMapping("/create") + @ApiOperation("创建短信模板") + @PreAuthorize("@ss.hasPermission('system:sms-template:create')") + public CommonResult createSmsTemplate(@Valid @RequestBody SysSmsTemplateCreateReqVO createReqVO) { + return success(smsTemplateService.createSmsTemplate(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新短信模板") + @PreAuthorize("@ss.hasPermission('system:sms-template:update')") + public CommonResult updateSmsTemplate(@Valid @RequestBody SysSmsTemplateUpdateReqVO updateReqVO) { + smsTemplateService.updateSmsTemplate(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除短信模板") + @ApiImplicitParam(name = "id", value = "编号", required = true) + @PreAuthorize("@ss.hasPermission('system:sms-template:delete')") + public CommonResult deleteSmsTemplate(@RequestParam("id") Long id) { + smsTemplateService.deleteSmsTemplate(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得短信模板") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('system:sms-template:query')") + public CommonResult getSmsTemplate(@RequestParam("id") Long id) { + SysSmsTemplateDO smsTemplate = smsTemplateService.getSmsTemplate(id); + return success(SysSmsTemplateConvert.INSTANCE.convert(smsTemplate)); + } + + @GetMapping("/page") + @ApiOperation("获得短信模板分页") + @PreAuthorize("@ss.hasPermission('system:sms-template:query')") + public CommonResult> getSmsTemplatePage(@Valid SysSmsTemplatePageReqVO pageVO) { + PageResult pageResult = smsTemplateService.getSmsTemplatePage(pageVO); + return success(SysSmsTemplateConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出短信模板 Excel") + @PreAuthorize("@ss.hasPermission('system:sms-template:export')") + @OperateLog(type = EXPORT) + public void exportSmsTemplateExcel(@Valid SysSmsTemplateExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = smsTemplateService.getSmsTemplateList(exportReqVO); + // 导出 Excel + List datas = SysSmsTemplateConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "短信模板.xls", "数据", SysSmsTemplateExcelVO.class, datas); + } + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateBaseVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateBaseVO.java new file mode 100644 index 000000000..f2ef6ac16 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateBaseVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** +* 短信模板 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class SysSmsTemplateBaseVO { + + @ApiModelProperty(value = "短信签名", required = true, example = "1", notes = "参见 SysSmsTemplateTypeEnum 枚举类") + @NotNull(message = "短信签名不能为空") + private Integer type; + + @ApiModelProperty(value = "开启状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举类") + @NotNull(message = "开启状态不能为空") + private Integer status; + + @ApiModelProperty(value = "模板编码", required = true, example = "test_01") + @NotNull(message = "模板编码不能为空") + private String code; + + @ApiModelProperty(value = "模板名称", required = true, example = "yudao") + @NotNull(message = "模板名称不能为空") + private String name; + + @ApiModelProperty(value = "模板内容", required = true, example = "你好,{name}。你长的太{like}啦!") + @NotNull(message = "模板内容不能为空") + private String content; + + @ApiModelProperty(value = "备注", example = "哈哈哈") + private String remark; + + @ApiModelProperty(value = "短信 API 的模板编号", required = true, example = "4383920") + @NotNull(message = "短信 API 的模板编号不能为空") + private String apiTemplateId; + + @ApiModelProperty(value = "短信渠道编号", required = true, example = "10") + @NotNull(message = "短信渠道编号不能为空") + private Long channelId; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateCreateReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateCreateReqVO.java new file mode 100644 index 000000000..8f847556d --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@ApiModel("短信模板创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SysSmsTemplateCreateReqVO extends SysSmsTemplateBaseVO { + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExcelVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExcelVO.java new file mode 100644 index 000000000..3eef8133b --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExcelVO.java @@ -0,0 +1,56 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; + +import static cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum.*; + +/** + * 短信模板 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SysSmsTemplateExcelVO { + + @ExcelProperty("编号") + private Long id; + + @ExcelProperty(value = "短信签名", converter = DictConvert.class) + @DictFormat(SYS_SMS_TEMPLATE_TYPE) + private Integer type; + + @ExcelProperty(value = "开启状态", converter = DictConvert.class) + @DictFormat(SYS_COMMON_STATUS) + private Integer status; + + @ExcelProperty("模板编码") + private String code; + + @ExcelProperty("模板名称") + private String name; + + @ExcelProperty("模板内容") + private String content; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("短信 API 的模板编号") + private String apiTemplateId; + + @ExcelProperty("短信渠道编号") + private Long channelId; + + @ExcelProperty(value = "短信渠道编码", converter = DictConvert.class) + @DictFormat(SYS_SMS_CHANNEL_CODE) + private String channelCode; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExportReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExportReqVO.java new file mode 100644 index 000000000..34f940253 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateExportReqVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "短信模板 Excel 导出 Request VO", description = "参数和 SysSmsTemplatePageReqVO 是一致的") +@Data +public class SysSmsTemplateExportReqVO { + + @ApiModelProperty(value = "短信签名", example = "1") + private Integer type; + + @ApiModelProperty(value = "开启状态", example = "1") + private Integer status; + + @ApiModelProperty(value = "模板编码", example = "test_01", notes = "模糊匹配") + private String code; + + @ApiModelProperty(value = "模板内容", example = "你好,{name}。你长的太{like}啦!", notes = "模糊匹配") + private String content; + + @ApiModelProperty(value = "短信 API 的模板编号", example = "4383920", notes = "模糊匹配") + private String apiTemplateId; + + @ApiModelProperty(value = "短信渠道编号", example = "10") + private Long channelId; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplatePageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplatePageReqVO.java new file mode 100644 index 000000000..b5f1e5bfb --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplatePageReqVO.java @@ -0,0 +1,47 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import cn.iocoder.dashboard.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("短信模板分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SysSmsTemplatePageReqVO extends PageParam { + + @ApiModelProperty(value = "短信签名", example = "1") + private Integer type; + + @ApiModelProperty(value = "开启状态", example = "1") + private Integer status; + + @ApiModelProperty(value = "模板编码", example = "test_01", notes = "模糊匹配") + private String code; + + @ApiModelProperty(value = "模板内容", example = "你好,{name}。你长的太{like}啦!", notes = "模糊匹配") + private String content; + + @ApiModelProperty(value = "短信 API 的模板编号", example = "4383920", notes = "模糊匹配") + private String apiTemplateId; + + @ApiModelProperty(value = "短信渠道编号", example = "10") + private Long channelId; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateRespVO.java new file mode 100644 index 000000000..033d2a2f2 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateRespVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.Date; + +@ApiModel("短信模板 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SysSmsTemplateRespVO extends SysSmsTemplateBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "短信渠道编码", required = true, example = "ALIYUN") + private String channelCode; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateUpdateReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateUpdateReqVO.java new file mode 100644 index 000000000..9b3aba840 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/template/SysSmsTemplateUpdateReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.dashboard.modules.system.controller.sms.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@ApiModel("短信模板更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SysSmsTemplateUpdateReqVO extends SysSmsTemplateBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java deleted file mode 100644 index 788fc8e19..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.dashboard.modules.system.convert.sms; - -import cn.iocoder.dashboard.common.pojo.PageResult; -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO; -import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; -import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface SmsTemplateConvert { - - SmsTemplateConvert INSTANCE = Mappers.getMapper(SmsTemplateConvert.class); - - @Mapping(source = "records", target = "list") - PageResult convertPage(IPage page); - - List convert(List bean); - - SmsTemplateVO convert(SysSmsTemplateDO bean); - -} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SysSmsTemplateConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SysSmsTemplateConvert.java new file mode 100644 index 000000000..5d73771eb --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SysSmsTemplateConvert.java @@ -0,0 +1,31 @@ +package cn.iocoder.dashboard.modules.system.convert.sms; + +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateExcelVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateRespVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface SysSmsTemplateConvert { + + SysSmsTemplateConvert INSTANCE = Mappers.getMapper(SysSmsTemplateConvert.class); + + SysSmsTemplateDO convert(SysSmsTemplateCreateReqVO bean); + + SysSmsTemplateDO convert(SysSmsTemplateUpdateReqVO bean); + + SysSmsTemplateRespVO convert(SysSmsTemplateDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java index 3cfc898b3..ee1b3f2d9 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java @@ -1,8 +1,11 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.sms; -import cn.iocoder.dashboard.common.enums.CommonStatusEnum; + +import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -14,29 +17,28 @@ public interface SysSmsTemplateMapper extends BaseMapperX { return selectOne("code", code); } - /** - * 根据短信渠道id查询短信模板集合 - * - * @param channelId 渠道id - * @return 模板集合 - */ - default List selectListByChannelId(Long channelId) { - return selectList(new LambdaQueryWrapper() - .eq(SysSmsTemplateDO::getChannelId, channelId) - .eq(SysSmsTemplateDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) - .orderByAsc(SysSmsTemplateDO::getId) - ); + default PageResult selectPage(SysSmsTemplatePageReqVO reqVO) { + return selectPage(reqVO, new QueryWrapperX() + .eqIfPresent("type", reqVO.getType()) + .eqIfPresent("status", reqVO.getStatus()) + .likeIfPresent("code", reqVO.getCode()) + .likeIfPresent("content", reqVO.getContent()) + .likeIfPresent("api_template_id", reqVO.getApiTemplateId()) + .eqIfPresent("channel_id", reqVO.getChannelId()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("id")); } - /** - * 查询有效短信模板集合 - * - * @return 有效短信模板集合 - */ - default List selectEnabledList() { - return selectList(new LambdaQueryWrapper() - .eq(SysSmsTemplateDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) - .orderByAsc(SysSmsTemplateDO::getId) - ); + default List selectList(SysSmsTemplateExportReqVO reqVO) { + return selectList(new QueryWrapperX() + .eqIfPresent("type", reqVO.getType()) + .eqIfPresent("status", reqVO.getStatus()) + .likeIfPresent("code", reqVO.getCode()) + .likeIfPresent("content", reqVO.getContent()) + .likeIfPresent("api_template_id", reqVO.getApiTemplateId()) + .eqIfPresent("channel_id", reqVO.getChannelId()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("id")); } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java index 705662126..0bc448fc1 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java @@ -19,6 +19,7 @@ public enum SysDictTypeEnum { SYS_CONFIG_TYPE("sys_config_type"), // 参数配置类型 SYS_BOOLEAN_STRING("sys_boolean_string"), // Boolean 是否类型 SYS_SMS_CHANNEL_CODE("sys_sms_channel_code"), // 短信渠道编码 + SYS_SMS_TEMPLATE_TYPE("sys_sms_template_type"), // 短信模板类型 INF_REDIS_TIMEOUT_TYPE("inf_redis_timeout_type"), // Redis 超时类型 INF_JOB_STATUS("inf_job_status"), // 定时任务状态的枚举 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java index 5faeeddcb..2c17b8a7a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java @@ -1,7 +1,15 @@ package cn.iocoder.dashboard.modules.system.service.sms; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; import java.util.Map; /** @@ -29,4 +37,58 @@ public interface SysSmsTemplateService { */ String formatSmsTemplateContent(String content, Map params); + /** + * 创建短信模板 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createSmsTemplate(@Valid SysSmsTemplateCreateReqVO createReqVO); + + /** + * 更新短信模板 + * + * @param updateReqVO 更新信息 + */ + void updateSmsTemplate(@Valid SysSmsTemplateUpdateReqVO updateReqVO); + + /** + * 删除短信模板 + * + * @param id 编号 + */ + void deleteSmsTemplate(Long id); + + /** + * 获得短信模板 + * + * @param id 编号 + * @return 短信模板 + */ + SysSmsTemplateDO getSmsTemplate(Long id); + + /** + * 获得短信模板列表 + * + * @param ids 编号 + * @return 短信模板列表 + */ + List getSmsTemplateList(Collection ids); + + /** + * 获得短信模板分页 + * + * @param pageReqVO 分页查询 + * @return 短信模板分页 + */ + PageResult getSmsTemplatePage(SysSmsTemplatePageReqVO pageReqVO); + + /** + * 获得短信模板列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 短信模板分页 + */ + List getSmsTemplateList(SysSmsTemplateExportReqVO exportReqVO); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java index c5c1a5127..ac54a2565 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java @@ -1,14 +1,25 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; import cn.hutool.core.util.StrUtil; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; +import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsTemplateConvert; import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsTemplateMapper; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; import java.util.Map; +import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.SMS_TEMPLATE_NOT_EXISTS; + /** * 短信模板Service实现类 * @@ -31,4 +42,56 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { return StrUtil.format(content, params); } + @Override + public Long createSmsTemplate(SysSmsTemplateCreateReqVO createReqVO) { + // 插入 + SysSmsTemplateDO smsTemplate = SysSmsTemplateConvert.INSTANCE.convert(createReqVO); + smsTemplateMapper.insert(smsTemplate); + // 返回 + return smsTemplate.getId(); + } + + @Override + public void updateSmsTemplate(SysSmsTemplateUpdateReqVO updateReqVO) { + // 校验存在 + this.validateSmsTemplateExists(updateReqVO.getId()); + // 更新 + SysSmsTemplateDO updateObj = SysSmsTemplateConvert.INSTANCE.convert(updateReqVO); + smsTemplateMapper.updateById(updateObj); + } + + @Override + public void deleteSmsTemplate(Long id) { + // 校验存在 + this.validateSmsTemplateExists(id); + // 更新 + smsTemplateMapper.deleteById(id); + } + + private void validateSmsTemplateExists(Long id) { + if (smsTemplateMapper.selectById(id) == null) { + throw exception(SMS_TEMPLATE_NOT_EXISTS); + } + } + + @Override + public SysSmsTemplateDO getSmsTemplate(Long id) { + return smsTemplateMapper.selectById(id); + } + + @Override + public List getSmsTemplateList(Collection ids) { + return smsTemplateMapper.selectBatchIds(ids); + } + + @Override + public PageResult getSmsTemplatePage(SysSmsTemplatePageReqVO pageReqVO) { + return smsTemplateMapper.selectPage(pageReqVO); + } + + @Override + public List getSmsTemplateList(SysSmsTemplateExportReqVO exportReqVO) { + return smsTemplateMapper.selectList(exportReqVO); + } + } diff --git a/src/test/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateServiceTest.java b/src/test/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateServiceTest.java new file mode 100644 index 000000000..a04034155 --- /dev/null +++ b/src/test/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateServiceTest.java @@ -0,0 +1,194 @@ +package cn.iocoder.dashboard.modules.system.service.sms; + +import cn.iocoder.dashboard.BaseDbUnitTest; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; +import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsTemplateMapper; +import cn.iocoder.dashboard.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; +import cn.iocoder.dashboard.util.object.ObjectUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.SMS_TEMPLATE_NOT_EXISTS; +import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException; +import static cn.iocoder.dashboard.util.RandomUtils.randomLongId; +import static cn.iocoder.dashboard.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.*; + +/** +* {@link SysSmsTemplateServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SysSmsTemplateServiceImpl.class) +public class SysSmsTemplateServiceTest extends BaseDbUnitTest { + + @Resource + private SysSmsTemplateServiceImpl smsTemplateService; + + @Resource + private SysSmsTemplateMapper smsTemplateMapper; + + @Test + public void testCreateSmsTemplate_success() { + // 准备参数 + SysSmsTemplateCreateReqVO reqVO = randomPojo(SysSmsTemplateCreateReqVO.class); + + // 调用 + Long smsTemplateId = smsTemplateService.createSmsTemplate(reqVO); + // 断言 + assertNotNull(smsTemplateId); + // 校验记录的属性是否正确 + SysSmsTemplateDO smsTemplate = smsTemplateMapper.selectById(smsTemplateId); + assertPojoEquals(reqVO, smsTemplate); + } + + @Test + public void testUpdateSmsTemplate_success() { + // mock 数据 + SysSmsTemplateDO dbSmsTemplate = randomPojo(SysSmsTemplateDO.class); + smsTemplateMapper.insert(dbSmsTemplate);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SysSmsTemplateUpdateReqVO reqVO = randomPojo(SysSmsTemplateUpdateReqVO.class, o -> { + o.setId(dbSmsTemplate.getId()); // 设置更新的 ID + }); + + // 调用 + smsTemplateService.updateSmsTemplate(reqVO); + // 校验是否更新正确 + SysSmsTemplateDO smsTemplate = smsTemplateMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, smsTemplate); + } + + @Test + public void testUpdateSmsTemplate_notExists() { + // 准备参数 + SysSmsTemplateUpdateReqVO reqVO = randomPojo(SysSmsTemplateUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> smsTemplateService.updateSmsTemplate(reqVO), SMS_TEMPLATE_NOT_EXISTS); + } + + @Test + public void testDeleteSmsTemplate_success() { + // mock 数据 + SysSmsTemplateDO dbSmsTemplate = randomPojo(SysSmsTemplateDO.class); + smsTemplateMapper.insert(dbSmsTemplate);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbSmsTemplate.getId(); + + // 调用 + smsTemplateService.deleteSmsTemplate(id); + // 校验数据不存在了 + assertNull(smsTemplateMapper.selectById(id)); + } + + @Test + public void testDeleteSmsTemplate_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> smsTemplateService.deleteSmsTemplate(id), SMS_TEMPLATE_NOT_EXISTS); + } + + @Test // TODO 请修改 null 为需要的值 + public void testGetSmsTemplatePage() { + // mock 数据 + SysSmsTemplateDO dbSmsTemplate = randomPojo(SysSmsTemplateDO.class, o -> { // 等会查询到 + o.setType(null); + o.setStatus(null); + o.setCode(null); + o.setContent(null); + o.setApiTemplateId(null); + o.setChannelId(null); + o.setCreateTime(null); + }); + smsTemplateMapper.insert(dbSmsTemplate); + // 测试 type 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setType(null))); + // 测试 status 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setStatus(null))); + // 测试 code 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setCode(null))); + // 测试 content 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setContent(null))); + // 测试 apiTemplateId 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setApiTemplateId(null))); + // 测试 channelId 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setChannelId(null))); + // 测试 createTime 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setCreateTime(null))); + // 准备参数 + SysSmsTemplatePageReqVO reqVO = new SysSmsTemplatePageReqVO(); + reqVO.setType(null); + reqVO.setStatus(null); + reqVO.setCode(null); + reqVO.setContent(null); + reqVO.setApiTemplateId(null); + reqVO.setChannelId(null); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + + // 调用 + PageResult pageResult = smsTemplateService.getSmsTemplatePage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbSmsTemplate, pageResult.getList().get(0)); + } + + @Test // TODO 请修改 null 为需要的值 + public void testGetSmsTemplateList() { + // mock 数据 + SysSmsTemplateDO dbSmsTemplate = randomPojo(SysSmsTemplateDO.class, o -> { // 等会查询到 + o.setType(null); + o.setStatus(null); + o.setCode(null); + o.setContent(null); + o.setApiTemplateId(null); + o.setChannelId(null); + o.setCreateTime(null); + }); + smsTemplateMapper.insert(dbSmsTemplate); + // 测试 type 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setType(null))); + // 测试 status 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setStatus(null))); + // 测试 code 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setCode(null))); + // 测试 content 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setContent(null))); + // 测试 apiTemplateId 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setApiTemplateId(null))); + // 测试 channelId 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setChannelId(null))); + // 测试 createTime 不匹配 + smsTemplateMapper.insert(ObjectUtils.clone(dbSmsTemplate, o -> o.setCreateTime(null))); + // 准备参数 + SysSmsTemplateExportReqVO reqVO = new SysSmsTemplateExportReqVO(); + reqVO.setType(null); + reqVO.setStatus(null); + reqVO.setCode(null); + reqVO.setContent(null); + reqVO.setApiTemplateId(null); + reqVO.setChannelId(null); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + + // 调用 + List list = smsTemplateService.getSmsTemplateList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbSmsTemplate, list.get(0)); + } + +}