增加分表查询
This commit is contained in:
@@ -52,24 +52,24 @@ function toggleShardingMode() {
|
||||
// 启用分表模式
|
||||
shardingConfig.style.display = 'block';
|
||||
executeButton.textContent = '执行分表查询比对';
|
||||
keyInputHint.textContent = '分表模式:Key值应包含时间戳用于计算分表索引';
|
||||
keysField.placeholder = ' (推荐使用包含时间戳的字段)';
|
||||
keyInputHint.textContent = '分表模式:Key值应包含时间戳用于计算分表索引,支持单主键和复合主键(逗号分隔)';
|
||||
keysField.placeholder = '单主键:wmid 或 复合主键:docid,id (推荐使用包含时间戳的字段)';
|
||||
keysField.value = '';
|
||||
|
||||
// 更新查询Key输入框的占位符
|
||||
const queryValues = document.getElementById('query_values');
|
||||
queryValues.placeholder = '请输入查询的Key值,一行一个\n分表查询示例(包含时间戳):\nwmid_1609459200\nwmid_1610064000\nwmid_1610668800';
|
||||
queryValues.placeholder = '请输入查询的Key值,一行一个\n单主键示例(包含时间戳):\nwmid_1609459200\nwmid_1610064000\nwmid_1610668800\n\n复合主键示例(逗号分隔):\ndocid_1609459200,id1\ndocid_1610064000,id2\ndocid_1610668800,id3';
|
||||
} else {
|
||||
// 禁用分表模式
|
||||
shardingConfig.style.display = 'none';
|
||||
executeButton.textContent = '执行查询比对';
|
||||
keyInputHint.textContent = '单表模式:输入普通Key值';
|
||||
keysField.placeholder = '';
|
||||
keyInputHint.textContent = '单表模式:支持单主键和复合主键查询,复合主键用逗号分隔';
|
||||
keysField.placeholder = '单主键:docid 或 复合主键:docid,id';
|
||||
keysField.value = '';
|
||||
|
||||
// 更新查询Key输入框的占位符
|
||||
const queryValues = document.getElementById('query_values');
|
||||
queryValues.placeholder = '请输入查询的Key值,一行一个\n单表查询示例:\nkey1\nkey2\nkey3';
|
||||
queryValues.placeholder = '请输入查询的Key值,一行一个\n单主键示例:\nkey1\nkey2\nkey3\n\n复合主键示例(逗号分隔):\ndocid1,id1\ndocid2,id2\ndocid3,id3';
|
||||
}
|
||||
|
||||
updateTableNameHints();
|
||||
@@ -975,7 +975,7 @@ function displayDifferences() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${JSON.stringify(diff.key)}</p>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${formatCompositeKey(diff.key)}</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-warning"><i class="fas fa-exclamation-triangle"></i> ${diff.message}</p>
|
||||
@@ -1008,7 +1008,7 @@ function displayDifferences() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${JSON.stringify(diff.key)}</p>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${formatCompositeKey(diff.key)}</p>
|
||||
<p class="mb-0"><strong>差异字段:</strong> ${diff.field}</p>
|
||||
</div>
|
||||
<div class="collapse" id="diffCollapse${globalIndex}">
|
||||
@@ -1137,7 +1137,7 @@ function displayIdenticalResults() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${JSON.stringify(result.key)}</p>
|
||||
<p class="mb-0 mt-2"><strong>主键:</strong> ${formatCompositeKey(result.key)}</p>
|
||||
</div>
|
||||
<div class="collapse" id="collapse${globalIndex}">
|
||||
<div class="card-body">
|
||||
@@ -1559,16 +1559,34 @@ function showRawData(keyStr) {
|
||||
// 查找生产环境数据
|
||||
if (currentResults.raw_pro_data) {
|
||||
proData = currentResults.raw_pro_data.find(item => {
|
||||
// 比较主键
|
||||
return JSON.stringify(item[Object.keys(key)[0]]) === JSON.stringify(key[Object.keys(key)[0]]);
|
||||
// 支持复合主键比较
|
||||
if (typeof key === 'object' && !Array.isArray(key)) {
|
||||
// 复合主键情况:比较所有主键字段
|
||||
return Object.keys(key).every(keyField =>
|
||||
JSON.stringify(item[keyField]) === JSON.stringify(key[keyField])
|
||||
);
|
||||
} else {
|
||||
// 单主键情况:保持原有逻辑
|
||||
const keyField = Object.keys(key)[0];
|
||||
return JSON.stringify(item[keyField]) === JSON.stringify(key[keyField]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 查找测试环境数据
|
||||
if (currentResults.raw_test_data) {
|
||||
testData = currentResults.raw_test_data.find(item => {
|
||||
// 比较主键
|
||||
return JSON.stringify(item[Object.keys(key)[0]]) === JSON.stringify(key[Object.keys(key)[0]]);
|
||||
// 支持复合主键比较
|
||||
if (typeof key === 'object' && !Array.isArray(key)) {
|
||||
// 复合主键情况:比较所有主键字段
|
||||
return Object.keys(key).every(keyField =>
|
||||
JSON.stringify(item[keyField]) === JSON.stringify(key[keyField])
|
||||
);
|
||||
} else {
|
||||
// 单主键情况:保持原有逻辑
|
||||
const keyField = Object.keys(key)[0];
|
||||
return JSON.stringify(item[keyField]) === JSON.stringify(key[keyField]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3867,7 +3885,7 @@ function renderRawDataContent() {
|
||||
const globalIndex = startIndex + index + 1;
|
||||
const envBadgeClass = item.environment === 'production' ? 'bg-primary' : 'bg-success';
|
||||
|
||||
// 获取主键值用于标识 - 修复主键解析问题
|
||||
// 获取主键值用于标识 - 修复主键解析问题,支持复合主键
|
||||
let keyValue = 'N/A';
|
||||
|
||||
// 从当前配置获取keys,因为query_config可能不在results中
|
||||
@@ -3884,11 +3902,12 @@ function renderRawDataContent() {
|
||||
}).filter(val => val !== 'N/A');
|
||||
|
||||
if (keyValues.length > 0) {
|
||||
// 复合主键显示格式:docid1,id1 或 单主键显示:value1
|
||||
keyValue = keyValues.join(', ');
|
||||
}
|
||||
} else {
|
||||
// 如果没有配置主键,尝试常见的主键字段名
|
||||
const commonKeyFields = ['id', 'statusid', 'key', 'uuid'];
|
||||
const commonKeyFields = ['id', 'statusid', 'key', 'uuid', 'docid'];
|
||||
for (const field of commonKeyFields) {
|
||||
if (item.data[field] !== undefined) {
|
||||
keyValue = item.data[field];
|
||||
@@ -4122,4 +4141,21 @@ function copyRawRecord(recordStr) {
|
||||
} catch (error) {
|
||||
showAlert('danger', '复制失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化复合主键显示
|
||||
function formatCompositeKey(key) {
|
||||
if (!key) {
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
if (typeof key === 'object' && !Array.isArray(key)) {
|
||||
// 复合主键情况:显示为 "docid: value1, id: value2" 格式
|
||||
return Object.entries(key)
|
||||
.map(([field, value]) => `${field}: ${value}`)
|
||||
.join(', ');
|
||||
} else {
|
||||
// 单主键或其他情况:使用JSON格式
|
||||
return JSON.stringify(key);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user