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:
RainySY
2026-05-11 14:27:15 +08:00
parent b3ec20fd77
commit 40c3966e9a
3 changed files with 288 additions and 704 deletions

936
app.go

File diff suppressed because it is too large Load Diff

View File

@@ -126,28 +126,32 @@ async function startMatching() {
progress.value = { current: 0, total: 100, message: '准备中...', phase: 'reading' }
try {
const config = {
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)
const data = await RunMatch(buildMatchConfig())
results.value = data; stats.value.matched = data.length
} catch (err) { errorMsg.value = typeof err === 'string' ? err : (err.message || '匹配失败')
hideProgressNow()
} 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 增强匹配 -----------
async function startAIEnhance() {
if (!fileAPath.value || !fileBPath.value) {
@@ -179,22 +183,7 @@ async function startAIEnhance() {
progress.value = { current: 0, total: 100, message: '正在启动 AI 增强匹配...', phase: 'reading' }
try {
const config = {
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)
const data = await RunMatchWithAI(buildMatchConfig())
results.value = data
stats.value.matched = data.length
} catch (err) {

View File

@@ -2,6 +2,7 @@ package main
import (
"embed"
"log"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
@@ -41,6 +42,6 @@ func main() {
})
if err != nil {
println("Error:", err.Error())
log.Fatalf("应用启动失败: %v", err)
}
}