- 添加短信服务 admin api
							parent
							
								
									fa2fd77719
								
							
						
					
					
						commit
						23864fac88
					
				|  | @ -0,0 +1,53 @@ | |||
| package cn.iocoder.mall.admin.application.controller.admins; | ||||
| 
 | ||||
| import cn.iocoder.mall.admin.api.SmsService; | ||||
| import cn.iocoder.mall.admin.api.dto.sms.PageQuerySmsSignDTO; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| 
 | ||||
| /** | ||||
|  * 短信服务 | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/26 12:26 PM | ||||
|  */ | ||||
| @RestController | ||||
| @RequestMapping("sms/sign") | ||||
| @Api("短信服务(签名)") | ||||
| public class SmsSignController { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private SmsService smsService; | ||||
| 
 | ||||
|     @PostMapping("page") | ||||
|     @ApiOperation("签名-page") | ||||
|     public void pageSign(PageQuerySmsSignDTO querySmsSignDTO) { | ||||
|         smsService.pageSmsSign(querySmsSignDTO); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("add") | ||||
|     @ApiOperation("签名-添加") | ||||
|     public void addSign(@RequestParam("sign") String sign, | ||||
|                         @RequestParam("platform") Integer platform) { | ||||
|         smsService.addSign(sign, platform); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("update") | ||||
|     @ApiOperation("签名-更新") | ||||
|     public void updateSign(@RequestParam("id") Integer id, | ||||
|                            @RequestParam("sign") String sign, | ||||
|                            @RequestParam("platform") Integer platform) { | ||||
|         smsService.updateSign(id, sign, platform); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("deleted") | ||||
|     @ApiOperation("签名-删除") | ||||
|     public void deletedSign(@RequestParam("id") Integer id) { | ||||
|         smsService.deleteSign(id); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,64 @@ | |||
| package cn.iocoder.mall.admin.application.controller.admins; | ||||
| 
 | ||||
| import cn.iocoder.mall.admin.api.SmsService; | ||||
| import cn.iocoder.mall.admin.api.dto.sms.PageQuerySmsSignDTO; | ||||
| import cn.iocoder.mall.admin.api.dto.sms.PageQuerySmsTemplateDTO; | ||||
| import cn.iocoder.mall.admin.application.po.sms.SmsTemplateAddPO; | ||||
| import cn.iocoder.mall.admin.application.po.sms.SmsTemplateUpdatePO; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| 
 | ||||
| /** | ||||
|  * 短信服务 | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/26 12:26 PM | ||||
|  */ | ||||
| @RestController | ||||
| @RequestMapping("sms/template") | ||||
| @Api("短信服务(短信模板)") | ||||
| public class SmsTemplateController { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private SmsService smsService; | ||||
| 
 | ||||
|     @PostMapping("page") | ||||
|     @ApiOperation("短信模板-page") | ||||
|     public void pageSign(PageQuerySmsTemplateDTO pageQuerySmsTemplateDTO) { | ||||
|         smsService.pageSmsTemplate(pageQuerySmsTemplateDTO); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("add") | ||||
|     @ApiOperation("短信模板-添加") | ||||
|     public void addSign(SmsTemplateAddPO smsTemplateAddPO) { | ||||
|         smsService.addTemplate( | ||||
|                 smsTemplateAddPO.getSmsSignId(), | ||||
|                 smsTemplateAddPO.getTemplateCode(), | ||||
|                 smsTemplateAddPO.getTemplate(), | ||||
|                 smsTemplateAddPO.getPlatform(), | ||||
|                 smsTemplateAddPO.getSmsType()); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("update") | ||||
|     @ApiOperation("短信模板-更新") | ||||
|     public void updateSign(SmsTemplateUpdatePO smsTemplateUpdatePO) { | ||||
|         smsService.updateTemplate( | ||||
|                 smsTemplateUpdatePO.getId(), | ||||
|                 smsTemplateUpdatePO.getSmsSignId(), | ||||
|                 smsTemplateUpdatePO.getTemplateCode(), | ||||
|                 smsTemplateUpdatePO.getTemplate(), | ||||
|                 smsTemplateUpdatePO.getPlatform(), | ||||
|                 smsTemplateUpdatePO.getSmsType()); | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping("deleted") | ||||
|     @ApiOperation("短信模板-删除") | ||||
|     public void deletedSign(@RequestParam("id") Integer id) { | ||||
|         smsService.deleteTemplate(id); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,5 @@ | |||
| /** | ||||
|  * @author Sin | ||||
|  * @time 2019/5/26 12:36 PM | ||||
|  */ | ||||
| package cn.iocoder.mall.admin.application.po; | ||||
|  | @ -0,0 +1,49 @@ | |||
| package cn.iocoder.mall.admin.application.po.sms; | ||||
| 
 | ||||
| import cn.iocoder.common.framework.validator.InEnum; | ||||
| import cn.iocoder.mall.admin.api.constant.SmsPlatformEnum; | ||||
| import cn.iocoder.mall.admin.api.constant.SmsTypeEnum; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| import lombok.experimental.Accessors; | ||||
| 
 | ||||
| import javax.validation.constraints.NotNull; | ||||
| import javax.validation.constraints.Size; | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| /** | ||||
|  * 短信模板 add | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/26 12:37 PM | ||||
|  */ | ||||
| @ApiModel("短信模板-添加") | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class SmsTemplateAddPO implements Serializable { | ||||
| 
 | ||||
|     @ApiModelProperty("短信签名id") | ||||
|     @NotNull(message = "短信短信签名id不能为空!") | ||||
|     private Integer smsSignId; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板code") | ||||
|     @NotNull | ||||
|     @Size(min = 3, max = 50, message = "短信code在 3-50 之间") | ||||
|     private String templateCode; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板") | ||||
|     @NotNull | ||||
|     @Size(min = 3, max = 255, message = "短信在 3-255 之间") | ||||
|     private String template; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板-平台") | ||||
|     @NotNull | ||||
|     @InEnum(value = SmsPlatformEnum.class) | ||||
|     private Integer platform; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板-平台") | ||||
|     @NotNull | ||||
|     @InEnum(value = SmsTypeEnum.class) | ||||
|     private Integer smsType; | ||||
| } | ||||
|  | @ -0,0 +1,53 @@ | |||
| package cn.iocoder.mall.admin.application.po.sms; | ||||
| 
 | ||||
| import cn.iocoder.common.framework.validator.InEnum; | ||||
| import cn.iocoder.mall.admin.api.constant.SmsPlatformEnum; | ||||
| import cn.iocoder.mall.admin.api.constant.SmsTypeEnum; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| import lombok.experimental.Accessors; | ||||
| 
 | ||||
| import javax.validation.constraints.NotNull; | ||||
| import javax.validation.constraints.Size; | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| /** | ||||
|  * 短信模板 add | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/26 12:37 PM | ||||
|  */ | ||||
| @ApiModel("短信模板-添加") | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class SmsTemplateUpdatePO implements Serializable { | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板id") | ||||
|     @NotNull(message = "短信模板不能为空!") | ||||
|     private Integer id; | ||||
| 
 | ||||
|     @ApiModelProperty("短信签名id") | ||||
|     @NotNull(message = "短信短信签名id不能为空!") | ||||
|     private Integer smsSignId; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板code") | ||||
|     @NotNull | ||||
|     @Size(min = 3, max = 50, message = "短信code在 3-50 之间") | ||||
|     private String templateCode; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板") | ||||
|     @NotNull | ||||
|     @Size(min = 3, max = 255, message = "短信在 3-255 之间") | ||||
|     private String template; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板-平台") | ||||
|     @NotNull | ||||
|     @InEnum(value = SmsPlatformEnum.class) | ||||
|     private Integer platform; | ||||
| 
 | ||||
|     @ApiModelProperty("短信模板-平台") | ||||
|     @NotNull | ||||
|     @InEnum(value = SmsTypeEnum.class) | ||||
|     private Integer smsType; | ||||
| } | ||||
|  | @ -39,7 +39,7 @@ public interface SmsService { | |||
|      * | ||||
|      * @param sign | ||||
|      */ | ||||
|     void createSign(String sign, Integer platform); | ||||
|     void addSign(String sign, Integer platform); | ||||
| 
 | ||||
|     /** | ||||
|      * 签名 - 获取 | ||||
|  | @ -72,7 +72,8 @@ public interface SmsService { | |||
|      * @param template 模板内容 | ||||
|      * @param platform 平台 | ||||
|      */ | ||||
|     void createTemplate(Integer smsSignId, String templateCode, String template, Integer platform, Integer smsType); | ||||
|     void addTemplate(Integer smsSignId, String templateCode, | ||||
|                      String template, Integer platform, Integer smsType); | ||||
| 
 | ||||
|     /** | ||||
|      * 模板 - 获取 | ||||
|  | @ -89,7 +90,8 @@ public interface SmsService { | |||
|      * @param template 模板内容 | ||||
|      * @param platform 短信平台 | ||||
|      */ | ||||
|     void updateTemplate(Integer id, Integer smsSignId, String template, Integer platform, Integer smsType); | ||||
|     void updateTemplate(Integer id, Integer smsSignId, String templateCode, | ||||
|                         String template, Integer platform, Integer smsType); | ||||
| 
 | ||||
|     /** | ||||
|      * 模板 - 删除 | ||||
|  |  | |||
|  | @ -1,17 +1,23 @@ | |||
| package cn.iocoder.mall.admin.api.constant; | ||||
| 
 | ||||
| import cn.iocoder.common.framework.core.IntArrayValuable; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| /** | ||||
|  * 短信审核状态 | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/16 12:48 PM | ||||
|  */ | ||||
| public enum SmsPlatformEnum { | ||||
| public enum SmsPlatformEnum implements IntArrayValuable { | ||||
| 
 | ||||
|     YunPian(1, "云片"), | ||||
|     AliYun(2, "阿里云"), | ||||
|     ; | ||||
| 
 | ||||
|     public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsPlatformEnum::getValue).toArray(); | ||||
| 
 | ||||
|     private final Integer value; | ||||
|     private final String name; | ||||
| 
 | ||||
|  | @ -27,4 +33,9 @@ public enum SmsPlatformEnum { | |||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int[] array() { | ||||
|         return ARRAYS; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,18 +1,24 @@ | |||
| package cn.iocoder.mall.admin.api.constant; | ||||
| 
 | ||||
| import cn.iocoder.common.framework.core.IntArrayValuable; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| /** | ||||
|  * 短信审核状态 | ||||
|  * | ||||
|  * @author Sin | ||||
|  * @time 2019/5/16 12:48 PM | ||||
|  */ | ||||
| public enum SmsTypeEnum { | ||||
| public enum SmsTypeEnum implements IntArrayValuable { | ||||
| 
 | ||||
|     VERIFICATION_CODE(1, "验证码"), | ||||
|     NOTICE(1, "通知"), | ||||
|     MARKETING(2, "营销"), | ||||
|     ; | ||||
| 
 | ||||
|     public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsTypeEnum::getValue).toArray(); | ||||
| 
 | ||||
|     private final Integer value; | ||||
|     private final String name; | ||||
| 
 | ||||
|  | @ -28,4 +34,9 @@ public enum SmsTypeEnum { | |||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int[] array() { | ||||
|         return ARRAYS; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -111,7 +111,7 @@ public class SmsServiceImpl implements SmsService { | |||
| 
 | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void createSign(String sign, Integer platform) { | ||||
|     public void addSign(String sign, Integer platform) { | ||||
| 
 | ||||
|         // 避免重复
 | ||||
|         SmsSignDO smsSignDO = smsSignMapper.selectOne( | ||||
|  | @ -196,8 +196,8 @@ public class SmsServiceImpl implements SmsService { | |||
| 
 | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void createTemplate(Integer smsSignId, String templateCode, | ||||
|                                String template, Integer platform, Integer smsType) { | ||||
|     public void addTemplate(Integer smsSignId, String templateCode, | ||||
|                             String template, Integer platform, Integer smsType) { | ||||
| 
 | ||||
|         SmsSignDO smsSignDO = smsSignMapper.selectOne( | ||||
|                 new QueryWrapper<SmsSignDO>().eq("id", smsSignId)); | ||||
|  | @ -240,7 +240,8 @@ public class SmsServiceImpl implements SmsService { | |||
| 
 | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void updateTemplate(Integer id, Integer smsSignId, String template, Integer platform, Integer smsType) { | ||||
|     public void updateTemplate(Integer id, Integer smsSignId, String templateCode, | ||||
|                                String template, Integer platform, Integer smsType) { | ||||
|         SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne( | ||||
|                 new QueryWrapper<SmsTemplateDO>().eq("id", id)); | ||||
| 
 | ||||
|  | @ -260,6 +261,7 @@ public class SmsServiceImpl implements SmsService { | |||
|         smsTemplateMapper.update( | ||||
|                 (SmsTemplateDO) new SmsTemplateDO() | ||||
|                         .setSmsSignId(smsSignId) | ||||
|                         .setTemplateCode(templateCode) | ||||
|                         .setTemplate(template) | ||||
|                         .setPlatform(platform) | ||||
|                         .setSmsType(smsType) | ||||
|  |  | |||
|  | @ -31,8 +31,8 @@ public class SmsServiceImplTest { | |||
| 
 | ||||
|     @Test | ||||
|     public void createSignTest() { | ||||
| //        smsService.createSign("悦跑运动", SmsPlatformEnum.YunPian.getValue());
 | ||||
|         smsService.createSign("登录确认验证码", SmsPlatformEnum.AliYun.getValue()); | ||||
| //        smsService.addSign("悦跑运动", SmsPlatformEnum.YunPian.getValue());
 | ||||
|         smsService.addSign("登录确认验证码", SmsPlatformEnum.AliYun.getValue()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|  | @ -63,7 +63,7 @@ public class SmsServiceImplTest { | |||
|         Integer sign = 4; | ||||
|         String templateCode = "SMS_137110043"; | ||||
|         String template = "验证码#code#,您正在登录,若非本人操作,请勿泄露。"; | ||||
|         smsService.createTemplate( | ||||
|         smsService.addTemplate( | ||||
|                 sign, | ||||
|                 templateCode, | ||||
|                 template, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 sin-ning@aliyun.com
						sin-ning@aliyun.com