subscribeupdatelogic.go 3.6 KB

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