refactor: 升级框架
This commit is contained in:
@@ -64,6 +64,13 @@
|
||||
<scope>provided</scope> <!-- 设置为 provided,主要是 PageParam 使用到 -->
|
||||
</dependency>
|
||||
|
||||
<!-- RPC 远程调用相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<scope>provided</scope> <!-- 设置为 provided,主要是 api 包使用到 -->
|
||||
</dependency>
|
||||
|
||||
<!-- 监控相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.agt.framework.common.biz.infra.logger;
|
||||
|
||||
import org.agt.framework.common.biz.infra.logger.dto.ApiAccessLogCreateReqDTO;
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = RpcConstants.INFRA_NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - API 访问日志")
|
||||
public interface ApiAccessLogCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.INFRA_PREFIX + "/api-access-log";
|
||||
|
||||
@PostMapping(PREFIX + "/create")
|
||||
@Operation(summary = "创建 API 访问日志")
|
||||
CommonResult<Boolean> createApiAccessLog(@Valid @RequestBody ApiAccessLogCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 【异步】创建 API 访问日志
|
||||
*
|
||||
* @param createDTO 访问日志 DTO
|
||||
*/
|
||||
@Async
|
||||
default void createApiAccessLogAsync(ApiAccessLogCreateReqDTO createDTO) {
|
||||
createApiAccessLog(createDTO).checkError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.agt.framework.common.biz.infra.logger;
|
||||
|
||||
import org.agt.framework.common.biz.infra.logger.dto.ApiErrorLogCreateReqDTO;
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = RpcConstants.INFRA_NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - API 异常日志")
|
||||
public interface ApiErrorLogCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.INFRA_PREFIX + "/api-error-log";
|
||||
|
||||
@PostMapping(PREFIX + "/create")
|
||||
@Operation(summary = "创建 API 异常日志")
|
||||
CommonResult<Boolean> createApiErrorLog(@Valid @RequestBody ApiErrorLogCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 【异步】创建 API 异常日志
|
||||
*
|
||||
* @param createDTO 异常日志 DTO
|
||||
*/
|
||||
@Async
|
||||
default void createApiErrorLogAsync(ApiErrorLogCreateReqDTO createDTO) {
|
||||
createApiErrorLog(createDTO).checkError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package org.agt.framework.common.biz.infra.logger.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* API 访问日志
|
||||
*
|
||||
* @author 千通源码
|
||||
*/
|
||||
@Data
|
||||
public class ApiAccessLogCreateReqDTO {
|
||||
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*/
|
||||
private String traceId;
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private Integer userType;
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
@NotNull(message = "应用名不能为空")
|
||||
private String applicationName;
|
||||
|
||||
/**
|
||||
* 请求方法名
|
||||
*/
|
||||
@NotNull(message = "http 请求方法不能为空")
|
||||
private String requestMethod;
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
@NotNull(message = "访问地址不能为空")
|
||||
private String requestUrl;
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private String requestParams;
|
||||
/**
|
||||
* 响应结果
|
||||
*/
|
||||
private String responseBody;
|
||||
/**
|
||||
* 用户 IP
|
||||
*/
|
||||
@NotNull(message = "ip 不能为空")
|
||||
private String userIp;
|
||||
/**
|
||||
* 浏览器 UA
|
||||
*/
|
||||
@NotNull(message = "User-Agent 不能为空")
|
||||
private String userAgent;
|
||||
|
||||
/**
|
||||
* 操作模块
|
||||
*/
|
||||
private String operateModule;
|
||||
/**
|
||||
* 操作名
|
||||
*/
|
||||
private String operateName;
|
||||
/**
|
||||
* 操作分类
|
||||
*
|
||||
* 枚举,参见 OperateTypeEnum 类
|
||||
*/
|
||||
private Integer operateType;
|
||||
|
||||
/**
|
||||
* 开始请求时间
|
||||
*/
|
||||
@NotNull(message = "开始请求时间不能为空")
|
||||
private LocalDateTime beginTime;
|
||||
/**
|
||||
* 结束请求时间
|
||||
*/
|
||||
@NotNull(message = "结束请求时间不能为空")
|
||||
private LocalDateTime endTime;
|
||||
/**
|
||||
* 执行时长,单位:毫秒
|
||||
*/
|
||||
@NotNull(message = "执行时长不能为空")
|
||||
private Integer duration;
|
||||
/**
|
||||
* 结果码
|
||||
*/
|
||||
@NotNull(message = "错误码不能为空")
|
||||
private Integer resultCode;
|
||||
/**
|
||||
* 结果提示
|
||||
*/
|
||||
private String resultMsg;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.agt.framework.common.biz.infra.logger.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "RPC 服务 - API 错误日志创建 Request DTO")
|
||||
@Data
|
||||
public class ApiErrorLogCreateReqDTO {
|
||||
|
||||
@Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long userId;
|
||||
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer userType;
|
||||
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "system-server")
|
||||
@NotNull(message = "应用名不能为空")
|
||||
private String applicationName;
|
||||
|
||||
@Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET")
|
||||
@NotNull(message = "http 请求方法不能为空")
|
||||
private String requestMethod;
|
||||
@Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy")
|
||||
@NotNull(message = "访问地址不能为空")
|
||||
private String requestUrl;
|
||||
@Schema(description = "请求参数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "请求参数不能为空")
|
||||
private String requestParams;
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
@NotNull(message = "ip 不能为空")
|
||||
private String userIp;
|
||||
@Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0")
|
||||
@NotNull(message = "User-Agent 不能为空")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "异常时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常时间不能为空")
|
||||
private LocalDateTime exceptionTime;
|
||||
@Schema(description = "异常名", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常名不能为空")
|
||||
private String exceptionName;
|
||||
@Schema(description = "异常发生的类全名", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常发生的类全名不能为空")
|
||||
private String exceptionClassName;
|
||||
@Schema(description = "异常发生的类文件", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常发生的类文件不能为空")
|
||||
private String exceptionFileName;
|
||||
@Schema(description = "异常发生的方法名", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常发生的方法名不能为空")
|
||||
private String exceptionMethodName;
|
||||
@Schema(description = "异常发生的方法所在行", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常发生的方法所在行不能为空")
|
||||
private Integer exceptionLineNumber;
|
||||
@Schema(description = "异常的栈轨迹异常的栈轨迹", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常的栈轨迹不能为空")
|
||||
private String exceptionStackTrace;
|
||||
@Schema(description = "异常导致的根消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常导致的根消息不能为空")
|
||||
private String exceptionRootCauseMessage;
|
||||
@Schema(description = "异常导致的消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "异常导致的消息不能为空")
|
||||
private String exceptionMessage;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 针对 infra 模块的 api 包
|
||||
*/
|
||||
package org.agt.framework.common.biz.infra;
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 特殊:用于 framework 下,starter 需要调用 biz 业务模块的接口定义!
|
||||
*/
|
||||
package org.agt.framework.common.biz;
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.agt.framework.common.biz.system.dict;
|
||||
|
||||
import org.agt.framework.common.biz.system.dict.dto.DictDataRespDTO;
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = RpcConstants.SYSTEM_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 字典数据")
|
||||
public interface DictDataCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.SYSTEM_PREFIX + "/dict-data";
|
||||
|
||||
@GetMapping(PREFIX + "/list")
|
||||
@Operation(summary = "获得指定字典类型的字典数据列表")
|
||||
@Parameter(name = "dictType", description = "字典类型", example = "SEX", required = true)
|
||||
CommonResult<List<DictDataRespDTO>> getDictDataList(@RequestParam("dictType") String dictType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.agt.framework.common.biz.system.dict.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "RPC 服务 - 字典数据 Response DTO")
|
||||
@Data
|
||||
public class DictDataRespDTO {
|
||||
|
||||
@Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "千通")
|
||||
private String label;
|
||||
|
||||
@Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
|
||||
private String value;
|
||||
|
||||
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
|
||||
private String dictType;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer status; // 参见 CommonStatusEnum 枚举
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.agt.framework.common.biz.system.logger;
|
||||
|
||||
import org.agt.framework.common.biz.system.logger.dto.OperateLogCreateReqDTO;
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = RpcConstants.SYSTEM_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 操作日志")
|
||||
public interface OperateLogCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.SYSTEM_PREFIX + "/operate-log";
|
||||
|
||||
@PostMapping(PREFIX + "/create")
|
||||
@Operation(summary = "创建操作日志")
|
||||
CommonResult<Boolean> createOperateLog(@Valid @RequestBody OperateLogCreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 【异步】创建操作日志
|
||||
*
|
||||
* @param createReqDTO 请求
|
||||
*/
|
||||
@Async
|
||||
default void createOperateLogAsync(OperateLogCreateReqDTO createReqDTO) {
|
||||
createOperateLog(createReqDTO).checkError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.agt.framework.common.biz.system.logger.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(name = "RPC 服务 - 系统操作日志 Create Request DTO")
|
||||
@Data
|
||||
public class OperateLogCreateReqDTO {
|
||||
|
||||
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2" )
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
@Schema(description = "操作模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单")
|
||||
@NotEmpty(message = "操作模块类型不能为空")
|
||||
private String type;
|
||||
@Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单")
|
||||
@NotEmpty(message = "操作名不能为空")
|
||||
private String subType;
|
||||
@Schema(description = "操作模块业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "188")
|
||||
@NotNull(message = "操作模块业务编号不能为空")
|
||||
private Long bizId;
|
||||
@Schema(description = "操作内容", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从千通改成源码")
|
||||
@NotEmpty(message = "操作内容不能为空")
|
||||
private String action;
|
||||
@Schema(description = "拓展字段", example = "{\"orderId\": \"1\"}")
|
||||
private String extra;
|
||||
|
||||
@Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET")
|
||||
@NotEmpty(message = "请求方法名不能为空")
|
||||
private String requestMethod;
|
||||
@Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/order/get")
|
||||
@NotEmpty(message = "请求地址不能为空")
|
||||
private String requestUrl;
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
@NotEmpty(message = "用户 IP 不能为空")
|
||||
private String userIp;
|
||||
@Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0")
|
||||
@NotEmpty(message = "浏览器 UA 不能为空")
|
||||
private String userAgent;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.agt.framework.common.biz.system.oauth2;
|
||||
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import org.agt.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
|
||||
import org.agt.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenCreateReqDTO;
|
||||
import org.agt.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenRespDTO;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@FeignClient(name = RpcConstants.SYSTEM_NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - OAuth2.0 令牌")
|
||||
public interface OAuth2TokenCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.SYSTEM_PREFIX + "/oauth2/token";
|
||||
|
||||
/**
|
||||
* 校验 Token 的 URL 地址,主要是提供给 Gateway 使用
|
||||
*/
|
||||
@SuppressWarnings("HttpUrlsUsage")
|
||||
String URL_CHECK = "http://" + RpcConstants.SYSTEM_NAME + PREFIX + "/check";
|
||||
|
||||
@PostMapping(PREFIX + "/create")
|
||||
@Operation(summary = "创建访问令牌")
|
||||
CommonResult<OAuth2AccessTokenRespDTO> createAccessToken(@Valid @RequestBody OAuth2AccessTokenCreateReqDTO reqDTO);
|
||||
|
||||
@GetMapping(PREFIX + "/check")
|
||||
@Operation(summary = "校验访问令牌")
|
||||
@Parameter(name = "accessToken", description = "访问令牌", required = true, example = "tudou")
|
||||
CommonResult<OAuth2AccessTokenCheckRespDTO> checkAccessToken(@RequestParam("accessToken") String accessToken);
|
||||
|
||||
@DeleteMapping(PREFIX + "/remove")
|
||||
@Operation(summary = "移除访问令牌")
|
||||
@Parameter(name = "accessToken", description = "访问令牌", required = true, example = "tudou")
|
||||
CommonResult<OAuth2AccessTokenRespDTO> removeAccessToken(@RequestParam("accessToken") String accessToken);
|
||||
|
||||
@PutMapping(PREFIX + "/refresh")
|
||||
@Operation(summary = "刷新访问令牌")
|
||||
@Parameters({
|
||||
@Parameter(name = "refreshToken", description = "刷新令牌", required = true, example = "haha"),
|
||||
@Parameter(name = "clientId", description = "客户端编号", required = true, example = "agtyuanma")
|
||||
})
|
||||
CommonResult<OAuth2AccessTokenRespDTO> refreshAccessToken(@RequestParam("refreshToken") String refreshToken,
|
||||
@RequestParam("clientId") String clientId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.agt.framework.common.biz.system.oauth2.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "RPC 服务 - OAuth2 访问令牌的校验 Response DTO")
|
||||
@Data
|
||||
public class OAuth2AccessTokenCheckRespDTO implements Serializable {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "用户信息", example = "{\"nickname\": \"千通\"}")
|
||||
private Map<String, String> userInfo;
|
||||
|
||||
@Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "授权范围的数组", example = "user_info")
|
||||
private List<String> scopes;
|
||||
|
||||
@Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime expiresTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.agt.framework.common.biz.system.oauth2.dto;
|
||||
|
||||
import org.agt.framework.common.enums.UserTypeEnum;
|
||||
import org.agt.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "RPC 服务 - OAuth2 访问令牌创建 Request DTO")
|
||||
@Data
|
||||
public class OAuth2AccessTokenCreateReqDTO implements Serializable {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "agtyuanma")
|
||||
@NotNull(message = "客户端编号不能为空")
|
||||
private String clientId;
|
||||
|
||||
@Schema(description = "授权范围的数组", example = "user_info")
|
||||
private List<String> scopes;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.agt.framework.common.biz.system.oauth2.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "RPC 服务 - OAuth2 访问令牌的信息 Response DTO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OAuth2AccessTokenRespDTO implements Serializable {
|
||||
|
||||
@Schema(description = "访问令牌", requiredMode = Schema.RequiredMode.REQUIRED, example = "tudou")
|
||||
private String accessToken;
|
||||
|
||||
@Schema(description = "刷新令牌", requiredMode = Schema.RequiredMode.REQUIRED, example = "haha")
|
||||
private String refreshToken;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1" )
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime expiresTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 针对 system 模块的 api 包
|
||||
*/
|
||||
package org.agt.framework.common.biz.system;
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.agt.framework.common.biz.system.permission;
|
||||
|
||||
import org.agt.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@FeignClient(name = RpcConstants.SYSTEM_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 权限")
|
||||
public interface PermissionCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.SYSTEM_PREFIX + "/permission";
|
||||
|
||||
@GetMapping(PREFIX + "/has-any-permissions")
|
||||
@Operation(summary = "判断是否有权限,任一一个即可")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户编号", example = "1", required = true),
|
||||
@Parameter(name = "permissions", description = "权限", example = "read,write", required = true)
|
||||
})
|
||||
CommonResult<Boolean> hasAnyPermissions(@RequestParam("userId") Long userId,
|
||||
@RequestParam("permissions") String... permissions);
|
||||
|
||||
@GetMapping(PREFIX + "/has-any-roles")
|
||||
@Operation(summary = "判断是否有角色,任一一个即可")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户编号", example = "1", required = true),
|
||||
@Parameter(name = "roles", description = "角色数组", example = "2", required = true)
|
||||
})
|
||||
CommonResult<Boolean> hasAnyRoles(@RequestParam("userId") Long userId,
|
||||
@RequestParam("roles") String... roles);
|
||||
|
||||
@GetMapping(PREFIX + "/get-dept-data-permission")
|
||||
@Operation(summary = "获得登陆用户的部门数据权限")
|
||||
@Parameter(name = "userId", description = "用户编号", example = "2", required = true)
|
||||
CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(@RequestParam("userId") Long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.agt.framework.common.biz.system.permission.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Schema(description = "RPC 服务 - 部门的数据权限 Response DTO")
|
||||
@Data
|
||||
public class DeptDataPermissionRespDTO {
|
||||
|
||||
@Schema(description = "是否可查看全部数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
private Boolean all;
|
||||
|
||||
@Schema(description = "是否可查看自己的数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
private Boolean self;
|
||||
|
||||
@Schema(description = "可查看的部门编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 3]")
|
||||
private Set<Long> deptIds;
|
||||
|
||||
public DeptDataPermissionRespDTO() {
|
||||
this.all = false;
|
||||
this.self = false;
|
||||
this.deptIds = new HashSet<>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.agt.framework.common.biz.system.tenant;
|
||||
|
||||
import org.agt.framework.common.enums.RpcConstants;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = RpcConstants.SYSTEM_NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 多租户")
|
||||
public interface TenantCommonApi {
|
||||
|
||||
String PREFIX = RpcConstants.SYSTEM_PREFIX + "/tenant";
|
||||
|
||||
@GetMapping(PREFIX + "/id-list")
|
||||
@Operation(summary = "获得所有租户编号")
|
||||
CommonResult<List<Long>> getTenantIdList();
|
||||
|
||||
@GetMapping(PREFIX + "/valid")
|
||||
@Operation(summary = "校验租户是否合法")
|
||||
@Parameter(name = "id", description = "租户编号", required = true, example = "1024")
|
||||
CommonResult<Boolean> validTenant(@RequestParam("id") Long id);
|
||||
|
||||
}
|
||||
@@ -7,11 +7,34 @@ package org.agt.framework.common.enums;
|
||||
*
|
||||
* @author 千通源码
|
||||
*/
|
||||
public class RpcConstants {
|
||||
public interface RpcConstants {
|
||||
|
||||
/**
|
||||
* RPC API 的前缀
|
||||
*/
|
||||
public static final String RPC_API_PREFIX = "/rpc-api";
|
||||
String RPC_API_PREFIX = "/rpc-api";
|
||||
|
||||
/**
|
||||
* system 服务名
|
||||
*
|
||||
* 注意,需要保证和 spring.application.name 保持一致
|
||||
*/
|
||||
String SYSTEM_NAME = "system-server";
|
||||
|
||||
/**
|
||||
* system 服务的前缀
|
||||
*/
|
||||
String SYSTEM_PREFIX = RPC_API_PREFIX + "/system";
|
||||
|
||||
/**
|
||||
* infra 服务名
|
||||
*
|
||||
* 注意,需要保证和 spring.application.name 保持一致
|
||||
*/
|
||||
String INFRA_NAME = "infra-server";
|
||||
/**
|
||||
* infra 服务的前缀
|
||||
*/
|
||||
String INFRA_PREFIX = RPC_API_PREFIX + "/infra";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user