From 9c426cb6066746ffbaeba389fa97a92e56dfe5f9 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Tue, 11 Apr 2023 11:16:57 +0800 Subject: [PATCH] =?UTF-8?q?param=20tz=20=E6=97=B6=E5=8C=BA,0:=E5=8C=97?= =?UTF-8?q?=E4=BA=AC=E6=97=B6=E9=97=B4=201:=E6=B2=99=E7=89=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _const/enum/timezone_e/tz.go | 21 +++++++++++++++++++++ rpc/group.go | 9 ++++++++- script/utils/utils_test.go | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 _const/enum/timezone_e/tz.go diff --git a/_const/enum/timezone_e/tz.go b/_const/enum/timezone_e/tz.go new file mode 100644 index 0000000..3e31ff9 --- /dev/null +++ b/_const/enum/timezone_e/tz.go @@ -0,0 +1,21 @@ +package timezone_e + +import "time" + +type Timezone int + +const ( + TimezoneBeijing Timezone = 0 + TimezoneKSA Timezone = 1 +) + +var Timezones = []Timezone{TimezoneBeijing, TimezoneKSA} +var ( + BeijingTimezoneLoc = time.FixedZone("CST", 8*3600) // 东八 + KSATimezoneLoc = time.FixedZone("CST", 3*3600) // 东三 +) + +var TimezoneLocMap = map[Timezone]*time.Location{ + TimezoneBeijing: BeijingTimezoneLoc, + TimezoneKSA: KSATimezoneLoc, +} diff --git a/rpc/group.go b/rpc/group.go index 1e3abab..c905942 100644 --- a/rpc/group.go +++ b/rpc/group.go @@ -3,6 +3,7 @@ package rpc import ( "encoding/json" "fmt" + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/resource/consul" @@ -119,8 +120,9 @@ func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID // 批量获取用户上麦时长 // param day 获取的天,格式 2006-01-02 +// param tz 时区,0:北京时间 1:沙特时间 // return userId->seconds -func MGetUserOnMic(model *domain.Model, day string, userIds []mysql.ID) (map[mysql.ID]mysql.Num, error) { +func MGetUserOnMic(model *domain.Model, day string, userIds []mysql.ID, tz ...timezone_e.Timezone) (map[mysql.ID]mysql.Num, error) { type Response struct { Code int `json:"code"` Message string `json:"message"` @@ -135,9 +137,14 @@ func MGetUserOnMic(model *domain.Model, day string, userIds []mysql.ID) (map[mys userIdsStr = append(userIdsStr, fmt.Sprintf("%d", userId)) } _url := fmt.Sprintf("%v://%v/inner/mic/onMicSeconds", defaultGroupServerScheme, getGroupHost()) + _tz := timezone_e.TimezoneBeijing + if len(tz) > 0 { + _tz = tz[0] + } resp, err := HttpGet(model, _url, nil, map[string][]string{ "ids": userIdsStr, "day": {day}, + "tz": {fmt.Sprintf("%d", _tz)}, }) if err != nil { model.Log.Errorf("MGetUserOnMic fail:%v", err) diff --git a/script/utils/utils_test.go b/script/utils/utils_test.go index 984772e..ba496fa 100644 --- a/script/utils/utils_test.go +++ b/script/utils/utils_test.go @@ -10,6 +10,6 @@ func TestTestCommon(t *testing.T) { } func TestJwt(t *testing.T) { - token, _ := jwt.GenerateToken(2781, "6373ff5c318c4057886a669b5c9b5301", "hiloApi") + token, _ := jwt.GenerateToken(3951, "7b0535559da045a187ba25a2d27482c0", "hiloApi") t.Logf(token) } -- 2.22.0