subscribeupdatelogic.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. it "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/init"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/svc"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/types"
  7. . "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/entity"
  8. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/bxsubscribe"
  9. "context"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. "log"
  14. "time"
  15. )
  16. type SubscribeUpdateLogic struct {
  17. logx.Logger
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. }
  21. func NewSubscribeUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubscribeUpdateLogic {
  22. return &SubscribeUpdateLogic{
  23. Logger: logx.WithContext(ctx),
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. }
  27. }
  28. func (l *SubscribeUpdateLogic) SubscribeUpdate(req *types.SubscribeUpdateReq) (resp *types.CommonResp, err error) {
  29. resp = &types.CommonResp{}
  30. if req.UserId == "" {
  31. return
  32. } else if KeyWordsRepeat(req.MgoUserId, req.Items) {
  33. resp.Data = map[string]interface{}{
  34. "status": -1,
  35. }
  36. resp.Err_code, resp.Err_msg = -1, "关键词设置异常"
  37. return
  38. }
  39. su := &SubscribeUpdate{
  40. Area: req.Area,
  41. Buyerclass: req.Buyerclass,
  42. Items: req.Items,
  43. Infotype: req.Infotype,
  44. Matchway: req.Matchway,
  45. Projectmatch: req.Projectmatch,
  46. Ratemode: req.Ratemode,
  47. Apppush: req.Apppush,
  48. Mailpush: req.Mailpush,
  49. Mail: req.Mail,
  50. Otherbuyerclass: req.Otherbuyerclass,
  51. District: req.District,
  52. Amount: req.Amount,
  53. ISwitch: req.ISwitch,
  54. Matchmode: req.Matchmode,
  55. }
  56. fmt.Println("###")
  57. b, _ := json.Marshal(su)
  58. rp, err := l.svcCtx.Suscribe.UpdateSubScribeInfo(l.ctx, &bxsubscribe.UpdateSubScribeInfoReq{
  59. UserId: req.UserId,
  60. PositionType: req.PositionType,
  61. SubSet: b,
  62. BaseUserId: req.NewUserId,
  63. PositionId: req.PositionId,
  64. UserType: req.UserType,
  65. MgoUserId: req.MgoUserId,
  66. })
  67. if err != nil {
  68. resp.Err_code, resp.Err_msg = -1, "修改失败"
  69. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  70. } else {
  71. saveData := map[string]interface{}{
  72. "userid": req.UserId,
  73. "o_vipjy": req,
  74. "createtime": time.Now().Unix(),
  75. "type": "o_vipjy",
  76. }
  77. go it.SubscribeUpdateLog.SendLogs(saveData)
  78. resp.Data = map[string]interface{}{
  79. "status": rp.Status,
  80. }
  81. }
  82. return
  83. }
  84. // 判断关键词是否异常,
  85. func KeyWordsRepeat(mgoUserId string, aitems []map[string]interface{}) bool {
  86. m := map[string]bool{} //去重的数组
  87. // 录入的关键词
  88. i := 0
  89. for _, items := range aitems {
  90. for kk, vv := range items {
  91. if kk == "a_key" {
  92. for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
  93. db_not := []string{}
  94. db_key := []string{}
  95. db_append := []string{}
  96. matchway := 0
  97. if n["key"] != nil {
  98. db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
  99. }
  100. if n["notkey"] != nil {
  101. db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
  102. }
  103. if n["appendkey"] != nil {
  104. db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
  105. }
  106. if n["matchway"] != nil {
  107. matchway = common.IntAll(n["matchway"])
  108. if mn, ok := n["matchway"].(json.Number); matchway == 0 && ok {
  109. mi, _ := mn.Int64()
  110. matchway = int(mi)
  111. }
  112. }
  113. key := fmt.Sprintf("%v%v%v%d", db_key, db_append, db_not, matchway)
  114. if m[key] {
  115. log.Println(mgoUserId, "--关键词有重复的--", key)
  116. return true //有重复 不可以提交
  117. }
  118. i++
  119. m[key] = true
  120. }
  121. }
  122. }
  123. }
  124. if i > 300 {
  125. //关键词大于300异常
  126. log.Println(mgoUserId, "--关键词数据大于300组--")
  127. return true
  128. }
  129. return false
  130. }