完成 SmsCodeApi、SmsSendApi 的 feign 支持

pull/4/head
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;
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;
/**
* API
*
* @author
*/
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFacx`tory =
@Api(tags = "RPC 服务 - 敏感词")
public interface SensitiveWordApi {
/**
*
*
* @param text
* @param tags
* @return
*/
List<String> validateText(String text, List<String> tags);
String PREFIX = ApiConstants.PREFIX + "/oauth2/sensitive-word";
/**
*
*
* @param text
* @param tags
* @return
*/
boolean isTextValid(String text, List<String> tags);
@GetMapping(PREFIX + "/validate-text")
@ApiOperation("获得文本所包含的不合法的敏感词数组")
@ApiImplicitParams({
@ApiImplicitParam(name = "text", value = "文本", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "tags", value = "标签数组", required = true, allowMultiple = true)
})
CommonResult<List<String>> validateText(@RequestParam("text") String text,
@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;
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.SmsCodeSendReqDTO;
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;
/**
* API
*
* @author
*/
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Api(tags = "RPC 服务 - 短信验证码")
public interface SmsCodeApi {
/**
*
*
* @param reqDTO
*/
void sendSmsCode(@Valid SmsCodeSendReqDTO reqDTO);
String PREFIX = ApiConstants.PREFIX + "/oauth2/sms/code";
/**
* 使
* 使
* {@link ServiceException}
*
* @param reqDTO 使
*/
void useSmsCode(@Valid SmsCodeUseReqDTO reqDTO);
@PostMapping(PREFIX + "/send")
@ApiOperation("创建短信验证码,并进行发送")
CommonResult<Boolean> sendSmsCode(@Valid @RequestBody SmsCodeSendReqDTO reqDTO);
/**
*
*
* @param reqDTO
*/
void checkSmsCode(@Valid SmsCodeCheckReqDTO reqDTO);
@PutMapping(PREFIX + "/use")
@ApiOperation("验证短信验证码,并进行使用")
CommonResult<Boolean> useSmsCode(@Valid @RequestBody SmsCodeUseReqDTO reqDTO);
@GetMapping(PREFIX + "/check")
@ApiOperation("检查验证码是否有效")
CommonResult<Boolean> checkSmsCode(@Valid @RequestBody SmsCodeCheckReqDTO reqDTO);
}

View File

@ -1,34 +1,28 @@
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.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;
/**
* API
*
* @author
*/
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Api(tags = "RPC 服务 - 短信发送")
public interface SmsSendApi {
/**
* Admin
*
* mobile 使 userId Admin
*
* @param reqDTO
* @return
*/
Long sendSingleSmsToAdmin(@Valid SmsSendSingleToUserReqDTO reqDTO);
String PREFIX = ApiConstants.PREFIX + "/oauth2/sms/send";
/**
* Member
*
* mobile 使 userId Member
*
* @param reqDTO
* @return
*/
Long sendSingleSmsToMember(@Valid SmsSendSingleToUserReqDTO reqDTO);
@PostMapping(PREFIX + "/send-single-admin")
@ApiOperation(value = "发送单条短信给 Admin 用户", notes = "在 mobile 为空时,使用 userId 加载对应 Admin 的手机号")
CommonResult<Long> sendSingleSmsToAdmin(@Valid @RequestBody SmsSendSingleToUserReqDTO reqDTO);
@PostMapping(PREFIX + "/send-single-member")
@ApiOperation(value = "发送单条短信给 Member 用户", notes = "在 mobile 为空时,使用 userId 加载对应 Member 的手机号")
CommonResult<Long> sendSingleSmsToMember(@Valid @RequestBody 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.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Request DTO
*
* @author
*/
@ApiModel("RPC 服务 - 短信验证码的校验 Request DTO")
@Data
public class SmsCodeCheckReqDTO {
/**
*
*/
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@Mobile
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
*
*/
@ApiModelProperty(value = "发送场景", required = true, example = "1")
@NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class)
private Integer scene;
/**
*
*/
@ApiModelProperty(value = "验证码", required = true, example = "1024")
@NotEmpty(message = "验证码")
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.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Request DTO
*
* @author
*/
@ApiModel("RPC 服务 - 短信验证码的发送 Request DTO")
@Data
public class SmsCodeSendReqDTO {
/**
*
*/
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@Mobile
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
*
*/
@ApiModelProperty(value = "发送场景", required = true, example = "1")
@NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class)
private Integer scene;
/**
* IP
*/
@ApiModelProperty(value = "发送 IP", required = true, example = "10.20.30.40")
@NotEmpty(message = "发送 IP 不能为空")
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.Mobile;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 使 Request DTO
*
* @author
*/
@ApiModel("RPC 服务 - 短信验证码的使用 Request DTO")
@Data
public class SmsCodeUseReqDTO {
/**
*
*/
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@Mobile
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
*
*/
@ApiModelProperty(value = "发送场景", required = true, example = "1")
@NotNull(message = "发送场景不能为空")
@InEnum(SmsSceneEnum.class)
private Integer scene;
/**
*
*/
@ApiModelProperty(value = "验证码", required = true, example = "1024")
@NotEmpty(message = "验证码")
private String code;
/**
* 使 IP
*/
@ApiModelProperty(value = "发送 IP", required = true, example = "10.20.30.40")
@NotEmpty(message = "使用 IP 不能为空")
private String usedIp;

View File

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

View File

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

View File

@ -1,20 +1,21 @@
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.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
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.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* API
*
* @author
*/
@Service
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口,给 Dubbo Consumer 调用
@Validated
public class SmsCodeApiImpl implements SmsCodeApi {
@ -22,18 +23,21 @@ public class SmsCodeApiImpl implements SmsCodeApi {
private SmsCodeService smsCodeService;
@Override
public void sendSmsCode(SmsCodeSendReqDTO reqDTO) {
public CommonResult<Boolean> sendSmsCode(SmsCodeSendReqDTO reqDTO) {
smsCodeService.sendSmsCode(reqDTO);
return success(true);
}
@Override
public void useSmsCode(SmsCodeUseReqDTO reqDTO) {
public CommonResult<Boolean> useSmsCode(SmsCodeUseReqDTO reqDTO) {
smsCodeService.useSmsCode(reqDTO);
return success(true);
}
@Override
public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
public CommonResult<Boolean> checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
smsCodeService.checkSmsCode(reqDTO);
return success(true);
}
}

View File

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