analysisManager.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package userAnalysis
  2. import (
  3. "github.com/gogf/gf/v2/frame/g"
  4. "github.com/gogf/gf/v2/util/gconv"
  5. )
  6. type (
  7. UserAnalysis struct {
  8. UserMapping map[string]BaseUserId //职位id、mongouserId对应的baseUserId
  9. BinPhone, BindMail map[BaseUserId]bool
  10. Vip, Vip15, Vip30 map[BaseUserId]bool
  11. Member, MemberExpire map[BaseUserId]bool
  12. }
  13. BaseUserId int64
  14. AnalysisRes struct {
  15. Name, Code string //标签名字
  16. Data map[BaseUserId]bool //数据
  17. }
  18. )
  19. func NewManager() *UserAnalysis {
  20. return &UserAnalysis{
  21. UserMapping: map[string]BaseUserId{},
  22. BinPhone: map[BaseUserId]bool{},
  23. BindMail: map[BaseUserId]bool{},
  24. Vip: map[BaseUserId]bool{},
  25. Vip15: map[BaseUserId]bool{},
  26. Vip30: map[BaseUserId]bool{},
  27. Member: map[BaseUserId]bool{},
  28. MemberExpire: map[BaseUserId]bool{},
  29. }
  30. }
  31. func (ua *UserAnalysis) LoadMapping() error {
  32. data, err := g.DB().Query(ctx, "SELECT mgoUserId,positionId,baseUserId FROM dwd_mgo_position")
  33. if err != nil {
  34. return err
  35. }
  36. newMapping := map[string]BaseUserId{}
  37. for _, m := range data.List() {
  38. var (
  39. mgoUserId = gconv.String(m["mgoUserId"])
  40. positionId = gconv.String(m["positionId"])
  41. baseUserId = BaseUserId(gconv.Int64(m["baseUserId"]))
  42. )
  43. newMapping[mgoUserId] = baseUserId
  44. newMapping[positionId] = baseUserId
  45. }
  46. ua.UserMapping = newMapping
  47. return nil
  48. }