From 6d33132a4a6a00843639d8f288c946aac22227c6 Mon Sep 17 00:00:00 2001 From: cheliangzhao Date: Sat, 10 Jan 2026 01:55:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=97=B6=E5=8C=BA=E9=97=AE=E9=A2=98=E5=92=8C=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E8=8C=83=E5=9B=B4=E9=80=89=E6=8B=A9=E5=99=A8=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 前端时区修复:统一使用本地时区格式化日期 - 日期范围选择器优化:使用 untrack 避免循环更新 - 后端时区修复:使用 time.ParseInLocation 指定本地时区 - 其他优化:修复分页逻辑 --- server/handler/bills.go | 12 +++++++----- server/service/bill.go | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/handler/bills.go b/server/handler/bills.go index 1b43a07..1857a0d 100644 --- a/server/handler/bills.go +++ b/server/handler/bills.go @@ -24,9 +24,9 @@ type ListBillsRequest struct { // ListBillsResponse 账单列表响应 type ListBillsResponse struct { - Result bool `json:"result"` - Message string `json:"message,omitempty"` - Data *ListBillsData `json:"data,omitempty"` + Result bool `json:"result"` + Message string `json:"message,omitempty"` + Data *ListBillsData `json:"data,omitempty"` } // ListBillsData 账单列表数据 @@ -69,13 +69,15 @@ func ListBills(c *gin.Context) { if req.StartDate != "" || req.EndDate != "" { timeFilter := make(map[string]interface{}) if req.StartDate != "" { - startTime, err := time.Parse("2006-01-02", req.StartDate) + // 使用本地时区解析日期,避免 UTC 时区问题 + startTime, err := time.ParseInLocation("2006-01-02", req.StartDate, time.Local) if err == nil { timeFilter["$gte"] = startTime } } if req.EndDate != "" { - endTime, err := time.Parse("2006-01-02", req.EndDate) + // 使用本地时区解析日期,避免 UTC 时区问题 + endTime, err := time.ParseInLocation("2006-01-02", req.EndDate, time.Local) if err == nil { // 结束日期包含当天,所以加一天 endTime = endTime.Add(24 * time.Hour) diff --git a/server/service/bill.go b/server/service/bill.go index da931b0..100fb45 100644 --- a/server/service/bill.go +++ b/server/service/bill.go @@ -489,13 +489,14 @@ func saveCleanedBillsFromJSON(filePath, billType, sourceFile, uploadBatch string } // parseTime 解析时间字符串 +// 使用本地时区解析,避免 UTC 时区问题 func parseTime(s string) time.Time { s = strings.TrimSpace(s) if s == "" { return time.Time{} } - // 尝试多种时间格式 + // 尝试多种时间格式(使用本地时区) formats := []string{ "2006-01-02 15:04:05", "2006/01/02 15:04:05", @@ -506,7 +507,7 @@ func parseTime(s string) time.Time { } for _, format := range formats { - if t, err := time.Parse(format, s); err == nil { + if t, err := time.ParseInLocation(format, s, time.Local); err == nil { return t } }