@ -2,17 +2,20 @@ package apelet.common.openapi.controller;
@@ -2,17 +2,20 @@ package apelet.common.openapi.controller;
import apelet.common.core.annotation.MyRequestBody ;
import apelet.common.core.constant.ErrorCodeEnum ;
import apelet.common.core.mcp.annotation.McpToolClass ;
import apelet.common.core.mcp.annotation.McpToolParam ;
import apelet.common.core.mcp.model.McpToolParamType ;
import apelet.common.core.object.MyPageData ;
import apelet.common.core.object.MyPageParam ;
import apelet.common.core.object.ResponseResult ;
import apelet.common.core.util.MyCommonUtil ;
import apelet.common.core.util.MyPageUtil ;
import apelet.common.openapi.dto.OpenApiFieldDto ;
import apelet.common.openapi.dto.OpenApiFormOptionDto ;
import apelet.common.openapi.dto.OpenApiOperationDto ;
import apelet.common.openapi.dto.OpenApiPageOptionDto ;
import apelet.common.openapi.dto.* ;
import apelet.common.openapi.model.OpenApiConfig ;
import apelet.common.openapi.model.OpenAppApiRelation ;
import apelet.common.openapi.service.OpenApiConfigService ;
import apelet.common.openapi.vo.OpenApiConfigVo ;
import cn.hutool.core.collection.CollectionUtil ;
import com.github.pagehelper.page.PageMethod ;
import io.swagger.v3.oas.annotations.tags.Tag ;
import lombok.extern.slf4j.Slf4j ;
@ -20,7 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
@@ -20,7 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
import org.springframework.web.bind.annotation.* ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
/ * *
* OpenAPI 开放接口配置管理接口 ( 内部 , 供前端开放平台界面调用 ) 。
@ -42,7 +48,8 @@ public class OpenApiConfigController {
@@ -42,7 +48,8 @@ public class OpenApiConfigController {
* 在线页面列表 ( 配置步骤1 选择 ) , 可按页面名称模糊搜索 。
* /
@GetMapping ( "/pages" )
public ResponseResult < List < OpenApiPageOptionDto > > pages ( @RequestParam ( required = false ) String keyword ) {
@McpToolClass ( name = "openapi_config_page_options" , description = "OpenAPI 配置步骤1:在线页面下拉,可按页面名称模糊搜索" )
public ResponseResult < List < OpenApiPageOptionDto > > pages ( @RequestParam ( required = false ) @McpToolParam ( fieldName = "keyword" , type = McpToolParamType . STRING , description = "页面名称关键字,空返回全部" ) String keyword ) {
return ResponseResult . success ( openApiConfigService . getPageOptionList ( keyword ) ) ;
}
@ -50,7 +57,8 @@ public class OpenApiConfigController {
@@ -50,7 +57,8 @@ public class OpenApiConfigController {
* 该页面关联的表单列表 ( 配置步骤2 联动 ) 。
* /
@GetMapping ( "/forms" )
public ResponseResult < List < OpenApiFormOptionDto > > forms ( @RequestParam Long pageId ) {
@McpToolClass ( name = "openapi_config_form_options" , description = "OpenAPI 配置步骤2:指定页面对应的表单下拉" )
public ResponseResult < List < OpenApiFormOptionDto > > forms ( @RequestParam @McpToolParam ( fieldName = "pageId" , type = McpToolParamType . INTEGER , description = "页面主键Id" , required = true ) Long pageId ) {
return ResponseResult . success ( openApiConfigService . getFormOptionList ( pageId ) ) ;
}
@ -58,7 +66,8 @@ public class OpenApiConfigController {
@@ -58,7 +66,8 @@ public class OpenApiConfigController {
* 可选操作下拉 : 查询 ( query ) + operationList 各项 ( 配置步骤3 ) 。
* /
@GetMapping ( "/operations" )
public ResponseResult < List < OpenApiOperationDto > > operations ( @RequestParam Long formId ) {
@McpToolClass ( name = "openapi_config_operation_options" , description = "OpenAPI 配置步骤3:指定表单的可选操作(查询 + operationList 各项)" )
public ResponseResult < List < OpenApiOperationDto > > operations ( @RequestParam @McpToolParam ( fieldName = "formId" , type = McpToolParamType . INTEGER , description = "在线表单主键Id" , required = true ) Long formId ) {
return ResponseResult . success ( openApiConfigService . getOperationList ( formId ) ) ;
}
@ -66,42 +75,54 @@ public class OpenApiConfigController {
@@ -66,42 +75,54 @@ public class OpenApiConfigController {
* 表单可配置字段树 ( FIELD_DIRECT 字段直传专用 ) 。
* /
@GetMapping ( "/fields" )
public ResponseResult < List < OpenApiFieldDto > > fields ( @RequestParam Long formId ) {
@McpToolClass ( name = "openapi_config_field_tree" , description = "OpenAPI 配置:指定表单的可配置字段树(主表字段/关联字段属性/一对多分录)" )
public ResponseResult < List < OpenApiFieldDto > > fields ( @RequestParam @McpToolParam ( fieldName = "formId" , type = McpToolParamType . INTEGER , description = "在线表单主键Id" , required = true ) Long formId ) {
return ResponseResult . success ( openApiConfigService . getFieldTree ( formId ) ) ;
}
/ * *
* 分页查询开放接口配置 。
* 分页查询开放接口配置 ( 查询条件 : 应用Id + 状态 ) 。
* /
@PostMapping ( "/list" )
public ResponseResult < MyPageData < OpenApiConfig > > list ( @MyRequestBody OpenApiConfig openApiConfigFilter , @MyRequestBody MyPageParam pageParam ) {
@McpToolClass ( name = "openapi_config_list" , description = "分页查询 OpenAPI 开放接口配置,查询条件:openApiConfigFilter.appId(应用Id,传了仅返回该应用已授权的配置)+ openApiConfigFilter.status" )
public ResponseResult < MyPageData < OpenApiConfigVo > > list ( @MyRequestBody @McpToolParam ( fieldName = "openApiConfigFilter" , type = McpToolParamType . OBJECT , description = "查询条件(appId/status)" , schemaClass = OpenApiConfigFilterDto . class ) OpenApiConfigFilterDto openApiConfigFilter , @MyRequestBody @McpToolParam ( fieldName = "pageParam" , type = McpToolParamType . OBJECT , description = "分页参数(pageNum/pageSize)" , schemaClass = MyPageParam . class ) MyPageParam pageParam ) {
if ( pageParam ! = null ) {
PageMethod . startPage ( pageParam . getPageNum ( ) , pageParam . getPageSize ( ) ) ;
}
List < OpenApiConfig > configList = openApiConfigService . getOpenApiConfigList ( openApiConfigFilter , "create_time DESC" ) ;
return ResponseResult . success ( MyPageUtil . makeResponseData ( configList ) ) ;
List < OpenApiConfig > configList = openApiConfigService . getOpenApiConfigListByFilter ( openApiConfigFilter , "create_time DESC" ) ;
MyPageData < OpenApiConfigVo > configVoMyPageData = MyPageUtil . makeResponseData ( configList , OpenApiConfig . INSTANCE ) ;
if ( CollectionUtil . isNotEmpty ( configVoMyPageData . getDataList ( ) ) ) {
// 一次查出本页全部配置的授权关联行,按 api_id 分组回填 appIdList
List < Long > configIdList = configList . stream ( ) . map ( OpenApiConfig : : getId ) . collect ( Collectors . toList ( ) ) ;
Map < Long , List < Long > > appIdMap = openApiConfigService . getAppApiRelationListByConfigIdList ( configIdList ) . stream ( )
. collect ( Collectors . groupingBy ( OpenAppApiRelation : : getApiId , Collectors . mapping ( OpenAppApiRelation : : getAppId , Collectors . toList ( ) ) ) ) ;
configVoMyPageData . getDataList ( ) . forEach ( configVo - > configVo . setAppIdList ( appIdMap . getOrDefault ( configVo . getId ( ) , new ArrayList < > ( ) ) ) ) ;
}
return ResponseResult . success ( configVoMyPageData ) ;
}
/ * *
* 查看配置详情 。
* 查看配置详情 ( 返回 VO , 含已授权应用编码集合 ) 。
* /
@GetMapping ( "/view" )
public ResponseResult < OpenApiConfig > view ( @RequestParam Long configId ) {
@McpToolClass ( name = "openapi_config_view" , description = "查看 OpenAPI 开放接口配置详情(返回 VO,appCodes 为已授权应用编码集合)" )
public ResponseResult < OpenApiConfigVo > view ( @RequestParam @McpToolParam ( fieldName = "configId" , type = McpToolParamType . INTEGER , description = "配置主键Id" , required = true ) Long configId ) {
OpenApiConfig config = openApiConfigService . getById ( configId ) ;
if ( config = = null ) {
return ResponseResult . error ( ErrorCodeEnum . DATA_NOT_EXIST ) ;
}
return ResponseResult . success ( config ) ;
OpenApiConfigVo configVo = OpenApiConfig . INSTANCE . fromModel ( config ) ;
configVo . setAppCodes ( openApiConfigService . getAppCodesByConfigId ( configId ) ) ;
return ResponseResult . success ( configVo ) ;
}
/ * *
* 新增开放接口配置 。
* /
@PostMapping ( "/add" )
public ResponseResult < OpenApiConfig > add ( @MyRequestBody OpenApiConfig openApiConfig ) {
if ( openApiConfig = = null | | MyCommonUtil . existBlankArgument ( openApiConfig . getAppCode ( ) ,
openApiConfig . getPageId ( ) , openApiConfig . getFormId ( ) , openApiConfig . getFormCode ( ) ,
openApiConfig . getOperationCode ( ) ) ) {
@McpToolClass ( name = "openapi_config_add" , description = "新增 OpenAPI 开放接口配置(pageId/formId/formCode/operationCode 必填,自动推导 paramMode 与 requestPath;应用关联通过 assignApps 分配)" )
public ResponseResult < OpenApiConfig > add ( @MyRequestBody @McpToolParam ( fieldName = "openApiConfig" , type = McpToolParamType . OBJECT , description = "开放接口配置信息" , schemaClass = OpenApiConfig . class , required = true ) OpenApiConfig openApiConfig ) {
if ( openApiConfig = = null | | MyCommonUtil . existBlankArgument ( openApiConfig . getPageId ( ) , openApiConfig . getFormId ( ) , openApiConfig . getFormCode ( ) , openApiConfig . getOperationCode ( ) ) ) {
return ResponseResult . error ( ErrorCodeEnum . ARGUMENT_NULL_EXIST ) ;
}
return ResponseResult . success ( openApiConfigService . addNew ( openApiConfig ) ) ;
@ -111,7 +132,8 @@ public class OpenApiConfigController {
@@ -111,7 +132,8 @@ public class OpenApiConfigController {
* 更新开放接口配置 。
* /
@PostMapping ( "/update" )
public ResponseResult < Void > update ( @MyRequestBody OpenApiConfig openApiConfig ) {
@McpToolClass ( name = "openapi_config_update" , description = "更新 OpenAPI 开放接口配置(重新推导 paramMode/requestPath,需传 id)" )
public ResponseResult < Void > update ( @MyRequestBody @McpToolParam ( fieldName = "openApiConfig" , type = McpToolParamType . OBJECT , description = "开放接口配置信息(id 必填)" , schemaClass = OpenApiConfig . class , required = true ) OpenApiConfig openApiConfig ) {
if ( openApiConfig = = null | | MyCommonUtil . existBlankArgument ( openApiConfig . getId ( ) ) ) {
return ResponseResult . error ( ErrorCodeEnum . ARGUMENT_NULL_EXIST ) ;
}
@ -122,10 +144,24 @@ public class OpenApiConfigController {
@@ -122,10 +144,24 @@ public class OpenApiConfigController {
}
/ * *
* 分配应用 : 全量替换该接口配置的应用授权 ( 空集合即清空授权 ) 。
* /
@PostMapping ( "/assignApps" )
@McpToolClass ( name = "openapi_config_assign_apps" , description = "给 OpenAPI 开放接口配置分配第三方应用(全量替换授权,appIds 空即清空),返回已授权应用Id 集合" )
public ResponseResult < List < Long > > assignApps ( @MyRequestBody @McpToolParam ( fieldName = "configId" , type = McpToolParamType . INTEGER , description = "开放接口配置Id" , required = true ) Long configId ,
@MyRequestBody @McpToolParam ( fieldName = "appIds" , type = McpToolParamType . ARRAY , description = "授权应用Id 集合(全量替换,空集合即清空授权)" ) List < Long > appIds ) {
if ( MyCommonUtil . existBlankArgument ( configId ) ) {
return ResponseResult . error ( ErrorCodeEnum . ARGUMENT_NULL_EXIST ) ;
}
return ResponseResult . success ( openApiConfigService . assignApps ( configId , appIds ) ) ;
}
/ * *
* 删除开放接口配置 。
* /
@PostMapping ( "/delete" )
public ResponseResult < Void > delete ( @MyRequestBody Long configId ) {
@McpToolClass ( name = "openapi_config_delete" , description = "删除 OpenAPI 开放接口配置,需传 configId" )
public ResponseResult < Void > delete ( @MyRequestBody @McpToolParam ( fieldName = "configId" , type = McpToolParamType . INTEGER , description = "配置主键Id" , required = true ) Long configId ) {
if ( MyCommonUtil . existBlankArgument ( configId ) ) {
return ResponseResult . error ( ErrorCodeEnum . ARGUMENT_NULL_EXIST ) ;
}