refactor: 升级框架

This commit is contained in:
caiyuchao
2025-05-21 14:13:15 +08:00
parent b2a5bedb30
commit 27941674a7
1000 changed files with 1833 additions and 1800 deletions

View File

@@ -1,26 +1,21 @@
package org.agt.module.system.api.dict;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import org.agt.framework.common.biz.system.dict.DictDataCommonApi;
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.agt.framework.common.pojo.CommonResult;
import org.agt.module.system.api.dict.dto.DictDataRespDTO;
import org.agt.module.system.enums.ApiConstants;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection;
import java.util.List;
import static org.agt.framework.common.util.collection.CollectionUtils.convertList;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 字典数据")
public interface DictDataApi {
public interface DictDataApi extends DictDataCommonApi {
String PREFIX = ApiConstants.PREFIX + "/dict-data";
@@ -33,53 +28,4 @@ public interface DictDataApi {
CommonResult<Boolean> validateDictDataList(@RequestParam("dictType") String dictType,
@RequestParam("values") Collection<String> values);
@GetMapping(PREFIX + "/get")
@Operation(summary = "获得指定的字典数据")
@Parameters({
@Parameter(name = "dictType", description = "字典类型", example = "SEX", required = true),
@Parameter(name = "description", description = "字典数据值", example = "1", required = true)
})
CommonResult<DictDataRespDTO> getDictData(@RequestParam("dictType") String dictType,
@RequestParam("value") String value);
/**
* 获得指定的字典标签,从缓存中
*
* @param type 字典类型
* @param value 字典数据值
* @return 字典标签
*/
default String getDictDataLabel(String type, Integer value) {
DictDataRespDTO dictData = getDictData(type, String.valueOf(value)).getData();
if (ObjUtil.isNull(dictData)) {
return StrUtil.EMPTY;
}
return dictData.getLabel();
}
@GetMapping(PREFIX + "/parse")
@Operation(summary = "解析获得指定的字典数据")
@Parameters({
@Parameter(name = "dictType", description = "字典类型", example = "SEX", required = true),
@Parameter(name = "label", description = "字典标签", example = "", required = true)
})
CommonResult<DictDataRespDTO> parseDictData(@RequestParam("dictType") String dictType,
@RequestParam("label") String label);
@GetMapping(PREFIX + "/list")
@Operation(summary = "获得指定字典类型的字典数据列表")
@Parameter(name = "dictType", description = "字典类型", example = "SEX", required = true)
CommonResult<List<DictDataRespDTO>> getDictDataList(@RequestParam("dictType") String dictType);
/**
* 获得字典数据标签列表
*
* @param dictType 字典类型
* @return 字典数据标签列表
*/
default List<String> getDictDataLabelList(String dictType) {
List<DictDataRespDTO> list = getDictDataList(dictType).getData();
return convertList(list, DictDataRespDTO::getLabel);
}
}

View File

@@ -1,22 +0,0 @@
package org.agt.module.system.api.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 枚举
}

View File

@@ -1,41 +1,23 @@
package org.agt.module.system.api.logger;
import org.agt.framework.common.biz.system.logger.OperateLogCommonApi;
import org.agt.framework.common.pojo.CommonResult;
import org.agt.framework.common.pojo.PageResult;
import org.agt.module.system.api.logger.dto.OperateLogCreateReqDTO;
import org.agt.module.system.api.logger.dto.OperateLogPageReqDTO;
import org.agt.module.system.api.logger.dto.OperateLogRespDTO;
import org.agt.module.system.enums.ApiConstants;
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.cloud.openfeign.SpringQueryMap;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 操作日志")
public interface OperateLogApi {
public interface OperateLogApi extends OperateLogCommonApi {
String PREFIX = ApiConstants.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();
}
@GetMapping(PREFIX + "/page")
@Operation(summary = "获取指定模块的指定数据的操作日志分页")
CommonResult<PageResult<OperateLogRespDTO>> getOperateLogPage(@SpringQueryMap OperateLogPageReqDTO pageReqDTO);

View File

@@ -1,50 +0,0 @@
package org.agt.module.system.api.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;
}

View File

@@ -1,52 +0,0 @@
package org.agt.module.system.api.oauth2;
import org.agt.framework.common.pojo.CommonResult;
import org.agt.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
import org.agt.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO;
import org.agt.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO;
import org.agt.module.system.enums.ApiConstants;
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 = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - OAuth2.0 令牌")
public interface OAuth2TokenApi {
String PREFIX = ApiConstants.PREFIX + "/oauth2/token";
/**
* 校验 Token 的 URL 地址,主要是提供给 Gateway 使用
*/
@SuppressWarnings("HttpUrlsUsage")
String URL_CHECK = "http://" + ApiConstants.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);
}

View File

@@ -1,33 +0,0 @@
package org.agt.module.system.api.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;
}

View File

@@ -1,32 +0,0 @@
package org.agt.module.system.api.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;
}

View File

@@ -1,30 +0,0 @@
package org.agt.module.system.api.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;
}

View File

@@ -1,11 +1,10 @@
package org.agt.module.system.api.permission;
import org.agt.framework.common.biz.system.permission.PermissionCommonApi;
import org.agt.framework.common.pojo.CommonResult;
import org.agt.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import org.agt.module.system.enums.ApiConstants;
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.GetMapping;
@@ -16,7 +15,7 @@ import java.util.Set;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 权限")
public interface PermissionApi {
public interface PermissionApi extends PermissionCommonApi {
String PREFIX = ApiConstants.PREFIX + "/permission";
@@ -25,27 +24,4 @@ public interface PermissionApi {
@Parameter(name = "roleIds", description = "角色编号集合", example = "1,2", required = true)
CommonResult<Set<Long>> getUserRoleIdListByRoleIds(@RequestParam("roleIds") Collection<Long> roleIds);
@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);
}

View File

@@ -1,28 +0,0 @@
package org.agt.module.system.api.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<>();
}
}

View File

@@ -1,29 +0,0 @@
package org.agt.module.system.api.tenant;
import org.agt.framework.common.pojo.CommonResult;
import org.agt.module.system.enums.ApiConstants;
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 = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 多租户")
public interface TenantApi {
String PREFIX = ApiConstants.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);
}