From 7869aa380c56b4bfb2d5377815af8590c4a2604a Mon Sep 17 00:00:00 2001 From: nanasikeai Date: Tue, 14 Jan 2025 15:13:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=A7=84=E5=88=99=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=EF=BC=8C=E9=A2=84=E6=9C=9F=E6=95=B0=E6=8D=AE=E4=B8=8E?= =?UTF-8?q?=E9=A3=8E=E9=99=A9=E5=8F=91=E7=8E=B0=E8=A7=84=E5=88=99=E8=81=94?= =?UTF-8?q?=E8=B0=83=20--story=3D120928207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/domain/model/strategy/common-data.ts | 2 + .../model/strategy/database-table-field.ts | 15 +- .../src/domain/service/strategy-manage.ts | 7 - .../src/domain/source/strategy-manage.ts | 30 --- .../expected-results/add-fields.vue | 13 +- .../components/expected-results/index.vue | 9 + .../rules/components/field-item.vue | 192 +++++++++++++----- .../customize/components/rules/index.vue | 66 +++++- .../components/scheme-input/event-log.vue | 10 +- .../scheme-input/link-table/detail.vue | 2 +- .../step1/components/customize/index.vue | 118 +++++++---- .../components/step1/index.vue | 18 +- 12 files changed, 323 insertions(+), 159 deletions(-) diff --git a/src/frontend/src/domain/model/strategy/common-data.ts b/src/frontend/src/domain/model/strategy/common-data.ts index 78911c15..5ed59de7 100644 --- a/src/frontend/src/domain/model/strategy/common-data.ts +++ b/src/frontend/src/domain/model/strategy/common-data.ts @@ -36,6 +36,7 @@ export default class CommonData { link_table_join_type: Array; link_table_table_type: Array; rule_audit_aggregate_type: Array; + rule_audit_condition_operator: Array; constructor(payload = {} as CommonData) { this.offset_unit = payload.offset_unit || []; @@ -52,6 +53,7 @@ export default class CommonData { this.link_table_join_type = payload.link_table_join_type || []; this.link_table_table_type = payload.link_table_table_type || []; this.rule_audit_aggregate_type = payload.rule_audit_aggregate_type || []; + this.rule_audit_condition_operator = payload.rule_audit_condition_operator || []; } } diff --git a/src/frontend/src/domain/model/strategy/database-table-field.ts b/src/frontend/src/domain/model/strategy/database-table-field.ts index 7e728bba..0a827a96 100644 --- a/src/frontend/src/domain/model/strategy/database-table-field.ts +++ b/src/frontend/src/domain/model/strategy/database-table-field.ts @@ -18,15 +18,16 @@ export default class DatabaseTableField { table: string; // RT ID raw_name: string; // bkbase 字段名 display_name: string; // 展示名称 -- 用于 AS 别名,查询中唯一 - type: string; // 字段类型 -- 来自 bkbase - aggregate?: string; // 聚合函数 -- 聚合算法 + field_type: string; // 字段类型 -- 来自 bkbase + aggregate: string | null; // 聚合函数 -- 聚合算法 remark: string; // 备注 constructor(payload = {} as DatabaseTableField) { - this.table = payload.table; - this.raw_name = payload.raw_name; - this.display_name = payload.display_name; - this.type = payload.type; - this.remark = payload.remark; + this.table = payload.table || ''; + this.raw_name = payload.raw_name || ''; + this.display_name = payload.display_name || ''; + this.field_type = payload.field_type || ''; + this.aggregate = payload.aggregate || null; + this.remark = payload.remark || ''; } } diff --git a/src/frontend/src/domain/service/strategy-manage.ts b/src/frontend/src/domain/service/strategy-manage.ts index 56290fd5..ddd19e5a 100644 --- a/src/frontend/src/domain/service/strategy-manage.ts +++ b/src/frontend/src/domain/service/strategy-manage.ts @@ -15,7 +15,6 @@ to the current version of the project delivered to anyone in the future. */ import SearchModel from '@model/es-query/search'; -import DatabaseTableFieldModel from '@model/strategy/database-table-field'; import StrategyModel from '@model/strategy/strategy'; import StrategyFieldEvent from '@model/strategy/strategy-field-event'; @@ -148,12 +147,6 @@ export default { /** * @desc 获取表字段对应的规则和枚举值列表 */ - fetchFiledRules(params: { - field: DatabaseTableFieldModel; - }) { - return StrategySource.gethFiledRules(params) - .then(({ data }) => data); - }, /** * @desc 获取表格下的rt字段 */ diff --git a/src/frontend/src/domain/source/strategy-manage.ts b/src/frontend/src/domain/source/strategy-manage.ts index eb87cbb8..e2e34010 100644 --- a/src/frontend/src/domain/source/strategy-manage.ts +++ b/src/frontend/src/domain/source/strategy-manage.ts @@ -18,7 +18,6 @@ import type SearchModel from '@model/es-query/search'; import type AiopsDetailModel from '@model/strategy/aiops-detail'; import type AiopsPlanModel from '@model/strategy/aiops-plan'; import type CommonDataModel from '@model/strategy/common-data'; -import type DatabaseTableFieldModel from '@model/strategy/database-table-field'; import type StrategyModel from '@model/strategy/strategy'; import type StrategyFieldEvent from '@model/strategy/strategy-field-event'; // import type StrategyFieldModel from '@model/strategy/strategy-field'; @@ -158,35 +157,6 @@ class Strategy extends ModuleBase { params, }); } - // 获取表字段对应的规则和枚举值列表 - gethFiledRules(params: { - field: DatabaseTableFieldModel; - }) { - // return Request.get<{ - // rulesList: Array>, - // enumList: Array> - // }>(`${this.path}/strategy_database_table_fields/`, { - // params, - // }); - console.log(params); - return Promise.resolve<{ - data: { - rulesList: Array>, - enumList: Array> - } - }>({ - data: { - rulesList: [{ - value: '=', - name: '=', - }, { - value: '!', - name: '!', - }], - enumList: [], - }, - }); - } // 获取表格的字段列表 getTableRtFields(params: { table_id: string diff --git a/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/add-fields.vue b/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/add-fields.vue index dd6254b7..99982d63 100644 --- a/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/add-fields.vue +++ b/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/add-fields.vue @@ -105,6 +105,14 @@ const localAggregateList = ref>>([]); const formData = ref(new DatabaseTableFieldModel()); + const fieldAggregateMap = { + string: ['COUNT', 'DISCOUNT'], + double: ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'], + int: ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'], + long: ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'], + timestamp: ['COUNT', 'MIX', 'MAX'], + }; + const handleShowPop = () => { isShow.value = true; // 重置可选 @@ -116,9 +124,12 @@ const handleSelectField = (index: number, field: DatabaseTableFieldModel) => { selectIndex.value = index; + // 每种类型字段拥有不同的聚合算法 + // eslint-disable-next-line max-len + localAggregateList.value = props.aggregateList.filter(item => fieldAggregateMap[field.field_type as keyof typeof fieldAggregateMap].includes(item.value) || item.label === '不聚和'); // 同一字段不能重复添加同一聚合算法 // eslint-disable-next-line max-len - const hasAggregate = props.expectedResultList.filter(item => (item.table + item.raw_name) === (field.table + item.raw_name)); + const hasAggregate = props.expectedResultList.filter(item => (item.table + item.raw_name) === (field.table + field.raw_name)); if (hasAggregate.length) { localAggregateList.value = localAggregateList.value.map((item) => { if (hasAggregate.some(element => element.aggregate === item.value)) { diff --git a/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/index.vue b/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/index.vue index 464a32aa..66fc19be 100644 --- a/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/index.vue +++ b/src/frontend/src/views/strategy-manage/strategy-create/components/step1/components/customize/components/expected-results/index.vue @@ -67,6 +67,9 @@ import AddFields from './add-fields.vue'; + interface Expose { + resetFormData: () => void, + } interface Emits { (e: 'updateExpectedResult', value: Array): void; } @@ -104,6 +107,12 @@ expectedResultList.value = []; updateExpectedResult(); }; + + defineExpose({ + resetFormData: () => { + expectedResultList.value = []; + }, + });