From 57ab43e871b7bb13f16f6238e93256763dfa523d Mon Sep 17 00:00:00 2001 From: Feynman Date: Mon, 15 Dec 2025 16:17:30 +0800 Subject: [PATCH 1/2] feat(compare-schema): add support for primary key inconsistency in comparison results and localization updates --- packages/api/src/core/metadata-instances.ts | 1 + .../components/form/compare-schema/index.tsx | 24 +++++-- .../field-inference/CompareResultDialog.vue | 66 ++++++++++++++----- packages/dag/src/locale/lang/en.js | 9 ++- packages/dag/src/locale/lang/zh-CN.js | 3 + packages/dag/src/locale/lang/zh-TW.js | 3 + 6 files changed, 82 insertions(+), 24 deletions(-) diff --git a/packages/api/src/core/metadata-instances.ts b/packages/api/src/core/metadata-instances.ts index 4e57c2235..4a9282bf2 100644 --- a/packages/api/src/core/metadata-instances.ts +++ b/packages/api/src/core/metadata-instances.ts @@ -345,6 +345,7 @@ export interface CompareResultStatistics { MissingApply: 0 DifferentApply: 0 Different: 0 + PrimaryKeyInconsistency: 0 } } diff --git a/packages/dag/src/components/form/compare-schema/index.tsx b/packages/dag/src/components/form/compare-schema/index.tsx index 499e21be6..dae04eca1 100644 --- a/packages/dag/src/components/form/compare-schema/index.tsx +++ b/packages/dag/src/components/form/compare-schema/index.tsx @@ -67,7 +67,10 @@ const CompareSchema = defineComponent({ const details = [] const total = - (map.CannotWrite || 0) + (map.Missing || 0) + (map.Different || 0) + (map.CannotWrite || 0) + + (map.Missing || 0) + + (map.Different || 0) + + (map.PrimaryKeyInconsistency || 0) const resolved = (map.CannotWriteApply || 0) + (map.MissingApply || 0) + @@ -135,15 +138,26 @@ const CompareSchema = defineComponent({ ) } + if (map.PrimaryKeyInconsistency) { + details.push( + t('packages_dag_compare_result_detail_primary_key_inconsistency', { + primaryKeyInconsistency: map.PrimaryKeyInconsistency, + }), + ) + } + return { type, title: t('packages_dag_compare_result_alert', { time1, time2, - result: t('packages_dag_compare_result_with_diff', { - count: total, - details: `(${details.join(',')})`, - }), + result: + details.length > 1 + ? t('packages_dag_compare_result_with_diff', { + count: total, + details: `(${details.join(',')})`, + }) + : details[0], }), } }) diff --git a/packages/dag/src/components/form/field-inference/CompareResultDialog.vue b/packages/dag/src/components/form/field-inference/CompareResultDialog.vue index 4a7eef918..14033a733 100644 --- a/packages/dag/src/components/form/field-inference/CompareResultDialog.vue +++ b/packages/dag/src/components/form/field-inference/CompareResultDialog.vue @@ -43,6 +43,7 @@ type TableItem = { additionalNum: number missingNum: number cannotWriteNum: number + primaryKeyInconsistencyNum: number } const { t } = useI18n() @@ -60,7 +61,12 @@ const invalidApplyNum = ref(0) const pageSize = ref(10) const currentPage = ref(1) const applyCompareRules = ref(props.rules) -const filterType = ref(['Different', 'Missing', 'CannotWrite']) +const filterType = ref([ + 'PrimaryKeyInconsistency', + 'Different', + 'Missing', + 'CannotWrite', +]) const typeMap = { Different: { @@ -70,6 +76,11 @@ const typeMap = { btnText: t('public_button_revise'), numKey: 'differentNum', }, + PrimaryKeyInconsistency: { + text: t('packages_dag_compare_primary_key_inconsistency'), + type: 'warning', + numKey: 'primaryKeyInconsistencyNum', + }, Missing: { text: t('packages_dag_compare_missing'), type: 'danger', @@ -87,6 +98,10 @@ const typeMap = { } const filterOptions = ref([ + { + label: t('packages_dag_compare_primary_key_inconsistency'), + value: 'PrimaryKeyInconsistency', + }, { label: t('packages_dag_compare_different'), value: 'Different', @@ -110,7 +125,7 @@ const filterOptions = ref([ ]) const ruleOptions = filterOptions.value.filter((item) => { - return item.value !== 'Additional' + return !['Additional', 'PrimaryKeyInconsistency'].includes(item.value) }) const totalMap = ref>({}) @@ -179,25 +194,29 @@ const { Additional: 0, Missing: 0, CannotWrite: 0, + PrimaryKeyInconsistency: 0, } const fields: TableItem['fields'] = [] item.differenceFieldList.forEach((field) => { - if (!field.applyType) totalMap[field.type as keyof typeof totalMap]++ + if (!field.applyType) { + totalMap[field.type as keyof typeof totalMap]++ + if (field.type !== 'PrimaryKeyInconsistency' && field.isPrimaryKey) { + // 只要是主键,其他差异也需要算进来 + totalMap.PrimaryKeyInconsistency++ + } + } let fieldType - let isPrimaryKey let isNullable let icon if (field.sourceField) { fieldType = field.sourceField.data_type - isPrimaryKey = field.sourceField.primary_key_position > 0 isNullable = field.sourceField.is_nullable icon = getFieldIcon(field.sourceField.tapType) } else { fieldType = field.targetField.data_type - isPrimaryKey = field.targetField.primary_key_position > 0 isNullable = field.targetField.is_nullable icon = getFieldIcon(field.targetField.tapType) } @@ -212,9 +231,11 @@ const { field.sourceField?.data_type, field.targetField?.data_type, ), + sourcePrimaryKey: field.sourceField?.primaryKey, + targetPrimaryKey: field.targetField?.primaryKey, fieldType, icon, - isPrimaryKey, + isPrimaryKey: field.isPrimaryKey, isNullable, }) }) @@ -227,6 +248,7 @@ const { additionalNum: totalMap.Additional, missingNum: totalMap.Missing, cannotWriteNum: totalMap.CannotWrite, + primaryKeyInconsistencyNum: totalMap.PrimaryKeyInconsistency, } }) @@ -294,10 +316,6 @@ const handleApplyTable = () => { ]) } -const handleApplyAll = () => { - saveApply(true) -} - const handleUndo = (item: Partial) => { deleteApply(false, [ { @@ -316,10 +334,6 @@ const handleUndoTable = () => { ]) } -const handleUndoAll = () => { - deleteApply(true) -} - let unwatch: () => void const handleCompareTargetModel = async () => { @@ -468,6 +482,8 @@ onBeforeUnmount(() => { width="60%" class="p-0 overflow-hidden compare-result-dialog" :show-close="false" + :close-on-click-modal="false" + :close-on-press-escape="false" @open="onOpen" @close="onClose" > @@ -805,6 +821,8 @@ onBeforeUnmount(() => { { { (field.type === 'Missing' || field.type === 'CannotWrite'), }" + > + key {{ field.fieldName }}
@@ -971,7 +997,15 @@ onBeforeUnmount(() => { >
- {{ field.fieldName }} + + key {{ field.fieldName }} Date: Mon, 15 Dec 2025 17:27:42 +0800 Subject: [PATCH 2/2] refactor(CompareResultDialog.vue): streamline type mapping and filter options for improved clarity and maintainability --- .../field-inference/CompareResultDialog.vue | 124 ++++++++---------- 1 file changed, 53 insertions(+), 71 deletions(-) diff --git a/packages/dag/src/components/form/field-inference/CompareResultDialog.vue b/packages/dag/src/components/form/field-inference/CompareResultDialog.vue index 14033a733..681757a90 100644 --- a/packages/dag/src/components/form/field-inference/CompareResultDialog.vue +++ b/packages/dag/src/components/form/field-inference/CompareResultDialog.vue @@ -68,68 +68,66 @@ const filterType = ref([ 'CannotWrite', ]) -const typeMap = { - Different: { - text: t('packages_dag_compare_different'), - type: 'warning', - doneText: 'packages_dag_compare_done_modify', - btnText: t('public_button_revise'), - numKey: 'differentNum', - }, - PrimaryKeyInconsistency: { - text: t('packages_dag_compare_primary_key_inconsistency'), - type: 'warning', - numKey: 'primaryKeyInconsistencyNum', - }, - Missing: { - text: t('packages_dag_compare_missing'), - type: 'danger', - doneText: 'packages_dag_compare_done_delete', - btnText: t('public_button_delete'), - numKey: 'missingNum', - }, - CannotWrite: { - text: t('packages_dag_compare_cannot_write'), - type: 'danger', - doneText: 'packages_dag_compare_done_delete', - btnText: t('public_button_delete'), - numKey: 'cannotWriteNum', - }, -} - const filterOptions = ref([ { label: t('packages_dag_compare_primary_key_inconsistency'), value: 'PrimaryKeyInconsistency', + type: 'warning', + numKey: 'primaryKeyInconsistencyNum', }, { label: t('packages_dag_compare_different'), value: 'Different', + type: 'warning', + numKey: 'differentNum', + doneText: 'packages_dag_compare_done_modify', + actionText: t('public_button_update'), }, { label: t('packages_dag_compare_missing'), value: 'Missing', + type: 'danger', + numKey: 'missingNum', + doneText: 'packages_dag_compare_done_delete', + actionText: t('public_button_delete'), }, { label: t('packages_dag_compare_cannot_write'), value: 'CannotWrite', + type: 'danger', + numKey: 'cannotWriteNum', + doneText: 'packages_dag_compare_done_delete', + actionText: t('public_button_delete'), }, { label: t('packages_dag_compare_missing_source'), value: 'Additional', + type: 'info', }, { label: t('packages_dag_compare_precision'), value: 'Precision', + type: 'info', + doneText: 'packages_dag_compare_done_modify', + actionText: t('public_button_update'), }, ]) const ruleOptions = filterOptions.value.filter((item) => { - return !['Additional', 'PrimaryKeyInconsistency'].includes(item.value) + return !!item.actionText }) const totalMap = ref>({}) +const typeMap = filterOptions.value.reduce((acc: Record, item) => { + acc[item.value] = item + return acc +}, {}) + +const importantOptions = filterOptions.value.filter((item) => { + return ['warning', 'danger'].includes(item.type) +}) + const isLoading = computed(() => { return compareResultLoading.value || compareStatus.value === 'running' }) @@ -577,7 +575,7 @@ onBeforeUnmount(() => { @@ -619,19 +617,11 @@ onBeforeUnmount(() => { :label="item.label" :value="item.value" > - + {{ item.label }} - {{ - item.value === 'Different' || item.value === 'Precision' - ? $t('public_button_update') - : $t('public_button_delete') - }} + {{ item.actionText }} @@ -732,15 +722,18 @@ onBeforeUnmount(() => { >
-