From dac0f3e1b2ffa105cd9e909e884ef0eef1de2a0c Mon Sep 17 00:00:00 2001 From: lizhensheng Date: Thu, 9 Nov 2023 15:42:00 +0800 Subject: [PATCH] [feature]: (Order) Support uploading sql zip files --- src/api/SqlManage/index.d.ts | 14 +++- src/api/SqlManage/index.enum.ts | 28 +++++++ src/api/task/index.d.ts | 4 + src/api/task/index.ts | 8 ++ src/locale/zh-CN/order.ts | 4 +- .../__snapshots__/index.test.tsx.snap | 21 ++++- .../SqlInfoForm/__test__/index.test.tsx | 4 +- .../Create/__snapshots__/index.test.tsx.snap | 84 ++++++++++++++++++- .../__snapshots__/index.test.tsx.snap | 19 +++++ .../SqlStatementFormTabs/SqlStatementForm.tsx | 27 +++++- .../__test__/SqlStatementForm.test.tsx | 8 +- .../SqlStatementForm.test.tsx.snap | 21 ++++- .../SqlStatementFormTabs.test.tsx.snap | 42 +++++++++- src/page/Order/SqlStatementFormTabs/index.ts | 2 + src/page/Order/hooks/useAuditOrder.tsx | 2 + 15 files changed, 271 insertions(+), 17 deletions(-) diff --git a/src/api/SqlManage/index.d.ts b/src/api/SqlManage/index.d.ts index ebd5390d..5b3408bd 100644 --- a/src/api/SqlManage/index.d.ts +++ b/src/api/SqlManage/index.d.ts @@ -2,9 +2,13 @@ import { GetSqlManageListFilterSourceEnum, GetSqlManageListFilterAuditLevelEnum, GetSqlManageListFilterStatusEnum, + GetSqlManageListSortFieldEnum, + GetSqlManageListSortOrderEnum, exportSqlManageV1FilterSourceEnum, exportSqlManageV1FilterAuditLevelEnum, - exportSqlManageV1FilterStatusEnum + exportSqlManageV1FilterStatusEnum, + exportSqlManageV1SortFieldEnum, + exportSqlManageV1SortOrderEnum } from './index.enum'; import { @@ -37,6 +41,10 @@ export interface IGetSqlManageListParams { filter_db_type?: string; + sort_field?: GetSqlManageListSortFieldEnum; + + sort_order?: GetSqlManageListSortOrderEnum; + page_index: number; page_size: number; @@ -72,6 +80,10 @@ export interface IExportSqlManageV1Params { filter_db_type?: string; filter_rule_name?: string; + + sort_field?: exportSqlManageV1SortFieldEnum; + + sort_order?: exportSqlManageV1SortOrderEnum; } export interface IGetSqlManageRuleTipsParams { diff --git a/src/api/SqlManage/index.enum.ts b/src/api/SqlManage/index.enum.ts index cc9a45c7..e13ea208 100644 --- a/src/api/SqlManage/index.enum.ts +++ b/src/api/SqlManage/index.enum.ts @@ -26,6 +26,20 @@ export enum GetSqlManageListFilterStatusEnum { 'manual_audited' = 'manual_audited' } +export enum GetSqlManageListSortFieldEnum { + 'first_appear_timestamp' = 'first_appear_timestamp', + + 'last_receive_timestamp' = 'last_receive_timestamp', + + 'fp_count' = 'fp_count' +} + +export enum GetSqlManageListSortOrderEnum { + 'asc' = 'asc', + + 'desc' = 'desc' +} + export enum exportSqlManageV1FilterSourceEnum { 'audit_plan' = 'audit_plan', @@ -51,3 +65,17 @@ export enum exportSqlManageV1FilterStatusEnum { 'manual_audited' = 'manual_audited' } + +export enum exportSqlManageV1SortFieldEnum { + 'first_appear_timestamp' = 'first_appear_timestamp', + + 'last_receive_timestamp' = 'last_receive_timestamp', + + 'fp_count' = 'fp_count' +} + +export enum exportSqlManageV1SortOrderEnum { + 'asc' = 'asc', + + 'desc' = 'desc' +} diff --git a/src/api/task/index.d.ts b/src/api/task/index.d.ts index 71dbbc99..45009920 100644 --- a/src/api/task/index.d.ts +++ b/src/api/task/index.d.ts @@ -40,6 +40,8 @@ export interface ICreateAndAuditTaskV1Params { input_sql_file?: any; input_mybatis_xml_file?: any; + + input_zip_file?: any; } export interface ICreateAndAuditTaskV1Return extends IGetAuditTaskResV1 {} @@ -52,6 +54,8 @@ export interface IAuditTaskGroupIdV1Params { input_sql_file?: any; input_mybatis_xml_file?: any; + + input_zip_file?: any; } export interface IAuditTaskGroupIdV1Return extends IAuditTaskGroupResV1 {} diff --git a/src/api/task/index.ts b/src/api/task/index.ts index 055f94ad..4f2646e3 100644 --- a/src/api/task/index.ts +++ b/src/api/task/index.ts @@ -84,6 +84,10 @@ class TaskService extends ServiceBase { ); } + if (params.input_zip_file != undefined) { + paramsData.append('input_zip_file', params.input_zip_file as any); + } + const project_name = params.project_name; return this.post( @@ -126,6 +130,10 @@ class TaskService extends ServiceBase { ); } + if (params.input_zip_file != undefined) { + paramsData.append('input_zip_file', params.input_zip_file as any); + } + return this.post( '/v1/task_groups/audit', paramsData, diff --git a/src/locale/zh-CN/order.ts b/src/locale/zh-CN/order.ts index 64a183d4..7c900259 100644 --- a/src/locale/zh-CN/order.ts +++ b/src/locale/zh-CN/order.ts @@ -154,13 +154,15 @@ export default { sql: 'SQL语句', sqlFile: 'SQL文件', mybatisFile: 'Mybatis的XML文件', + zipFile: 'ZIP文件', addInstance: '添加数据源', uploadType: '选择审核SQL语句上传方式', manualInput: '输入SQL语句', uploadFile: '上传SQL文件', - updateMybatisFile: '上传Mybatis的XML文件', + uploadMybatisFile: '上传Mybatis的XML文件', + uploadZipFile: '上传ZIP文件', audit: '审核', format: 'SQL美化', diff --git a/src/page/Order/Create/SqlInfoForm/__test__/__snapshots__/index.test.tsx.snap b/src/page/Order/Create/SqlInfoForm/__test__/__snapshots__/index.test.tsx.snap index 23ad9b25..9823cfbb 100644 --- a/src/page/Order/Create/SqlInfoForm/__test__/__snapshots__/index.test.tsx.snap +++ b/src/page/Order/Create/SqlInfoForm/__test__/__snapshots__/index.test.tsx.snap @@ -480,7 +480,26 @@ exports[`order/create/sqlInfoForm should match snapshot 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + diff --git a/src/page/Order/Create/SqlInfoForm/__test__/index.test.tsx b/src/page/Order/Create/SqlInfoForm/__test__/index.test.tsx index 9cf77add..f84604e8 100644 --- a/src/page/Order/Create/SqlInfoForm/__test__/index.test.tsx +++ b/src/page/Order/Create/SqlInfoForm/__test__/index.test.tsx @@ -335,7 +335,7 @@ describe('order/create/sqlInfoForm', () => { fireEvent.click(instance); await act(async () => jest.advanceTimersByTime(3000)); - fireEvent.click(screen.getByText('order.sqlInfo.updateMybatisFile')); + fireEvent.click(screen.getByText('order.sqlInfo.uploadMybatisFile')); const mybatisFile = new File( [ @@ -503,7 +503,7 @@ describe('order/create/sqlInfoForm', () => { fireEvent.click(screen.getByText('order.sqlInfo.format')); expect(mockSqlFormatter).toBeCalledTimes(2); - fireEvent.click(screen.getByText('order.sqlInfo.updateMybatisFile')); + fireEvent.click(screen.getByText('order.sqlInfo.uploadMybatisFile')); fireEvent.click(screen.getByText('order.sqlInfo.format')); expect(mockSqlFormatter).toBeCalledTimes(2); diff --git a/src/page/Order/Create/__snapshots__/index.test.tsx.snap b/src/page/Order/Create/__snapshots__/index.test.tsx.snap index b076281a..132c363b 100644 --- a/src/page/Order/Create/__snapshots__/index.test.tsx.snap +++ b/src/page/Order/Create/__snapshots__/index.test.tsx.snap @@ -679,7 +679,26 @@ exports[`Order/Create should audit sql when user click audit button 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + @@ -3445,7 +3464,26 @@ exports[`Order/Create should audit sql when user click audit button 2`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + @@ -5123,7 +5161,26 @@ exports[`Order/Create should render page header 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + @@ -5994,7 +6051,26 @@ exports[`Order/Create should render result modal when created order 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + diff --git a/src/page/Order/Detail/Modal/ModifySqlModal/__snapshots__/index.test.tsx.snap b/src/page/Order/Detail/Modal/ModifySqlModal/__snapshots__/index.test.tsx.snap index ef4795a7..3e874d07 100644 --- a/src/page/Order/Detail/Modal/ModifySqlModal/__snapshots__/index.test.tsx.snap +++ b/src/page/Order/Detail/Modal/ModifySqlModal/__snapshots__/index.test.tsx.snap @@ -156,6 +156,25 @@ exports[`Order/Detail/Modal/ModifySqlModal should send sql file when user upload order.sqlInfo.uploadFile + diff --git a/src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx b/src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx index e617d28e..e6306322 100644 --- a/src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx +++ b/src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx @@ -84,9 +84,12 @@ const SqlStatementForm: React.FC = ({ - {t('order.sqlInfo.updateMybatisFile')} + {t('order.sqlInfo.uploadMybatisFile')} + + {t('order.sqlInfo.uploadZipFile')} + @@ -158,6 +161,28 @@ const SqlStatementForm: React.FC = ({ + + + + false} + onRemove={removeFile.bind(null, 'zipFile')} + > + + + + ); }; diff --git a/src/page/Order/SqlStatementFormTabs/__test__/SqlStatementForm.test.tsx b/src/page/Order/SqlStatementFormTabs/__test__/SqlStatementForm.test.tsx index f2fb722b..0e791329 100644 --- a/src/page/Order/SqlStatementFormTabs/__test__/SqlStatementForm.test.tsx +++ b/src/page/Order/SqlStatementFormTabs/__test__/SqlStatementForm.test.tsx @@ -97,7 +97,7 @@ describe('test Order/SqlStatementForm', () => { screen.queryByLabelText('order.sqlInfo.mybatisFile') ).not.toBeInTheDocument(); - fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile')); + fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile')); expect( screen.queryByLabelText('order.sqlInfo.sql') ).not.toBeInTheDocument(); @@ -179,7 +179,7 @@ describe('test Order/SqlStatementForm', () => { ); expect( - screen.queryByLabelText('order.sqlInfo.updateMybatisFile') + screen.queryByLabelText('order.sqlInfo.uploadMybatisFile') ).not.toBeInTheDocument(); }); @@ -224,7 +224,7 @@ describe('test Order/SqlStatementForm', () => { '0_sqlFile' ); - fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile')); + fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile')); expect(screen.getByLabelText('order.sqlInfo.mybatisFile')).toHaveAttribute( 'id', '0_mybatisFile' @@ -258,7 +258,7 @@ describe('test Order/SqlStatementForm', () => { '1_sqlFile' ); - fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile')); + fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile')); expect(screen.getByLabelText('order.sqlInfo.mybatisFile')).toHaveAttribute( 'id', '1_mybatisFile' diff --git a/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementForm.test.tsx.snap b/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementForm.test.tsx.snap index 54ddd680..32a1cba1 100644 --- a/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementForm.test.tsx.snap +++ b/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementForm.test.tsx.snap @@ -90,7 +90,26 @@ exports[`test Order/SqlStatementForm should match snapshot 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + diff --git a/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementFormTabs.test.tsx.snap b/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementFormTabs.test.tsx.snap index 3b849278..084054fa 100644 --- a/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementFormTabs.test.tsx.snap +++ b/src/page/Order/SqlStatementFormTabs/__test__/__snapshots__/SqlStatementFormTabs.test.tsx.snap @@ -204,7 +204,26 @@ exports[`test Order/SqlStatementFormTabs should match snapshot 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + @@ -348,7 +367,26 @@ exports[`test Order/SqlStatementFormTabs should match snapshot 1`] = ` /> - order.sqlInfo.updateMybatisFile + order.sqlInfo.uploadMybatisFile + + + diff --git a/src/page/Order/SqlStatementFormTabs/index.ts b/src/page/Order/SqlStatementFormTabs/index.ts index d7844a62..b53ca5e0 100644 --- a/src/page/Order/SqlStatementFormTabs/index.ts +++ b/src/page/Order/SqlStatementFormTabs/index.ts @@ -33,6 +33,7 @@ export enum SQLInputType { manualInput, uploadFile, uploadMybatisFile, + zipFile, } export type SqlStatementFields = { @@ -40,4 +41,5 @@ export type SqlStatementFields = { sql: string; sqlFile: File[]; mybatisFile: File[]; + zipFile: File[]; }; diff --git a/src/page/Order/hooks/useAuditOrder.tsx b/src/page/Order/hooks/useAuditOrder.tsx index 30d5a5c6..55de7415 100644 --- a/src/page/Order/hooks/useAuditOrder.tsx +++ b/src/page/Order/hooks/useAuditOrder.tsx @@ -100,6 +100,7 @@ const useAuditOrder = () => { sql: sqlStatementInfo.sql, input_sql_file: sqlStatementInfo.sqlFile?.[0], input_mybatis_xml_file: sqlStatementInfo.mybatisFile?.[0], + input_zip_file: sqlStatementInfo.zipFile?.[0], }; const res = await task.auditTaskGroupIdV1(auditTaskPrams); if (res && res.data.code === ResponseCode.SUCCESS) { @@ -142,6 +143,7 @@ const useAuditOrder = () => { sql: sqlStatementInfo.sql, input_sql_file: sqlStatementInfo.sqlFile?.[0], input_mybatis_xml_file: sqlStatementInfo.mybatisFile?.[0], + input_zip_file: sqlStatementInfo.zipFile?.[0], }; const res = await task.createAndAuditTaskV1(params);