fix: 修复代码审查全部18项问题,重构导出与匹配引擎
A级(严重): - ExportResults 支持 CSV 格式导出和 IncludeHeader 配置,使用实际表头名 - RunMatchWithAI 消除重复文件读取,提取 runMatchOnData() 内部函数 - AI 缓存文件权限收紧至 0600 B级(中等): - 移除废弃代码约400行 (MonthlyReport/DailyReport/StartMatching/DeepseekEnhanceMatching) - 替换自定义 parseCSVLine 为标准 encoding/csv - GetAICacheInfo 返回命名结构体 AICacheInfo - 时间差排序改为数值比较 - App.vue 提取 buildMatchConfig() 工厂函数消除配置重复 - AllMatches=false 时命中 1.0 相似度可提前结束 B 表循环 C级(轻微): - 魔法数字提取为命名常量 - main.go 替换 println 为 log.Fatalf - 清理未使用变量 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -126,28 +126,32 @@ async function startMatching() {
|
|||||||
progress.value = { current: 0, total: 100, message: '准备中...', phase: 'reading' }
|
progress.value = { current: 0, total: 100, message: '准备中...', phase: 'reading' }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const config = {
|
const data = await RunMatch(buildMatchConfig())
|
||||||
fileAPath: fileAPath.value, fileBPath: fileBPath.value,
|
|
||||||
colAMatchIndex: colAMatchIdx.value, colATimeIndex: colATimeIdx.value,
|
|
||||||
colBMatchIndex: colBMatchIdx.value, colBTimeIndex: colBTimeIdx.value,
|
|
||||||
colBExtractIndex: colBExtractIdx.value,
|
|
||||||
regexPattern: matchConfig.value.regexPattern || '',
|
|
||||||
timeWindow: Number(matchConfig.value.timeWindow) || 12,
|
|
||||||
threshold: Number(matchConfig.value.threshold) || 0.65,
|
|
||||||
allMatches: matchConfig.value.allMatches || false,
|
|
||||||
caseSensitive: matchConfig.value.caseSensitive || false,
|
|
||||||
sortBy: matchConfig.value.sortBy || '',
|
|
||||||
maxPreview: Number(matchConfig.value.maxPreview) || 0,
|
|
||||||
exportFormat: matchConfig.value.exportFormat || 'xlsx',
|
|
||||||
includeHeader: matchConfig.value.includeHeader !== false
|
|
||||||
}
|
|
||||||
const data = await RunMatch(config)
|
|
||||||
results.value = data; stats.value.matched = data.length
|
results.value = data; stats.value.matched = data.length
|
||||||
} catch (err) { errorMsg.value = typeof err === 'string' ? err : (err.message || '匹配失败')
|
} catch (err) { errorMsg.value = typeof err === 'string' ? err : (err.message || '匹配失败')
|
||||||
hideProgressNow()
|
hideProgressNow()
|
||||||
} finally { loading.value = false; if (!errorMsg.value) scheduleProgressDone() }
|
} finally { loading.value = false; if (!errorMsg.value) scheduleProgressDone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildMatchConfig 从响应式状态构建 MatchConfig 对象(消除重复)
|
||||||
|
function buildMatchConfig() {
|
||||||
|
return {
|
||||||
|
fileAPath: fileAPath.value, fileBPath: fileBPath.value,
|
||||||
|
colAMatchIndex: colAMatchIdx.value, colATimeIndex: colATimeIdx.value,
|
||||||
|
colBMatchIndex: colBMatchIdx.value, colBTimeIndex: colBTimeIdx.value,
|
||||||
|
colBExtractIndex: colBExtractIdx.value,
|
||||||
|
regexPattern: matchConfig.value.regexPattern || '',
|
||||||
|
timeWindow: Number(matchConfig.value.timeWindow) || 12,
|
||||||
|
threshold: Number(matchConfig.value.threshold) || 0.65,
|
||||||
|
allMatches: matchConfig.value.allMatches || false,
|
||||||
|
caseSensitive: matchConfig.value.caseSensitive || false,
|
||||||
|
sortBy: matchConfig.value.sortBy || '',
|
||||||
|
maxPreview: Number(matchConfig.value.maxPreview) || 0,
|
||||||
|
exportFormat: matchConfig.value.exportFormat || 'xlsx',
|
||||||
|
includeHeader: matchConfig.value.includeHeader !== false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------- Deepseek AI 增强匹配 -----------
|
// ----------- Deepseek AI 增强匹配 -----------
|
||||||
async function startAIEnhance() {
|
async function startAIEnhance() {
|
||||||
if (!fileAPath.value || !fileBPath.value) {
|
if (!fileAPath.value || !fileBPath.value) {
|
||||||
@@ -179,22 +183,7 @@ async function startAIEnhance() {
|
|||||||
progress.value = { current: 0, total: 100, message: '正在启动 AI 增强匹配...', phase: 'reading' }
|
progress.value = { current: 0, total: 100, message: '正在启动 AI 增强匹配...', phase: 'reading' }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const config = {
|
const data = await RunMatchWithAI(buildMatchConfig())
|
||||||
fileAPath: fileAPath.value, fileBPath: fileBPath.value,
|
|
||||||
colAMatchIndex: colAMatchIdx.value, colATimeIndex: colATimeIdx.value,
|
|
||||||
colBMatchIndex: colBMatchIdx.value, colBTimeIndex: colBTimeIdx.value,
|
|
||||||
colBExtractIndex: colBExtractIdx.value,
|
|
||||||
regexPattern: matchConfig.value.regexPattern || '',
|
|
||||||
timeWindow: Number(matchConfig.value.timeWindow) || 12,
|
|
||||||
threshold: Number(matchConfig.value.threshold) || 0.65,
|
|
||||||
allMatches: matchConfig.value.allMatches || false,
|
|
||||||
caseSensitive: matchConfig.value.caseSensitive || false,
|
|
||||||
sortBy: matchConfig.value.sortBy || '',
|
|
||||||
maxPreview: Number(matchConfig.value.maxPreview) || 0,
|
|
||||||
exportFormat: matchConfig.value.exportFormat || 'xlsx',
|
|
||||||
includeHeader: matchConfig.value.includeHeader !== false
|
|
||||||
}
|
|
||||||
const data = await RunMatchWithAI(config)
|
|
||||||
results.value = data
|
results.value = data
|
||||||
stats.value.matched = data.length
|
stats.value.matched = data.length
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
@@ -41,6 +42,6 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Error:", err.Error())
|
log.Fatalf("应用启动失败: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user