getsubscribeinfologic.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/model"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc"
  7. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/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. data := &map[string]interface{}{}
  27. items, ok := (*data)["items"].([]map[string]interface{})
  28. if !ok {
  29. inter_items, _ := (*data)["items"].([]interface{})
  30. items = common.ObjArrToMapArr(inter_items)
  31. }
  32. buyerclass, _ := (*data)["buyerclass"].([]interface{})
  33. infotype, _ := (*data)["infotype"].([]interface{})
  34. keytip := false
  35. if in.Types == model.MemberFlag && in.PositionType == 0 {
  36. keytip = (*data)["b_keytip"].(bool)
  37. }
  38. return &bxsubscribe.UserResq{
  39. ErrorCode: 0,
  40. ErrorMsg: "",
  41. Data: &bxsubscribe.Subscribe{
  42. Area: l.formatM(common.ObjToMap((*data)["area"])),
  43. Buyerclass: common.ObjArrToStringArr(buyerclass),
  44. Infotype: common.ObjArrToStringArr(infotype),
  45. Matchway: common.Int64All((*data)["matchway"]),
  46. Projectmatch: common.Int64All((*data)["projectmatch"]),
  47. Items: l.formatItems(items),
  48. Keytip: keytip,
  49. },
  50. }, nil
  51. }
  52. //格式转化 map<string,list>转化
  53. func (l *GetSubScribeInfoLogic) formatM(m *map[string]interface{}) map[string]*bxsubscribe.List {
  54. retM := map[string]*bxsubscribe.List{}
  55. if len(*m) == 0 {
  56. return retM
  57. }
  58. for k, v := range *m {
  59. s_v, ok := v.([]string)
  60. if !ok {
  61. interf, _ := v.([]interface{})
  62. s_v = common.ObjArrToStringArr(interf)
  63. }
  64. retM[k] = &bxsubscribe.List{
  65. Value: s_v,
  66. }
  67. }
  68. return retM
  69. }
  70. func (l *GetSubScribeInfoLogic) formatItems(m []map[string]interface{}) []*bxsubscribe.Items {
  71. items := make([]*bxsubscribe.Items, len(m))
  72. for k, v := range m {
  73. items[k] = &bxsubscribe.Items{
  74. SItem: common.ObjToString(v["s_item"]),
  75. UpdateTime: common.Int64All(v["updatetime"]),
  76. }
  77. akey, _ := v["a_key"].([]map[string]interface{})
  78. pbKey := make([]*bxsubscribe.Keys, len(akey))
  79. for kk, vv := range akey {
  80. key, ok := vv["key"].([]string)
  81. if !ok {
  82. inter_vv, _ := vv["key"].([]interface{})
  83. key = common.ObjArrToStringArr(inter_vv)
  84. }
  85. notkey, ok := vv["notkey"].([]string)
  86. if !ok {
  87. inter_vv, _ := vv["notkey"].([]interface{})
  88. notkey = common.ObjArrToStringArr(inter_vv)
  89. }
  90. pbKey[kk] = &bxsubscribe.Keys{
  91. Key: key,
  92. Notkey: notkey,
  93. UpdateTime: common.If(vv["updatetime"] == nil, int64(0), common.Int64All(vv["updatetime"])).(int64),
  94. }
  95. }
  96. items[k].AKey = pbKey
  97. }
  98. return items
  99. }