messageClass.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package common
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/entity"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
  5. "app.yhyue.com/moapp/jybase/common"
  6. "context"
  7. "fmt"
  8. "log"
  9. "strings"
  10. )
  11. // InitClassSearchMap 初始化需要展示细化分类的消息分类信息
  12. func InitClassSearchMap() {
  13. entity.ClassSearchMap = map[int64][]entity.MsgClass{}
  14. entity.ClassMap = map[int64]entity.MsgClass{}
  15. // 初始化需要展示消息细化分类的groupid 和对应的class信息
  16. if config.ConfigJson.ClassSearchList != nil && len(config.ConfigJson.ClassSearchList) > 0 {
  17. groupIDs := config.ConfigJson.ClassSearchList
  18. qArr := []string{}
  19. for i := 0; i < len(groupIDs); i++ {
  20. qArr = append(qArr, fmt.Sprintf("%d", groupIDs[i]))
  21. }
  22. // 查库
  23. 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;"
  24. rs, err := entity.ClickhouseConn.Query(context.Background(), q)
  25. if err != nil {
  26. log.Println("InitClassSearchMap 查询message_class出错:", err)
  27. return
  28. }
  29. for rs.Next() {
  30. mg := entity.MsgGroup{}
  31. err = rs.ScanStruct(&mg)
  32. if err != nil {
  33. log.Println("InitClassSearchMap 初始化rs ScanStruct出错:", err)
  34. return
  35. }
  36. groupID := common.Int64All(mg.GroupId)
  37. msgName := common.ObjToString(mg.Name)
  38. msgType := common.Int64All(mg.Msg_type)
  39. img := common.ObjToString(mg.Img)
  40. // 处理成map
  41. if _, ok := entity.ClassSearchMap[groupID]; !ok {
  42. entity.ClassSearchMap[groupID] = []entity.MsgClass{}
  43. }
  44. tmp := entity.MsgClass{
  45. MsgType: msgType,
  46. Name: msgName,
  47. Img: img,
  48. }
  49. entity.ClassSearchMap[groupID] = append(entity.ClassSearchMap[groupID], tmp)
  50. entity.ClassMap[msgType] = tmp
  51. }
  52. }
  53. }
  54. //func () {
  55. //
  56. //}