diff --git a/internal/db/models/http_access_log_dao.go b/internal/db/models/http_access_log_dao.go index 9f5ce54b..79d948a3 100644 --- a/internal/db/models/http_access_log_dao.go +++ b/internal/db/models/http_access_log_dao.go @@ -206,7 +206,14 @@ Loop: // CreateHTTPAccessLog 写入单条访问日志 func (this *HTTPAccessLogDAO) CreateHTTPAccessLog(tx *dbs.Tx, dao *HTTPAccessLogDAO, accessLog *pb.HTTPAccessLog) error { - var day = timeutil.FormatTime("Ymd", accessLog.Timestamp) + var day = "" + // 注意:如果你修改了 TimeISO8601 的逻辑,这里也需要同步修改 + if len(accessLog.TimeISO8601) > 10 { + day = strings.ReplaceAll(accessLog.TimeISO8601[:10], "-", "") + } else { + timeutil.FormatTime("Ymd", accessLog.Timestamp) + } + tableDef, err := SharedHTTPAccessLogManager.FindLastTable(dao.Instance, day, true) if err != nil { return err diff --git a/internal/db/models/sys_setting_dao.go b/internal/db/models/sys_setting_dao.go index 7ad3db64..53988f73 100644 --- a/internal/db/models/sys_setting_dao.go +++ b/internal/db/models/sys_setting_dao.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/remotelogs" "github.com/TeaOSLab/EdgeAPI/internal/utils" "github.com/TeaOSLab/EdgeAPI/internal/zero" + "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/userconfigs" @@ -13,6 +14,7 @@ import ( "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/types" + "time" ) type SysSettingDAO dbs.DAO @@ -211,6 +213,18 @@ func (this *SysSettingDAO) NotifyUpdate(tx *dbs.Tx, code string) error { switch code { case systemconfigs.SettingCodeAccessLogQueue: accessLogQueueChanged <- zero.New() + case systemconfigs.SettingCodeAdminUIConfig: + // 修改当前时区 + config, err := this.ReadAdminUIConfig(nil, nil) + if err == nil && config != nil { + if len(config.TimeZone) == 0 { + config.TimeZone = nodeconfigs.DefaultTimeZoneLocation + } + location, err := time.LoadLocation(config.TimeZone) + if err == nil && time.Local != location { + time.Local = location + } + } } return nil } diff --git a/internal/nodes/api_node.go b/internal/nodes/api_node.go index c93166c1..a72c9bd9 100644 --- a/internal/nodes/api_node.go +++ b/internal/nodes/api_node.go @@ -15,6 +15,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/setup" "github.com/TeaOSLab/EdgeAPI/internal/utils" "github.com/TeaOSLab/EdgeCommon/pkg/iplibrary" + "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/go-sql-driver/mysql" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/dbs" @@ -132,6 +133,9 @@ func (this *APINode) Start() { logs.Println("[API_NODE]notify ready ...") dbs.NotifyReady() + // 设置时区 + this.setupTimeZone() + // 读取配置 this.setProgress("DATABASE", "加载API配置") logs.Println("[API_NODE]reading api config ...") @@ -811,3 +815,17 @@ func (this *APINode) setProgress(name, description string) { Description: description, } } + +// 设置时区 +func (this *APINode) setupTimeZone() { + config, err := models.SharedSysSettingDAO.ReadAdminUIConfig(nil, nil) + if err == nil && config != nil { + if len(config.TimeZone) == 0 { + config.TimeZone = nodeconfigs.DefaultTimeZoneLocation + } + location, err := time.LoadLocation(config.TimeZone) + if err == nil && time.Local != location { + time.Local = location + } + } +}