完成 SmsCodeApi、SmsSendApi 的 feign 支持

This commit is contained in:
YunaiV 2022-06-16 08:08:19 +08:00
parent b52a38d297
commit cca4c9fceb
10 changed files with 138 additions and 164 deletions

View File

@ -1,30 +1,39 @@
package cn.iocoder.yudao.module.system.api.sensitiveword; package cn.iocoder.yudao.module.system.api.sensitiveword;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFacx`tory =
* 敏感词 API 接口 @Api(tags = "RPC 服务 - 敏感词")
*
* @author 永不言败
*/
public interface SensitiveWordApi { public interface SensitiveWordApi {
/** String PREFIX = ApiConstants.PREFIX + "/oauth2/sensitive-word";
* 获得文本所包含的不合法的敏感词数组
*
* @param text 文本
* @param tags 标签数组
* @return 不合法的敏感词数组
*/
List<String> validateText(String text, List<String> tags);
/** @GetMapping(PREFIX + "/validate-text")
* 判断文本是否包含敏感词 @ApiOperation("获得文本所包含的不合法的敏感词数组")
* @ApiImplicitParams({
* @param text 文本 @ApiImplicitParam(name = "text", value = "文本", required = true, dataTypeClass = String.class),
* @param tags 表述数组 @ApiImplicitParam(name = "tags", value = "标签数组", required = true, allowMultiple = true)
* @return 是否包含 })
*/ CommonResult<List<String>> validateText(@RequestParam("text") String text,
boolean isTextValid(String text, List<String> tags); @RequestParam("tags") List<String> tags);
@GetMapping(PREFIX + "/is-text-valid")
@ApiOperation("判断文本是否包含敏感词")
@ApiImplicitParams({
@ApiImplicitParam(name = "text", value = "文本", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "tags", value = "标签数组", required = true, allowMultiple = true)
})
CommonResult<Boolean> isTextValid(@RequestParam("text") String text,
@RequestParam("tags") List<String> tags);
} }

View File

@ -1,40 +1,36 @@
package cn.iocoder.yudao.module.system.api.sms; package cn.iocoder.yudao.module.system.api.sms;
import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid; import javax.validation.Valid;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* 短信验证码 API 接口 @Api(tags = "RPC 服务 - 短信验证码")
*
* @author 芋道源码
*/
public interface SmsCodeApi { public interface SmsCodeApi {
/** String PREFIX = ApiConstants.PREFIX + "/oauth2/sms/code";
* 创建短信验证码并进行发送
*
* @param reqDTO 发送请求
*/
void sendSmsCode(@Valid SmsCodeSendReqDTO reqDTO);
/** @PostMapping(PREFIX + "/send")
* 验证短信验证码并进行使用 @ApiOperation("创建短信验证码,并进行发送")
* 如果正确则将验证码标记成已使用 CommonResult<Boolean> sendSmsCode(@Valid @RequestBody SmsCodeSendReqDTO reqDTO);
* 如果错误则抛出 {@link ServiceException} 异常
*
* @param reqDTO 使用请求
*/
void useSmsCode(@Valid SmsCodeUseReqDTO reqDTO);
/** @PutMapping(PREFIX + "/use")
* 检查验证码是否有效 @ApiOperation("验证短信验证码,并进行使用")
* CommonResult<Boolean> useSmsCode(@Valid @RequestBody SmsCodeUseReqDTO reqDTO);
* @param reqDTO 校验请求
*/ @GetMapping(PREFIX + "/check")
void checkSmsCode(@Valid SmsCodeCheckReqDTO reqDTO); @ApiOperation("检查验证码是否有效")
CommonResult<Boolean> checkSmsCode(@Valid @RequestBody SmsCodeCheckReqDTO reqDTO);
} }

View File

@ -1,34 +1,28 @@
package cn.iocoder.yudao.module.system.api.sms; package cn.iocoder.yudao.module.system.api.sms;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid; import javax.validation.Valid;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* 短信发送 API 接口 @Api(tags = "RPC 服务 - 短信发送")
*
* @author 芋道源码
*/
public interface SmsSendApi { public interface SmsSendApi {
/** String PREFIX = ApiConstants.PREFIX + "/oauth2/sms/send";
* 发送单条短信给 Admin 用户
*
* mobile 为空时使用 userId 加载对应 Admin 的手机号
*
* @param reqDTO 发送请求
* @return 发送日志编号
*/
Long sendSingleSmsToAdmin(@Valid SmsSendSingleToUserReqDTO reqDTO);
/** @PostMapping(PREFIX + "/send-single-admin")
* 发送单条短信给 Member 用户 @ApiOperation(value = "发送单条短信给 Admin 用户", notes = "在 mobile 为空时,使用 userId 加载对应 Admin 的手机号")
* CommonResult<Long> sendSingleSmsToAdmin(@Valid @RequestBody SmsSendSingleToUserReqDTO reqDTO);
* mobile 为空时使用 userId 加载对应 Member 的手机号
* @PostMapping(PREFIX + "/send-single-member")
* @param reqDTO 发送请求 @ApiOperation(value = "发送单条短信给 Member 用户", notes = "在 mobile 为空时,使用 userId 加载对应 Member 的手机号")
* @return 发送日志编号 CommonResult<Long> sendSingleSmsToMember(@Valid @RequestBody SmsSendSingleToUserReqDTO reqDTO);
*/
Long sendSingleSmsToMember(@Valid SmsSendSingleToUserReqDTO reqDTO);
} }

View File

@ -3,34 +3,26 @@ package cn.iocoder.yudao.module.system.api.sms.dto.code;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** @ApiModel("RPC 服务 - 短信验证码的校验 Request DTO")
* 短信验证码的校验 Request DTO
*
* @author 芋道源码
*/
@Data @Data
public class SmsCodeCheckReqDTO { public class SmsCodeCheckReqDTO {
/** @ApiModelProperty(value = "手机号", required = true, example = "15601691300")
* 手机号
*/
@Mobile @Mobile
@NotEmpty(message = "手机号不能为空") @NotEmpty(message = "手机号不能为空")
private String mobile; private String mobile;
/** @ApiModelProperty(value = "发送场景", required = true, example = "1")
* 发送场景
*/
@NotNull(message = "发送场景不能为空") @NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class) @InEnum(SmsSceneEnum.class)
private Integer scene; private Integer scene;
/** @ApiModelProperty(value = "验证码", required = true, example = "1024")
* 验证码
*/
@NotEmpty(message = "验证码") @NotEmpty(message = "验证码")
private String code; private String code;

View File

@ -3,34 +3,26 @@ package cn.iocoder.yudao.module.system.api.sms.dto.code;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** @ApiModel("RPC 服务 - 短信验证码的发送 Request DTO")
* 短信验证码的发送 Request DTO
*
* @author 芋道源码
*/
@Data @Data
public class SmsCodeSendReqDTO { public class SmsCodeSendReqDTO {
/** @ApiModelProperty(value = "手机号", required = true, example = "15601691300")
* 手机号
*/
@Mobile @Mobile
@NotEmpty(message = "手机号不能为空") @NotEmpty(message = "手机号不能为空")
private String mobile; private String mobile;
/** @ApiModelProperty(value = "发送场景", required = true, example = "1")
* 发送场景
*/
@NotNull(message = "发送场景不能为空") @NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class) @InEnum(SmsSceneEnum.class)
private Integer scene; private Integer scene;
/** @ApiModelProperty(value = "发送 IP", required = true, example = "10.20.30.40")
* 发送 IP
*/
@NotEmpty(message = "发送 IP 不能为空") @NotEmpty(message = "发送 IP 不能为空")
private String createIp; private String createIp;

View File

@ -3,39 +3,29 @@ package cn.iocoder.yudao.module.system.api.sms.dto.code;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** @ApiModel("RPC 服务 - 短信验证码的使用 Request DTO")
* 短信验证码的使用 Request DTO
*
* @author 芋道源码
*/
@Data @Data
public class SmsCodeUseReqDTO { public class SmsCodeUseReqDTO {
/** @ApiModelProperty(value = "手机号", required = true, example = "15601691300")
* 手机号
*/
@Mobile @Mobile
@NotEmpty(message = "手机号不能为空") @NotEmpty(message = "手机号不能为空")
private String mobile; private String mobile;
/** @ApiModelProperty(value = "发送场景", required = true, example = "1")
* 发送场景
*/
@NotNull(message = "发送场景不能为空") @NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class) @InEnum(SmsSceneEnum.class)
private Integer scene; private Integer scene;
/** @ApiModelProperty(value = "验证码", required = true, example = "1024")
* 验证码
*/
@NotEmpty(message = "验证码") @NotEmpty(message = "验证码")
private String code; private String code;
/** @ApiModelProperty(value = "发送 IP", required = true, example = "10.20.30.40")
* 使用 IP
*/
@NotEmpty(message = "使用 IP 不能为空") @NotEmpty(message = "使用 IP 不能为空")
private String usedIp; private String usedIp;

View File

@ -1,37 +1,27 @@
package cn.iocoder.yudao.module.system.api.sms.dto.send; package cn.iocoder.yudao.module.system.api.sms.dto.send;
import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Mobile;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Map; import java.util.Map;
/** @ApiModel("RPC 服务 - 短信发送给 Admin 或者 Member 用户 Request DTO")
* 短信发送给 Admin 或者 Member 用户
*
* @author 芋道源码
*/
@Data @Data
public class SmsSendSingleToUserReqDTO { public class SmsSendSingleToUserReqDTO {
/** @ApiModelProperty(value = "用户编号", example = "1024")
* 用户编号
*/
private Long userId; private Long userId;
/** @ApiModelProperty(value = "手机号", required = true, example = "15601691300")
* 手机号
*/
@Mobile @Mobile
private String mobile; private String mobile;
/** @ApiModelProperty(value = "用户编号", required = true, example = "USER_SEND")
* 短信模板编号
*/
@NotEmpty(message = "短信模板编号不能为空") @NotEmpty(message = "短信模板编号不能为空")
private String templateCode; private String templateCode;
/** @ApiModelProperty(value = "短信模板参数")
* 短信模板参数
*/
private Map<String, Object> templateParams; private Map<String, Object> templateParams;
} }

View File

@ -1,29 +1,34 @@
package cn.iocoder.yudao.module.system.api.sensitiveword; package cn.iocoder.yudao.module.system.api.sensitiveword;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
* 敏感词 API 实现类 import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;
*
* @author 永不言败 @RestController // 提供 RESTful API 接口 Feign 调用
*/ @DubboService(version = VERSION) // 提供 Dubbo RPC 接口 Dubbo Consumer 调用
@Service @Validated
public class SensitiveWordApiImpl implements SensitiveWordApi { public class SensitiveWordApiImpl implements SensitiveWordApi {
@Resource @Resource
private SensitiveWordService sensitiveWordService; private SensitiveWordService sensitiveWordService;
@Override @Override
public List<String> validateText(String text, List<String> tags) { public CommonResult<List<String>> validateText(String text, List<String> tags) {
return sensitiveWordService.validateText(text, tags); return success(sensitiveWordService.validateText(text, tags));
} }
@Override @Override
public boolean isTextValid(String text, List<String> tags) { public CommonResult<Boolean> isTextValid(String text, List<String> tags) {
return sensitiveWordService.isTextValid(text, tags); return success(sensitiveWordService.isTextValid(text, tags));
} }
} }

View File

@ -1,20 +1,21 @@
package cn.iocoder.yudao.module.system.api.sms; package cn.iocoder.yudao.module.system.api.sms;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
import cn.iocoder.yudao.module.system.service.sms.SmsCodeService; import cn.iocoder.yudao.module.system.service.sms.SmsCodeService;
import org.springframework.stereotype.Service; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
/** import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
* 短信验证码 API 实现类 import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;
*
* @author 芋道源码 @RestController // 提供 RESTful API 接口 Feign 调用
*/ @DubboService(version = VERSION) // 提供 Dubbo RPC 接口 Dubbo Consumer 调用
@Service
@Validated @Validated
public class SmsCodeApiImpl implements SmsCodeApi { public class SmsCodeApiImpl implements SmsCodeApi {
@ -22,18 +23,21 @@ public class SmsCodeApiImpl implements SmsCodeApi {
private SmsCodeService smsCodeService; private SmsCodeService smsCodeService;
@Override @Override
public void sendSmsCode(SmsCodeSendReqDTO reqDTO) { public CommonResult<Boolean> sendSmsCode(SmsCodeSendReqDTO reqDTO) {
smsCodeService.sendSmsCode(reqDTO); smsCodeService.sendSmsCode(reqDTO);
return success(true);
} }
@Override @Override
public void useSmsCode(SmsCodeUseReqDTO reqDTO) { public CommonResult<Boolean> useSmsCode(SmsCodeUseReqDTO reqDTO) {
smsCodeService.useSmsCode(reqDTO); smsCodeService.useSmsCode(reqDTO);
return success(true);
} }
@Override @Override
public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) { public CommonResult<Boolean> checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
smsCodeService.checkSmsCode(reqDTO); smsCodeService.checkSmsCode(reqDTO);
return success(true);
} }
} }

View File

@ -1,18 +1,20 @@
package cn.iocoder.yudao.module.system.api.sms; package cn.iocoder.yudao.module.system.api.sms;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.service.sms.SmsSendService; import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
/** import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
* 短信发送 API 接口 import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;
*
* @author 芋道源码 @RestController // 提供 RESTful API 接口 Feign 调用
*/ @DubboService(version = VERSION) // 提供 Dubbo RPC 接口 Dubbo Consumer 调用
@Service
@Validated @Validated
public class SmsSendApiImpl implements SmsSendApi { public class SmsSendApiImpl implements SmsSendApi {
@ -20,15 +22,15 @@ public class SmsSendApiImpl implements SmsSendApi {
private SmsSendService smsSendService; private SmsSendService smsSendService;
@Override @Override
public Long sendSingleSmsToAdmin(SmsSendSingleToUserReqDTO reqDTO) { public CommonResult<Long> sendSingleSmsToAdmin(SmsSendSingleToUserReqDTO reqDTO) {
return smsSendService.sendSingleSmsToAdmin(reqDTO.getMobile(), reqDTO.getUserId(), return success(smsSendService.sendSingleSmsToAdmin(reqDTO.getMobile(), reqDTO.getUserId(),
reqDTO.getTemplateCode(), reqDTO.getTemplateParams()); reqDTO.getTemplateCode(), reqDTO.getTemplateParams()));
} }
@Override @Override
public Long sendSingleSmsToMember(SmsSendSingleToUserReqDTO reqDTO) { public CommonResult<Long> sendSingleSmsToMember(SmsSendSingleToUserReqDTO reqDTO) {
return smsSendService.sendSingleSmsToMember(reqDTO.getMobile(), reqDTO.getUserId(), return success(smsSendService.sendSingleSmsToMember(reqDTO.getMobile(), reqDTO.getUserId(),
reqDTO.getTemplateCode(), reqDTO.getTemplateParams()); reqDTO.getTemplateCode(), reqDTO.getTemplateParams()));
} }
} }