From 80e26bb71d56f250a2e80018b1355253dd9be186 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Tue, 11 Apr 2023 15:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=8C=83=E5=9B=B4=E4=B8=8A=E9=BA=A6=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/group.go | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/rpc/group.go b/rpc/group.go index c905942..b43cf38 100644 --- a/rpc/group.go +++ b/rpc/group.go @@ -118,7 +118,7 @@ func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID return res, nil } -// 批量获取用户上麦时长 +// 批量获取用户天上麦时长 // param day 获取的天,格式 2006-01-02 // param tz 时区,0:北京时间 1:沙特时间 // return userId->seconds @@ -159,6 +159,49 @@ func MGetUserOnMic(model *domain.Model, day string, userIds []mysql.ID, tz ...ti return res, nil } +// 批量获取用户范围上麦时长 +// param beginDate 获取的天,格式 2006-01-02 +// param endDate 获取的天,格式 2006-01-02 +// param tz 时区,0:北京时间 1:沙特时间 +// return userId->seconds +func MGetUserOnMicRange(model *domain.Model, beginDate, endDate 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"` + Data map[mysql.ID]mysql.Num + } + var res = make(map[mysql.ID]mysql.Num) + if len(userIds) <= 0 { + return res, nil + } + var userIdsStr []string + for _, userId := range userIds { + userIdsStr = append(userIdsStr, fmt.Sprintf("%d", userId)) + } + _url := fmt.Sprintf("%v://%v/inner/mic/onMicSeconds/range", defaultGroupServerScheme, getGroupHost()) + _tz := timezone_e.TimezoneBeijing + if len(tz) > 0 { + _tz = tz[0] + } + resp, err := HttpGet(model, _url, nil, map[string][]string{ + "ids": userIdsStr, + "beginDate": {beginDate}, + "endDate": {endDate}, + "tz": {fmt.Sprintf("%d", _tz)}, + }) + if err != nil { + model.Log.Errorf("MGetUserOnMic fail:%v", err) + return res, err + } + response := new(Response) + if err = json.Unmarshal(resp, response); err != nil { + model.Log.Errorf("MGetUserOnMic json fail:%v", err) + return res, err + } + res = response.Data + return res, nil +} + func getGroupHost() string { l := len(groupServerHost) r := rand.Intn(l) // 随机一个 -- 2.22.0