完成 LoginLogApi、DictDataApi 的 feign 支持

pull/4/head
YunaiV 2022-06-15 22:59:06 +08:00
parent 2f1234cda8
commit 84744938be
8 changed files with 72 additions and 71 deletions

View File

@ -6,6 +6,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection; import java.util.Collection;
@ -17,6 +18,6 @@ public interface PostApi {
@GetMapping(PREFIX + "/valid") @GetMapping(PREFIX + "/valid")
@ApiImplicitParam(name = "ids", value = "部门编号数组", required = true, allowMultiple = true) @ApiImplicitParam(name = "ids", value = "部门编号数组", required = true, allowMultiple = true)
CommonResult<Boolean> validPosts(Collection<Long> ids); CommonResult<Boolean> validPosts(@RequestParam("ids") Collection<Long> ids);
} }

View File

@ -1,22 +1,28 @@
package cn.iocoder.yudao.module.system.api.dict; package cn.iocoder.yudao.module.system.api.dict;
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 java.util.Collection; import java.util.Collection;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* API @Api(tags = "RPC 服务 - 字典数据")
*
* @author
*/
public interface DictDataApi { public interface DictDataApi {
/** String PREFIX = ApiConstants.PREFIX + "/dict-data";
*
* 1. @GetMapping(PREFIX + "/valid")
* 2. @ApiOperation("校验字典数据们是否有效")
* @ApiImplicitParams({
* @param dictType @ApiImplicitParam(name = "dictType", value = "字典类型", required = true, dataTypeClass = String.class),
* @param values @ApiImplicitParam(name = "values", value = "字典数据值的数组", required = true, allowMultiple = true)
*/ })
void validDictDatas(String dictType, Collection<String> values); CommonResult<Boolean> validDictDatas(String dictType, Collection<String> values);
} }

View File

@ -1,21 +1,24 @@
package cn.iocoder.yudao.module.system.api.logger; package cn.iocoder.yudao.module.system.api.logger;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
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 LoginLogApi { public interface LoginLogApi {
/** String PREFIX = ApiConstants.PREFIX + "/login-log";
*
* @PostMapping(PREFIX + "/create")
* @param reqDTO @ApiOperation("创建登录日志")
*/ CommonResult<Boolean> createLoginLog(@Valid @RequestBody LoginLogCreateReqDTO reqDTO);
void createLoginLog(@Valid LoginLogCreateReqDTO reqDTO);
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.api.logger.dto; package cn.iocoder.yudao.module.system.api.logger.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
@ -15,48 +16,32 @@ import javax.validation.constraints.Size;
@Data @Data
public class LoginLogCreateReqDTO { public class LoginLogCreateReqDTO {
/** @ApiModelProperty(value = "日志类型", required = true, example = "1", notes = "参见 LoginLogTypeEnum 枚举类")
*
*/
@NotNull(message = "日志类型不能为空") @NotNull(message = "日志类型不能为空")
private Integer logType; private Integer logType;
/**
* @ApiModelProperty(value = "链路追踪编号", required = true, example = "89aca178-a370-411c-ae02-3f0d672be4ab")
*/
private String traceId; private String traceId;
/** @ApiModelProperty(value = "用户编号", example = "666")
*
*/
private Long userId; private Long userId;
/** @ApiModelProperty(value = "用户类型", required = true, example = "2", notes = "参见 UserTypeEnum 枚举")
*
*/
@NotNull(message = "用户类型不能为空") @NotNull(message = "用户类型不能为空")
private Integer userType; private Integer userType;
/** @ApiModelProperty(value = "用户账号", required = true, example = "yudao")
*
*/
@NotBlank(message = "用户账号不能为空") @NotBlank(message = "用户账号不能为空")
@Size(max = 30, message = "用户账号长度不能超过30个字符") @Size(max = 30, message = "用户账号长度不能超过30个字符")
private String username; private String username;
/** @ApiModelProperty(value = "登录结果", required = true, example = "1", notes = "参见 LoginResultEnum 枚举类")
*
*/
@NotNull(message = "登录结果不能为空") @NotNull(message = "登录结果不能为空")
private Integer result; private Integer result;
/** @ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1")
* IP
*/
@NotEmpty(message = "用户 IP 不能为空") @NotEmpty(message = "用户 IP 不能为空")
private String userIp; private String userIp;
/**
* UserAgent @ApiModelProperty(value = "浏览器 UserAgent", required = true, example = "Mozilla/5.0")
*
* Job UserAgent
*/
private String userAgent; private String userAgent;
} }

View File

@ -1,25 +1,30 @@
package cn.iocoder.yudao.module.system.api.dict; package cn.iocoder.yudao.module.system.api.dict;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.service.dict.DictDataService; import cn.iocoder.yudao.module.system.service.dict.DictDataService;
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.Collection; import java.util.Collection;
/** 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 DictDataApiImpl implements DictDataApi { public class DictDataApiImpl implements DictDataApi {
@Resource @Resource
private DictDataService dictDataService; private DictDataService dictDataService;
@Override @Override
public void validDictDatas(String dictType, Collection<String> values) { public CommonResult<Boolean> validDictDatas(String dictType, Collection<String> values) {
dictDataService.validDictDatas(dictType, values); dictDataService.validDictDatas(dictType, values);
return success(true);
} }
} }

View File

@ -1,18 +1,20 @@
package cn.iocoder.yudao.module.system.api.logger; package cn.iocoder.yudao.module.system.api.logger;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
import cn.iocoder.yudao.module.system.service.logger.LoginLogService; import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
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 LoginLogApiImpl implements LoginLogApi { public class LoginLogApiImpl implements LoginLogApi {
@ -20,8 +22,9 @@ public class LoginLogApiImpl implements LoginLogApi {
private LoginLogService loginLogService; private LoginLogService loginLogService;
@Override @Override
public void createLoginLog(LoginLogCreateReqDTO reqDTO) { public CommonResult<Boolean> createLoginLog(LoginLogCreateReqDTO reqDTO) {
loginLogService.createLoginLog(reqDTO); loginLogService.createLoginLog(reqDTO);
return success(true);
} }
} }

View File

@ -19,7 +19,7 @@ public class LoginLogBaseVO {
@NotNull(message = "日志类型不能为空") @NotNull(message = "日志类型不能为空")
private Integer logType; private Integer logType;
@ApiModelProperty(value = "链路追踪编号", required = true, example = "89aca178-a370-411c-ae02-3f0d672be4ab") @ApiModelProperty(value = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab")
@NotEmpty(message = "链路追踪编号不能为空") @NotEmpty(message = "链路追踪编号不能为空")
private String traceId; private String traceId;
@ -36,8 +36,7 @@ public class LoginLogBaseVO {
@NotEmpty(message = "用户 IP 不能为空") @NotEmpty(message = "用户 IP 不能为空")
private String userIp; private String userIp;
@ApiModelProperty(value = "浏览器 UserAgent", required = true, example = "Mozilla/5.0") @ApiModelProperty(value = "浏览器 UserAgent", example = "Mozilla/5.0")
@NotEmpty(message = "浏览器 UserAgent 不能为空")
private String userAgent; private String userAgent;
} }

View File

@ -18,8 +18,7 @@ public class LoginLogRespVO extends LoginLogBaseVO {
@ApiModelProperty(value = "日志编号", required = true, example = "1024") @ApiModelProperty(value = "日志编号", required = true, example = "1024")
private Long id; private Long id;
@ApiModelProperty(value = "用户编号", required = true, example = "666") @ApiModelProperty(value = "用户编号", example = "666")
@NotNull(message = "用户编号不能为空")
private Long userId; private Long userId;
@ApiModelProperty(value = "用户类型", required = true, example = "2", notes = "参见 UserTypeEnum 枚举") @ApiModelProperty(value = "用户类型", required = true, example = "2", notes = "参见 UserTypeEnum 枚举")