Files
billai/server/service/cleaner.go
2026-01-26 13:44:22 +08:00

59 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package service 业务逻辑层
package service
import (
"billai-server/adapter"
)
// CleanOptions 清洗选项(保持向后兼容)
type CleanOptions = adapter.CleanOptions
// CleanResult 清洗结果(保持向后兼容)
type CleanResult = adapter.CleanResult
// RunCleanScript 执行清洗脚本(使用适配器)
// inputPath: 输入文件路径
// outputPath: 输出文件路径
// opts: 清洗选项
func RunCleanScript(inputPath, outputPath string, opts *CleanOptions) (*CleanResult, error) {
cleaner := adapter.GetCleaner()
return cleaner.Clean(inputPath, outputPath, opts)
}
// ConvertBillFile 转换账单文件格式xlsx -> csv处理编码
// 返回转换后的文件路径和检测到的账单类型
func ConvertBillFile(inputPath string) (outputPath string, billType string, err error) {
cleaner := adapter.GetCleaner()
return cleaner.Convert(inputPath)
}
// DetectBillTypeFromOutput 从脚本输出中检测账单类型
// 保留此函数以兼容其他调用
func DetectBillTypeFromOutput(output string) string {
if containsSubstring(output, "支付宝") {
return "alipay"
}
if containsSubstring(output, "微信") {
return "wechat"
}
if containsSubstring(output, "京东") {
return "jd"
}
return ""
}
// containsSubstring 检查字符串是否包含子串
func containsSubstring(s, substr string) bool {
return len(s) >= len(substr) && (s == substr || len(substr) == 0 ||
(len(s) > 0 && len(substr) > 0 && findSubstring(s, substr)))
}
func findSubstring(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}