getsubscribeinfologic.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jyBXSubscribe/rpc/model"
  6. "jyBXSubscribe/rpc/internal/svc"
  7. "jyBXSubscribe/rpc/type/bxsubscribe"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type GetSubScribeInfoLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewGetSubScribeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubScribeInfoLogic {
  16. return &GetSubScribeInfoLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. // 订阅设置获取
  23. func (l *GetSubScribeInfoLogic) GetSubScribeInfo(in *bxsubscribe.UserReq) (*bxsubscribe.UserResq, error) {
  24. // todo: add your logic here and delete this line
  25. data := model.NewSubscribePush(in.Types).GetSubScribeInfo(in)
  26. items, ok := (*data)["items"].([]map[string]interface{})
  27. if !ok {
  28. inter_items, _ := (*data)["items"].([]interface{})
  29. items = common.ObjArrToMapArr(inter_items)
  30. }
  31. buyerclass, _ := (*data)["buyerclass"].([]interface{})
  32. infotype, _ := (*data)["infotype"].([]interface{})
  33. keytip := false
  34. if in.Types == model.MemberFlag && in.PositionType == 0 {
  35. keytip = (*data)["b_keytip"].(bool)
  36. }
  37. return &bxsubscribe.UserResq{
  38. ErrorCode: 0,
  39. ErrorMsg: "",
  40. Data: &bxsubscribe.Subscribe{
  41. Area: l.formatM(common.ObjToMap((*data)["area"])),
  42. Buyerclass: common.ObjArrToStringArr(buyerclass),
  43. Infotype: common.ObjArrToStringArr(infotype),
  44. Matchway: common.Int64All((*data)["matchway"]),
  45. Projectmatch: common.Int64All((*data)["projectmatch"]),
  46. Items: l.formatItems(items),
  47. Keytip: keytip,
  48. },
  49. }, nil
  50. }
  51. //格式转化 map<string,list>转化
  52. func (l *GetSubScribeInfoLogic) formatM(m *map[string]interface{}) map[string]*bxsubscribe.List {
  53. retM := map[string]*bxsubscribe.List{}
  54. if len(*m) == 0 {
  55. return retM
  56. }
  57. for k, v := range *m {
  58. s_v, ok := v.([]string)
  59. if !ok {
  60. interf, _ := v.([]interface{})
  61. s_v = common.ObjArrToStringArr(interf)
  62. }
  63. retM[k] = &bxsubscribe.List{
  64. Value: s_v,
  65. }
  66. }
  67. return retM
  68. }
  69. func (l *GetSubScribeInfoLogic) formatItems(m []map[string]interface{}) []*bxsubscribe.Items {
  70. items := make([]*bxsubscribe.Items, len(m))
  71. for k, v := range m {
  72. items[k] = &bxsubscribe.Items{
  73. SItem: common.ObjToString(v["s_item"]),
  74. UpdateTime: common.Int64All(v["updatetime"]),
  75. }
  76. akey, _ := v["a_key"].([]map[string]interface{})
  77. pbKey := make([]*bxsubscribe.Keys, len(akey))
  78. for kk, vv := range akey {
  79. key, ok := vv["key"].([]string)
  80. if !ok {
  81. inter_vv, _ := vv["key"].([]interface{})
  82. key = common.ObjArrToStringArr(inter_vv)
  83. }
  84. notkey, ok := vv["notkey"].([]string)
  85. if !ok {
  86. inter_vv, _ := vv["notkey"].([]interface{})
  87. notkey = common.ObjArrToStringArr(inter_vv)
  88. }
  89. pbKey[kk] = &bxsubscribe.Keys{
  90. Key: key,
  91. Notkey: notkey,
  92. UpdateTime: common.If(vv["updatetime"] == nil, int64(0), common.Int64All(vv["updatetime"])).(int64),
  93. }
  94. }
  95. items[k].AKey = pbKey
  96. }
  97. return items
  98. }