From 674395000a1f59c3fa38767efa183d1769603827 Mon Sep 17 00:00:00 2001 From: lizhensheng Date: Thu, 21 Dec 2023 14:36:05 +0800 Subject: [PATCH] [feature]:(SQLManagement) Support sql analyze --- src/api/SqlManage/index.d.ts | 12 +++- src/api/SqlManage/index.ts | 20 ++++++ src/api/common.d.ts | 48 ++++++++----- src/locale/zh-CN/sqlManagement.ts | 1 + src/page/SQLManagement/SQLPanel/column.tsx | 58 ++++++++++------ src/page/SQLManagement/SQLPanel/index.tsx | 5 ++ src/page/SqlAnalyze/SqlManage/index.tsx | 77 +++++++++++++++++++++ src/page/SqlAnalyze/SqlManage/index.type.ts | 3 + src/router/config.tsx | 27 +++++++- src/types/router.type.ts | 1 + 10 files changed, 212 insertions(+), 40 deletions(-) create mode 100644 src/page/SqlAnalyze/SqlManage/index.tsx create mode 100644 src/page/SqlAnalyze/SqlManage/index.type.ts diff --git a/src/api/SqlManage/index.d.ts b/src/api/SqlManage/index.d.ts index ab6606d5..d0ef060b 100644 --- a/src/api/SqlManage/index.d.ts +++ b/src/api/SqlManage/index.d.ts @@ -20,7 +20,8 @@ import { IGetSqlManageListResp, IBatchUpdateSqlManageReq, IBaseRes, - IGetSqlManageRuleTipsResp + IGetSqlManageRuleTipsResp, + IGetSqlManageSqlAnalysisResp } from '../common.d'; export interface IGetSqlManageListParams { @@ -106,6 +107,15 @@ export interface IGetSqlManageRuleTipsParams { export interface IGetSqlManageRuleTipsReturn extends IGetSqlManageRuleTipsResp {} +export interface IGetSqlManageSqlAnalysisV1Params { + project_name: string; + + sql_manage_id: string; +} + +export interface IGetSqlManageSqlAnalysisV1Return + extends IGetSqlManageSqlAnalysisResp {} + export interface IGetSqlManageListV2Params { project_name: string; diff --git a/src/api/SqlManage/index.ts b/src/api/SqlManage/index.ts index 5ea417b2..7ba00d35 100644 --- a/src/api/SqlManage/index.ts +++ b/src/api/SqlManage/index.ts @@ -14,6 +14,8 @@ import { IExportSqlManageV1Params, IGetSqlManageRuleTipsParams, IGetSqlManageRuleTipsReturn, + IGetSqlManageSqlAnalysisV1Params, + IGetSqlManageSqlAnalysisV1Return, IGetSqlManageListV2Params, IGetSqlManageListV2Return } from './index.d'; @@ -79,6 +81,24 @@ class SqlManageService extends ServiceBase { ); } + public GetSqlManageSqlAnalysisV1( + params: IGetSqlManageSqlAnalysisV1Params, + options?: AxiosRequestConfig + ) { + const paramsData = this.cloneDeep(params); + const project_name = paramsData.project_name; + delete paramsData.project_name; + + const sql_manage_id = paramsData.sql_manage_id; + delete paramsData.sql_manage_id; + + return this.get( + `/v1/projects/${project_name}/sql_manages/${sql_manage_id}/sql_analysis`, + paramsData, + options + ); + } + public GetSqlManageListV2( params: IGetSqlManageListV2Params, options?: AxiosRequestConfig diff --git a/src/api/common.d.ts b/src/api/common.d.ts index fa7bb04c..27ec6ead 100644 --- a/src/api/common.d.ts +++ b/src/api/common.d.ts @@ -51,6 +51,12 @@ export interface IBaseRes { message?: string; } +export interface IAffectRows { + count?: number; + + err_message?: string; +} + export interface IAuditPlanCount { audit_plan_count?: number; @@ -1385,6 +1391,14 @@ export interface IGetSqlManageRuleTipsResp { message?: string; } +export interface IGetSqlManageSqlAnalysisResp { + code?: number; + + data?: ISqlAnalysis; + + message?: string; +} + export interface IGetSyncInstanceTaskListResV1 { code?: number; @@ -1997,6 +2011,10 @@ export interface IPatchUserGroupReqV1 { user_name_list?: string[]; } +export interface IPerformanceStatistics { + affect_rows?: IAffectRows; +} + export interface IPersonaliseReqV1 { title?: string; } @@ -2289,6 +2307,14 @@ export interface ISource { type?: SourceTypeEnum; } +export interface ISqlAnalysis { + performance_statistics?: IPerformanceStatistics; + + sql_explain?: ISQLExplain; + + table_metas?: ITableMetas; +} + export interface ISqlAnalysisResDataV1 { sql_explain?: ISQLExplain; @@ -2427,6 +2453,12 @@ export interface ITableMetaItemHeadResV1 { field_name?: string; } +export interface ITableMetas { + err_message?: string; + + table_meta_items?: ITableMeta[]; +} + export interface ITestAuditPlanNotifyConfigResDataV1 { is_notify_send_normal?: boolean; @@ -3093,12 +3125,6 @@ export interface IWorkflowTemplateDetailResV1 { workflow_template_name?: string; } -export interface IAffectRows { - count?: number; - - err_message?: string; -} - export interface IAuditPlanReportSQLResV2 { audit_plan_report_sql?: string; @@ -3421,10 +3447,6 @@ export interface IPartialSyncAuditPlanSQLsReqV2 { audit_plan_sql_list?: IAuditPlanSQLReqV2[]; } -export interface IPerformanceStatistics { - affect_rows?: IAffectRows; -} - export interface IRejectWorkflowReqV2 { reason?: string; } @@ -3435,12 +3457,6 @@ export interface IRuleTemplateV2 { name?: string; } -export interface ITableMetas { - err_message?: string; - - table_meta_items?: ITableMeta[]; -} - export interface ITaskAnalysisDataV2 { performance_statistics?: IPerformanceStatistics; diff --git a/src/locale/zh-CN/sqlManagement.ts b/src/locale/zh-CN/sqlManagement.ts index 8fb2c43f..e163d3ac 100644 --- a/src/locale/zh-CN/sqlManagement.ts +++ b/src/locale/zh-CN/sqlManagement.ts @@ -52,6 +52,7 @@ export default { status: '状态', comment: '备注', endpoint: '端点信息', + analyze: '分析', actions: { batchAssignment: '批量指派', diff --git a/src/page/SQLManagement/SQLPanel/column.tsx b/src/page/SQLManagement/SQLPanel/column.tsx index 3a4be702..7fed7811 100644 --- a/src/page/SQLManagement/SQLPanel/column.tsx +++ b/src/page/SQLManagement/SQLPanel/column.tsx @@ -49,6 +49,7 @@ export const SQLPanelColumns: (params: { id: number, status: BatchUpdateSqlManageReqStatusEnum ) => Promise | undefined; + handleClickAnalyze: (sqlManageId: string) => void; }) => Array< | (ColumnGroupType | ColumnType) & { dataIndex?: keyof ISqlManage | 'operator'; @@ -61,6 +62,7 @@ export const SQLPanelColumns: (params: { actionPermission, username, updateSQLStatus, + handleClickAnalyze, }) => { const columns: Array< | (ColumnGroupType | ColumnType) & { @@ -250,7 +252,6 @@ export const SQLPanelColumns: (params: { ); }, }, - { dataIndex: 'operator', title: () => t('common.operate'), @@ -258,33 +259,46 @@ export const SQLPanelColumns: (params: { render: (_, record) => { return ( - - signalAssignment(record.id ?? 0, members) - } - > - - {t('sqlManagement.table.assignMember.label')} - - + + + signalAssignment(record.id ?? 0, members) + } + > + + {t('sqlManagement.table.assignMember.label')} + + + + + + updateSQLStatus(record.id ?? 0, status)} + > + + {t('sqlManagement.table.updateStatus.triggerText')} + + + - updateSQLStatus(record.id ?? 0, status)} + { + handleClickAnalyze(record.id?.toString() ?? ''); + }} > - - {t('sqlManagement.table.updateStatus.triggerText')} - - + {t('sqlManagement.table.analyze')} + ); }, }, ]; - if (!actionPermission) { - return columns.filter((v) => v.dataIndex !== 'operator'); - } + return columns; }; diff --git a/src/page/SQLManagement/SQLPanel/index.tsx b/src/page/SQLManagement/SQLPanel/index.tsx index 0e68e5d2..9243acb9 100644 --- a/src/page/SQLManagement/SQLPanel/index.tsx +++ b/src/page/SQLManagement/SQLPanel/index.tsx @@ -306,6 +306,10 @@ const SQLPanel: React.FC = () => { ] ); + const handleClickAnalyze = (sqlManageId: string) => { + window.open(`/project/${projectName}/sqlManagement/${sqlManageId}/analyze`); + }; + const [ exportButtonDisabled, { setFalse: finishExport, setTrue: startExport }, @@ -454,6 +458,7 @@ const SQLPanel: React.FC = () => { actionPermission, username, updateSQLStatus, + handleClickAnalyze, })} pagination={{ showSizeChanger: true, diff --git a/src/page/SqlAnalyze/SqlManage/index.tsx b/src/page/SqlAnalyze/SqlManage/index.tsx new file mode 100644 index 00000000..34c68bbe --- /dev/null +++ b/src/page/SqlAnalyze/SqlManage/index.tsx @@ -0,0 +1,77 @@ +import { useBoolean } from 'ahooks'; +import { ResultStatusType } from 'antd/lib/result'; +import { useCallback, useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { + IPerformanceStatistics, + ISQLExplain, + ITableMetas, +} from '../../../api/common'; +import { ResponseCode } from '../../../data/common'; +import SqlAnalyze from '../SqlAnalyze'; +import { SQLManageAnalyzeUrlParams } from './index.type'; +import SqlManage from '../../../api/SqlManage'; +import { useCurrentProjectName } from '../../ProjectManage/ProjectDetail'; + +const SQLManageAnalyze = () => { + const urlParams = useParams(); + const { projectName } = useCurrentProjectName(); + const [errorMessage, setErrorMessage] = useState(''); + + const [sqlExplain, setSqlExplain] = useState(); + const [tableMetas, setTableMetas] = useState(); + const [performanceStatistics, setPerformancesStatistics] = + useState(); + const [ + loading, + { setTrue: startGetSqlAnalyze, setFalse: getSqlAnalyzeFinish }, + ] = useBoolean(); + const [errorType, setErrorType] = useState('error'); + + const getSqlAnalyze = useCallback(async () => { + startGetSqlAnalyze(); + try { + const res = await SqlManage.GetSqlManageSqlAnalysisV1({ + sql_manage_id: urlParams.sqlManageId ?? '', + project_name: projectName, + }); + if (res.data.code === ResponseCode.SUCCESS) { + setErrorMessage(''); + setSqlExplain(res.data.data?.sql_explain); + setTableMetas(res.data.data?.table_metas); + setPerformancesStatistics(res.data.data?.performance_statistics); + } else { + if (res.data.code === ResponseCode.NotSupportDML) { + setErrorType('info'); + } else { + setErrorType('error'); + } + setErrorMessage(res.data.message ?? ''); + } + } finally { + getSqlAnalyzeFinish(); + } + }, [ + getSqlAnalyzeFinish, + projectName, + startGetSqlAnalyze, + urlParams.sqlManageId, + ]); + + useEffect(() => { + getSqlAnalyze(); + }, [getSqlAnalyze]); + + return ( + + ); +}; + +export default SQLManageAnalyze; diff --git a/src/page/SqlAnalyze/SqlManage/index.type.ts b/src/page/SqlAnalyze/SqlManage/index.type.ts new file mode 100644 index 00000000..87c1bfd5 --- /dev/null +++ b/src/page/SqlAnalyze/SqlManage/index.type.ts @@ -0,0 +1,3 @@ +export type SQLManageAnalyzeUrlParams = { + sqlManageId: string; +}; diff --git a/src/router/config.tsx b/src/router/config.tsx index 54ceb0e7..5ab16dfd 100644 --- a/src/router/config.tsx +++ b/src/router/config.tsx @@ -274,16 +274,26 @@ const UpdateSyncTask = React.lazy( const SQLManagement = React.lazy( () => import(/* webpackChunkName: "SQLManagement" */ '../page/SQLManagement') ); + +const SQLManagementAnalyze = React.lazy( + () => + import( + /* webpackChunkName: "SQLManagementAnalyze" */ '../page/SqlAnalyze/SqlManage' + ) +); + const SQLAuditList = React.lazy( () => import(/* webpackChunkName: "SQLAuditList" */ '../page/SqlAuditRecord/List') ); + const SQLAuditDetail = React.lazy( () => import( /* webpackChunkName: "SQLAuditDetail" */ '../page/SqlAuditRecord/Detail' ) ); + const SQLAuditCreate = React.lazy( () => import( @@ -320,7 +330,22 @@ export const projectDetailRouterConfig: RouterConfigItem, path: 'sqlManagement', - element: , + hideChildrenInSliderMenu: true, + children: [ + { + index: true, + element: , + key: 'SQLManagement', + }, + /* IFTRUE_isEE */ + { + path: ':sqlManageId/analyze', + hideInSliderMenu: true, + element: , + key: 'SQLManagementAnalyze', + }, + /* FITRUE_isEE */ + ] as RouterConfigItem[], }, { label: 'menu.sqlAudit', diff --git a/src/types/router.type.ts b/src/types/router.type.ts index 1d41d42e..a2d5ed1b 100644 --- a/src/types/router.type.ts +++ b/src/types/router.type.ts @@ -60,6 +60,7 @@ export type ProjectDetailRouterItemKeyLiteral = | 'projectOverview' | 'projectRedirect' | 'SQLManagement' + | 'SQLManagementAnalyze' | 'sqlAudit' | 'sqlAuditList' | 'sqlAuditDetail'