1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package common
- import (
- "app.yhyue.com/moapp/MessageCenter/entity"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
- "app.yhyue.com/moapp/jybase/common"
- "context"
- "fmt"
- "log"
- "strings"
- )
- // InitClassSearchMap 初始化需要展示细化分类的消息分类信息
- func InitClassSearchMap() {
- entity.ClassSearchMap = map[int64][]entity.MsgClass{}
- entity.ClassMap = map[int64]entity.MsgClass{}
- // 初始化需要展示消息细化分类的groupid 和对应的class信息
- if config.ConfigJson.ClassSearchList != nil && len(config.ConfigJson.ClassSearchList) > 0 {
- groupIDs := config.ConfigJson.ClassSearchList
- qArr := []string{}
- for i := 0; i < len(groupIDs); i++ {
- qArr = append(qArr, fmt.Sprintf("%d", groupIDs[i]))
- }
- // 查库
- q := "SELECT msg_type,msg_name as name,group_id,img FROM message_class where group_id in (" + strings.Join(qArr, ",") + ") order by msg_type;"
- rs, err := entity.ClickhouseConn.Query(context.Background(), q)
- if err != nil {
- log.Println("InitClassSearchMap 查询message_class出错:", err)
- return
- }
- for rs.Next() {
- mg := entity.MsgGroup{}
- err = rs.ScanStruct(&mg)
- if err != nil {
- log.Println("InitClassSearchMap 初始化rs ScanStruct出错:", err)
- return
- }
- groupID := common.Int64All(mg.GroupId)
- msgName := common.ObjToString(mg.Name)
- msgType := common.Int64All(mg.Msg_type)
- img := common.ObjToString(mg.Img)
- // 处理成map
- if _, ok := entity.ClassSearchMap[groupID]; !ok {
- entity.ClassSearchMap[groupID] = []entity.MsgClass{}
- }
- tmp := entity.MsgClass{
- MsgType: msgType,
- Name: msgName,
- Img: img,
- }
- entity.ClassSearchMap[groupID] = append(entity.ClassSearchMap[groupID], tmp)
- entity.ClassMap[msgType] = tmp
- }
- }
- }
- //func () {
- //
- //}
|