summary.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/job/main/account-summary/model"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. _SummaryTable = "ugc:AccountSum"
  10. _ColFamily = "accountsum"
  11. )
  12. // Save is
  13. func (d *Dao) Save(ctx context.Context, key string, data map[string][]byte) error {
  14. values := map[string]map[string][]byte{
  15. _ColFamily: data,
  16. }
  17. _, err := d.AccountSumHBase.PutStr(ctx, _SummaryTable, key, values)
  18. return err
  19. }
  20. // GetByKey is
  21. func (d *Dao) GetByKey(ctx context.Context, key string) (*model.AccountSummary, error) {
  22. res, err := d.AccountSumHBase.GetStr(ctx, _SummaryTable, key)
  23. if err != nil {
  24. return nil, errors.WithStack(err)
  25. }
  26. sum := model.NewAccountSummary()
  27. for _, c := range res.Cells {
  28. v := string(c.Value)
  29. switch string(c.Qualifier) {
  30. case "birthday":
  31. sum.Birthday = v
  32. case "face":
  33. sum.Face = v
  34. case "mid":
  35. sum.Mid, _ = strconv.ParseInt(v, 10, 64)
  36. case "name":
  37. sum.Name = v
  38. case "rank":
  39. sum.Rank, _ = strconv.ParseInt(v, 10, 64)
  40. case "sex":
  41. sum.Sex, _ = strconv.ParseInt(v, 10, 64)
  42. case "sign":
  43. sum.Sign = v
  44. case "official.role":
  45. sum.Official.Role, _ = strconv.ParseInt(v, 10, 64)
  46. case "official.mid":
  47. sum.Official.Mid, _ = strconv.ParseInt(v, 10, 64)
  48. case "official.title":
  49. sum.Official.Title = v
  50. case "official.description":
  51. sum.Official.Description = v
  52. case "exp.mid":
  53. sum.Exp.Mid, _ = strconv.ParseInt(v, 10, 64)
  54. case "exp.exp":
  55. sum.Exp.Exp, _ = strconv.ParseInt(v, 10, 64)
  56. case "relation.mid":
  57. sum.RelationStat.Mid, _ = strconv.ParseInt(v, 10, 64)
  58. case "relation.follower":
  59. sum.RelationStat.Follower, _ = strconv.ParseInt(v, 10, 64)
  60. case "relation.following":
  61. sum.RelationStat.Following, _ = strconv.ParseInt(v, 10, 64)
  62. case "relation.black":
  63. sum.RelationStat.Black, _ = strconv.ParseInt(v, 10, 64)
  64. case "relation.whisper":
  65. sum.RelationStat.Whisper, _ = strconv.ParseInt(v, 10, 64)
  66. case "block.mid":
  67. sum.Block.Mid, _ = strconv.ParseInt(v, 10, 64)
  68. case "block.block_status":
  69. sum.Block.BlockStatus, _ = strconv.ParseInt(v, 10, 64)
  70. case "block.start_time":
  71. sum.Block.StartTime = v
  72. case "block.end_time":
  73. sum.Block.EndTime = v
  74. case "passport.mid":
  75. sum.Passport.Mid, _ = strconv.ParseInt(v, 10, 64)
  76. case "passport.tel_status":
  77. sum.Passport.TelStatus, _ = strconv.ParseInt(v, 10, 64)
  78. case "passport.country_id":
  79. sum.Passport.CountryID, _ = strconv.ParseInt(v, 10, 64)
  80. case "passport.join_ip":
  81. sum.Passport.JoinIP = v
  82. case "passport.join_time":
  83. sum.Passport.JoinTime = v
  84. case "passport.email_suffix":
  85. sum.Passport.EmailSuffix = v
  86. case "passport.origin_type":
  87. sum.Passport.OriginType, _ = strconv.ParseInt(v, 10, 64)
  88. case "passport.reg_type":
  89. sum.Passport.RegType, _ = strconv.ParseInt(v, 10, 64)
  90. }
  91. }
  92. return sum, nil
  93. }