fix(server, webhook): 添加 MongoDB 数据持久化和上传前去重功能

- 优化支付宝时间格式解析(支持无前导零格式)
- 修复 webhook 服务编译错误
- 更新版本号至 1.0.5
This commit is contained in:
CHE LIANG ZHAO
2026-01-14 14:53:50 +08:00
parent 05ab270677
commit 4805f94126
6 changed files with 50 additions and 4 deletions

View File

@@ -490,12 +490,44 @@ func saveCleanedBillsFromJSON(filePath, billType, sourceFile, uploadBatch string
// parseTime 解析时间字符串
// 使用本地时区解析,返回 model.LocalTime 类型
// 支持支付宝格式: 2026/1/13 20:08 (月份和日期可能没有前导零)
func parseTime(s string) model.LocalTime {
s = strings.TrimSpace(s)
if s == "" {
return model.LocalTime(time.Time{})
}
// 先尝试标准化支付宝格式(将单数日期/月份补零)
// 例如: "2026/1/13 20:08" -> "2026/01/13 20:08"
if strings.Contains(s, "/") && !strings.Contains(s, "-") {
// 匹配格式: YYYY/M/D 或 YYYY/M/D HH:mm 或 YYYY/M/D HH:mm:ss
parts := strings.Split(s, " ")
if len(parts) > 0 {
datePart := parts[0]
// 使用正则表达式将单数日期/月份补零
// 例如: "2026/1/13" -> "2026/01/13"
dateParts := strings.Split(datePart, "/")
if len(dateParts) == 3 {
year := dateParts[0]
month := dateParts[1]
day := dateParts[2]
// 补零
if len(month) == 1 {
month = "0" + month
}
if len(day) == 1 {
day = "0" + day
}
datePart = year + "/" + month + "/" + day
if len(parts) > 1 {
s = datePart + " " + strings.Join(parts[1:], " ")
} else {
s = datePart
}
}
}
}
// 尝试多种时间格式(使用本地时区)
formats := []string{
"2006-01-02 15:04:05",