Commit 5922a58b authored by hujiebin's avatar hujiebin

feat:获取家族rpc

parent ea614646
package rpc
import (
"encoding/json"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/consul"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/hashicorp/consul/api"
"math/rand"
)
const (
defaultGroupConsulName = "hiloGroup"
defaultGroupServerScheme = "http"
defaultGroupServerAddr = "127.0.0.1:9050" // 默认内网转发,本地回环
)
var groupServerHost = []string{defaultGroupServerAddr}
func init() {
go func() {
address := api.DefaultConfig().Address // 用consul api的default config
if err := consul.RegisterWatcher("services", nil, address, func(serviceStatus map[string]map[string][]string) {
if statusAddrs, ok := serviceStatus[defaultGroupConsulName]; ok {
healthAddrs, _ := statusAddrs[api.HealthPassing]
l := len(healthAddrs)
if l > 0 {
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)
groupServerHost = []string{defaultGroupServerAddr} // 有其他问题都用默认的
}
for status := range statusAddrs {
if status == api.HealthPassing {
continue
}
mylogrus.MyLog.Warnf("consul service wrong state:%v-%v-%v", defaultGroupConsulName, status, statusAddrs[status])
}
}
}); err != nil {
mylogrus.MyLog.Errorf("启动 consul 的watch监控失败")
}
}()
}
// 家族信息
type CvGroupPowerInfo struct {
CvGroupPowerBase `json:",inline"`
CvGroupPowerMember `json:",inline"`
}
// 家族基本信息
type CvGroupPowerBase struct {
GroupPowerId mysql.ID `json:"groupPowerId"` // 家族id
Icon string `json:"icon"` // 家族图片
Name string `json:"name"` // 家族名
Nameplate string `json:"nameplate"` // 铭牌
}
// 家族成员
type CvGroupPowerMember struct {
MemberNum mysql.Num `json:"memberNum"` // 当前成员数
MemberLimit mysql.Num `json:"memberLimit"` // 成员上限
}
// 获取家族
func GetGroupPower(model *domain.Model, groupPowerId mysql.ID) (CvGroupPowerInfo, error) {
infos, err := MGetGroupPower(model, []mysql.ID{groupPowerId})
if err != nil {
return CvGroupPowerInfo{}, nil
}
return infos[groupPowerId], nil
}
// 批量获取家族
func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID]CvGroupPowerInfo, error) {
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data map[mysql.ID]CvGroupPowerInfo
}
var res = make(map[mysql.ID]CvGroupPowerInfo)
if len(groupPowerIds) <= 0 {
return res, nil
}
var idsStr []string
for _, userId := range groupPowerIds {
idsStr = append(idsStr, fmt.Sprintf("%d", userId))
}
_url := fmt.Sprintf("%v://%v/inner/groupPower/infos", defaultGroupServerScheme, getGroupHost())
resp, err := HttpGet(model, _url, nil, map[string][]string{
"ids": idsStr,
})
if err != nil {
model.Log.Errorf("MGetGroupPower fail:%v", err)
return res, err
}
response := new(Response)
if err = json.Unmarshal(resp, response); err != nil {
model.Log.Errorf("MGetUserSvip json fail:%v", err)
return res, err
}
res = response.Data
return res, nil
}
func getGroupHost() string {
l := len(groupServerHost)
r := rand.Intn(l) // 随机一个
mylogrus.MyLog.Infof("getHostGroup:%v---%v", r, groupServerHost[r])
return groupServerHost[r]
}
......@@ -205,10 +205,10 @@ func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string
}(fromUserId, msg, rspUids, err)
if err != nil {
mylogrus.MyLog.Errorf("grpc SendGroupChatNotice send fail,userId:", fromUserId)
mylogrus.MyLog.Errorf("grpc SendGroupChatNotice send fail,userId:%v", fromUserId)
return err
} else {
mylogrus.MyLog.Info("grpc SendGroupChatNotice send success,userId:", fromUserId)
mylogrus.MyLog.Infof("grpc SendGroupChatNotice send success,userId:%v", fromUserId)
}
} else {
return err
......
......@@ -17,7 +17,7 @@ type Msg struct {
func main() {
var rpcLogs []RpcLog
if err := mysql.ProdReadOnlyDB.Table("rpc_log_202303 ").Where("`type` = 146").
Where("created_time >= ? and created_time < ?", "2023-03-06", "2023-03-07").Find(&rpcLogs).Error; err != nil {
Where("created_time >= ? and created_time < ?", "2023-03-08", "2023-03-09").Find(&rpcLogs).Error; err != nil {
panic(err)
}
var data = make(map[int]int)
......
MODE=local
\ No newline at end of file
[DATABASE]
MYSQL_HOST=47.244.34.27:3306
MYSQL_USERNAME=root
MYSQL_PASSWORD=yX0jPAhO0I4s2zlA
MYSQL_DB=hilo
[DATABASECODE]
MYSQL_HOST=47.244.34.27:3306
MYSQL_USERNAME=root
MYSQL_PASSWORD=yX0jPAhO0I4s2zlA
MYSQL_DB=hilo_code
[REDIS]
REDIS_HOST=47.244.34.27:6379
REDIS_PASSWORD=8QZ9JD1zLvPR3yHf
[JWT]
SECRET=hilo1632
ISSUER_API=hiloApi
ISSUER_Mgr=hiloMgr
EXPIRE=24h
[APP]
MASTER=true
BIZ_SECRET=biz
OPERATION_SECRET=operation1258236
SUPERUSER=2701,2831
OFFICIAL_STAFF=2701,2831
OFFICIAL_GROUP=@TGS#3NC2ATRHS,@TGS#33W3KNLHK
MINIMAL_VERSION_ANDROID=212
MINIMAL_VERSION_IOS=100
[OSS]
OSS_ACCESS_KEY_ID=LTAIxdazV2pCuV3T
OSS_ACCESS_KEY_SECRET=zuAnreAXQ6vlAKnvvmolFLfb1N5w5S
OSS_ROLE_ARN=acs:ram::1509841556585969:role/aliyunosstokengeneratorrole
OSS_END_POINT=http://oss-accelerate.aliyuncs.com
OSS_BUCKET=starvoice
OSS_CDN=https://oss.chathot.me/
OSS_EXPIRED_TIME=3600
OSS_STS_POINT=me-east-1
OSS_STS=sts-faceline-demo
OSS_STS_AES=484194d4d0f968a7
[AWS]
AWS_BUCKET=starchat
AWS_CDN=https://image.whoisamy.shop/
AWS_DIR=hilo/
[RONGYUN]
RONG_CLOUD_APP_KEY=pvxdm17jpe9tr
RONG_CLOUD_APP_SECRET=rI4giiKWaBS4
RONG_CLOUD_URL=https://api-sg01.ronghub.com
[TENCENTYUN]
TENCENTYUN_APP_ID=1400548270
TENCENTYUN_KEY=321bd60f73096b059c7350f1cd97d51028850b34fa58c5c0d26bb4a19e783de8
TX_OVERSEA_APP_ID=40000066
TX_OVERSEA_KEY=3ab68ea5bddc8774d90b8c764ae71188914bd5fd06f30b28790c51e44ca7885c
[EMAS]
REGION_ID=cn-hangzhou
ACCESS_KEY_ID=LTAI4FhNPzxdzD4w6bHirL9Z
ACCESS_KEY_SECRET=OQvUJpXDrjGi3g1F2aHiAIFWIvLdbP
ANDROID_APP_KEY=30250713
ANDROID_APP_SECRET=cae7b9a9d3e54577d2c3b60bf6d23047
IOS_APP_KEY=30240346
IOS_APP_SECRET=57f33ab9ca6a957a8c659f2b0b6d1205
APNS=DEV
[AGORA]
APP_ID=fc3e087f701b4f788099e1924c3cc7b0
APP_CERTIFICATE=ff29c100a613433db82324e8411eabc8
CUSTOMER_KEY=6b132c0ff7164560a2bc53fda06ea85a
CUSTOMER_SECRET=eedad2cd16d24834990d5450ace9f1ce
CALLBACK_SECRET=n_ZizS_N8
[CHECKOUT]
AUTHORIZATION=sk_test_9b5e771c-5a3f-4a8d-a4da-31b19bd43d83
URL=https://api.sandbox.checkout.com/hosted-payments
[MATCH]
MATCH_FREE_TIME=60
MATCH_FREE_TIME_VIP=300
MATCH_ADD_TIME_FREE=90
MATCH_AGORA_TIME=30
MATCH_CYCLE=8
MATCH_USER_EXPIRES=480
MATCH_SUCCESS_WAIT_DURATION=10
MATCH_SUCCESS_SINGLE_WAIT_TIME_IN_SEC=12
MATCH_SUCCESS_DUAL_WAIT_TIME_IN_SEC=15
[ONLINE]
ONLINE_CYCLE=600
ONLINE_USER_EXPIRES=259200
[VIDEO]
VIDEO_DAILY_FREE_NUM=20
VIDEO_FREE_TIME=60
VIDEO_FREE_TIME_VIP=300
VIDEO_ADD_TIME_FREE=60
VIDEO_AGORA_TIME=30
[SESSION]
SESSION_DAILY_FREE_NUM=50
[BEAN]
DIAMOND_BEAN_RATE=90
[H5]
USER_LEVEL=http://test.chathot.me/action/activityhtml/hiloUserLevel/index.html
GROUP_SUPPORT=http://test.chathot.me/action/activityhtml/21_12_06/page.html
LUCKY_WHEEL=https://h5.whoisamy.shop/action/activityhtml/21_12_30/page.html
NOBLE_BUY_IOS=https://h5.whoisamy.shop/action/hiloHtml/lxt_h5/page.html
[GROUPIM]
MSG_SORT_EXPIRE=43200
MSG_SORT_SNAP=300
[GRADE]
CHARM_SPEED_VIP=15
ACTITY_SPEED_VIP=15
WEALTH_SPEED_VIP=15
[LIKE]
I_LIKE_NUM=30
I_LIKE_NUM_VIP=100
I_LIKE_NUM_NOBLE=1000
[APPLEPAY]
PASSWORD=38702750a05c4cb09c9d6ca646835634
[REGISTER]
IMEI_TOTAL=3
IMEI_OAUTH=2
ACCOUNT_IP=100
ACCOUNT_IP_DURATION=21600
[BANNER]
GIFT_BANNER_LEVEL1=100
GIFT_BANNER_LEVEL2=2000
GIFT_BANNER_LEVEL3=5000
[DIAMOND]
DAILY_LOGIN_IMEI_LIMIT=200
DAILY_LOGIN_IP_LIMIT=5
PRIVATE_GIFT_RETURN=1440
[LUCKY_WHEEL]
MINIMAL_PARTICIPANT=2
WAIT_TIMELONG=10
WINNER_DIAMOND_BANNER=100
[GROUP_CUSTOM_THEME]
PIC_LIMIT=5
DAY=10
[GIFT]
WALL_DIAMOND=10
[DAILY]
LOGIN_COMMON=5
LOGIN_VIP=300
[DAILY]
LOGIN_COMMON=5
LOGIN_VIP=300
[FRUIT_TYCOON]
POOL_RATIO=20
WATERMELON_RATIO=70
package test
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/rpc"
"testing"
)
func TestMGetGroupPower(t *testing.T) {
res, err := rpc.MGetGroupPower(domain.CreateModelNil(), []mysql.ID{250, 251})
println(res, err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment