diff --git a/rpc/group.go b/rpc/group.go index 8b9c6c793d00bbcbedc81bc7c8fc6d822947920e..1e3abab56b6db5173506e7e47e91ccbf2543ab96 100644 --- a/rpc/group.go +++ b/rpc/group.go @@ -30,7 +30,7 @@ func init() { mylogrus.MyLog.Infof("consul service update state:%v-%v", defaultGroupConsulName, healthAddrs) groupServerHost = healthAddrs } else { - mylogrus.MyLog.Warnf("consul service update local state:%v-%v", defaultFinanceConsulName, defaultFinanceServerAddr) + mylogrus.MyLog.Warnf("consul service update local state:%v-%v", defaultGroupConsulName, defaultGroupServerScheme) groupServerHost = []string{defaultGroupServerAddr} // 有其他问题都用默认的 } for status := range statusAddrs { @@ -117,6 +117,41 @@ func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID return res, nil } +// 批量获取用户上麦时长 +// param day 获取的天,格式 2006-01-02 +// return userId->seconds +func MGetUserOnMic(model *domain.Model, day string, userIds []mysql.ID) (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", defaultGroupServerScheme, getGroupHost()) + resp, err := HttpGet(model, _url, nil, map[string][]string{ + "ids": userIdsStr, + "day": {day}, + }) + 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) // 随机一个 diff --git a/test/rpc_test.go b/test/rpc_test.go index 71b8af57a9784432fd6002b1c4802c6ac599cc19..a6b6afad175ff5c2b1a291fd09abd614f3a73066 100644 --- a/test/rpc_test.go +++ b/test/rpc_test.go @@ -11,3 +11,8 @@ func TestMGetGroupPower(t *testing.T) { res, err := rpc.MGetGroupPower(domain.CreateModelNil(), []mysql.ID{250, 251}) println(res, err) } + +func TestMGetUserOnMic(t *testing.T) { + res, err := rpc.MGetUserOnMic(domain.CreateModelNil(), "2023-03-16", []mysql.ID{2781, 4549, 4556, 4559}) + println(res, err) +}