Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 规则审计,预期数据与风险发现规则联调 --story=120928207 #530

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/frontend/src/domain/model/strategy/common-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class CommonData {
link_table_join_type: Array<ItemType>;
link_table_table_type: Array<ItemType>;
rule_audit_aggregate_type: Array<ItemType>;
rule_audit_condition_operator: Array<ItemType>;

constructor(payload = {} as CommonData) {
this.offset_unit = payload.offset_unit || [];
Expand All @@ -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 || [];
}
}

15 changes: 8 additions & 7 deletions src/frontend/src/domain/model/strategy/database-table-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
}
}
10 changes: 8 additions & 2 deletions src/frontend/src/domain/model/strategy/strategy-field-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type EventItem = {
description: string
display_name: string;
is_priority: boolean;
field_mapping: string;
map_config?: {
target_value: string | undefined,
source_field: string | undefined,
};
prefix: string;
example?: string
}
Expand All @@ -40,7 +43,10 @@ export default class StrategyFieldEvent {
field_name: item.field_name,
display_name: item.display_name,
is_priority: item.is_priority || false,
field_mapping: item.field_mapping,
map_config: {
target_value: item.map_config?.target_value,
source_field: item.map_config?.source_field,
},
description: item.description,
example: item.example,
prefix,
Expand Down
24 changes: 24 additions & 0 deletions src/frontend/src/domain/model/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
to the current version of the project delivered to anyone in the future.
*/

import DatabaseTableFieldModel from '@model/strategy/database-table-field';

import StrategyFieldEvent from '../strategy/strategy-field-event';

export default class Strategy {
Expand All @@ -34,6 +36,12 @@ export default class Strategy {
data_source?: {
source_type: string;
result_table_id?: string;
rt_id: string;
link_table: {
uid: string,
version: number,
},
system_ids: Array<string>,
filter_config: Array<{
connector: string;
key: string;
Expand All @@ -54,6 +62,22 @@ export default class Strategy {
}>
}
};
select: Array<DatabaseTableFieldModel>,
where: {
operator: 'and' | 'or' ;
conditions: Array<{
operator: 'and' | 'or';
conditions: Array<{
field: DatabaseTableFieldModel | '';
filter: string;
filters: string[];
}>
}>;
},
schedule_config: {
count_freq: string,
schedule_period: string,
},
[key: string]: any
};
status: string;
Expand Down
7 changes: 0 additions & 7 deletions src/frontend/src/domain/service/strategy-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -148,12 +147,6 @@ export default {
/**
* @desc 获取表字段对应的规则和枚举值列表
*/
fetchFiledRules(params: {
field: DatabaseTableFieldModel;
}) {
return StrategySource.gethFiledRules(params)
.then(({ data }) => data);
},
/**
* @desc 获取表格下的rt字段
*/
Expand Down
30 changes: 0 additions & 30 deletions src/frontend/src/domain/source/strategy-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -158,35 +157,6 @@ class Strategy extends ModuleBase {
params,
});
}
// 获取表字段对应的规则和枚举值列表
gethFiledRules(params: {
field: DatabaseTableFieldModel;
}) {
// return Request.get<{
// rulesList: Array<Record<string, any>>,
// enumList: Array<Record<string, any>>
// }>(`${this.path}/strategy_database_table_fields/`, {
// params,
// });
console.log(params);
return Promise.resolve<{
data: {
rulesList: Array<Record<string, any>>,
enumList: Array<Record<string, any>>
}
}>({
data: {
rulesList: [{
value: '=',
name: '=',
}, {
value: '!',
name: '!',
}],
enumList: [],
},
});
}
// 获取表格的字段列表
getTableRtFields(params: {
table_id: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
const localAggregateList = ref<Array<Record<string, any>>>([]);
const formData = ref<DatabaseTableFieldModel>(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;
// 重置可选
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@

import AddFields from './add-fields.vue';

interface Expose {
resetFormData: () => void,
setConfigs: (config: Array<DatabaseTableFieldModel>) => void;
}
interface Emits {
(e: 'updateExpectedResult', value: Array<DatabaseTableFieldModel>): void;
}
Expand Down Expand Up @@ -104,6 +108,15 @@
expectedResultList.value = [];
updateExpectedResult();
};

defineExpose<Expose>({
resetFormData: () => {
expectedResultList.value = [];
},
setConfigs(configs: Array<DatabaseTableFieldModel>) {
expectedResultList.value = configs;
},
});
</script>
<style scoped lang="postcss">
.panel-edit {
Expand Down
Loading
Loading