sensitivemethodlogic.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package logic
  2. import (
  3. md "app.yhyue.com/moapp/jyInfo/rpc/model"
  4. model "app.yhyue.com/moapp/jyInfo/rpc/model/es"
  5. "app.yhyue.com/moapp/jyInfo/rpc/util"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "context"
  8. "fmt"
  9. "log"
  10. "strings"
  11. "time"
  12. "app.yhyue.com/moapp/jyInfo/rpc/common/commonclient"
  13. "app.yhyue.com/moapp/jyInfo/rpc/common/internal/svc"
  14. mc "app.yhyue.com/moapp/jybase/common"
  15. "github.com/zeromicro/go-zero/core/logx"
  16. )
  17. type SensitiveMethodLogic struct {
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. logx.Logger
  21. }
  22. func NewSensitiveMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SensitiveMethodLogic {
  23. return &SensitiveMethodLogic{
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. Logger: logx.WithContext(ctx),
  27. }
  28. }
  29. //数据组rpc回调,敏感词过滤后结果
  30. func (l *SensitiveMethodLogic) SensitiveMethod(in *commonclient.SensitiveRequest) (*commonclient.SensitiveResponse, error) {
  31. var (
  32. resp commonclient.SensitiveResponse
  33. //isSensitive 是否有敏感词 isPublishInfo招标信息是否需要自动发布 isPublishSup 供应信息是否需要自动发布
  34. isSensitive, isPublishInfo, isPublishSup bool
  35. )
  36. log.Println("接收到敏感词回调----------------------", in)
  37. upData := make(map[string]interface{})
  38. query := make(map[string]interface{})
  39. if in.Title != nil || in.Detail != nil || in.Attachments != "" || in.AttachTxt != "" {
  40. isSensitive = true
  41. }
  42. if !isSensitive && !md.Sensitive.Information {
  43. isPublishInfo = true
  44. }
  45. if !isSensitive && !md.Sensitive.SupplyInfo {
  46. isPublishSup = true
  47. }
  48. if in.Title != nil {
  49. upData["sensitive_title"] = strings.Join(in.Title, ",")
  50. }
  51. if in.Detail != nil {
  52. upData["sensitive_detail"] = strings.Join(in.Detail, ",")
  53. }
  54. if in.Attachments != "" {
  55. upData["sensitive_attach"] = in.Attachments
  56. }
  57. if in.AttachTxt != "" {
  58. upData["discern_attach"] = in.AttachTxt
  59. }
  60. //当前信息是否已被删除 默认:false;删除:true
  61. isDel := false
  62. query["id"] = in.Id
  63. upData["status"] = 2
  64. switch in.MsgType {
  65. case "1", "2": //招标信息
  66. data := md.Mysql.FindOne("information", query, "", "")
  67. if data != nil && len(*data) > 0 {
  68. //是否已被删除
  69. isDel = mc.IntAll((*data)["is_del"]) == -1
  70. //未删除 且 不用人工审核 直接入消息队列 进行发布流程
  71. if !isDel && isPublishInfo {
  72. upData["status"] = 3
  73. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  74. upData["review_desc"] = "自动审批通过"
  75. //调用发布功能
  76. nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
  77. if err != nil || nsq.NsqPushInfo() != nil {
  78. resp.ErrCode = -2
  79. resp.ErrMsg = "发布信息:信息入nsq消息队列失败"
  80. //break
  81. }
  82. }
  83. //修改此信息敏感词过滤结果
  84. if !md.Mysql.Update("information", query, upData) {
  85. resp.ErrCode = -1
  86. resp.ErrMsg = resp.ErrMsg + "敏感词过滤成功,更新库数据信息失败"
  87. }
  88. }
  89. case "3": //供应信息
  90. data := md.Mysql.FindOne("supply_info", query, "", "")
  91. if data != nil && len(*data) > 0 {
  92. //是否已被删除
  93. isDel = mc.IntAll((*data)["is_del"]) == -1
  94. //信息未被删除 且 不用人工审核 直接进入es 发布信息
  95. if !isDel && isPublishSup {
  96. upData["status"] = 3
  97. upData["published"] = 2
  98. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  99. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  100. upData["review_desc"] = "自动审批通过"
  101. //调用发布功能
  102. entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
  103. entName := redis.GetStr("other", entNameKye)
  104. supInfo := make(map[string]interface{})
  105. supInfo["id"] = (*data)["id"]
  106. supInfo["title"] = (*data)["title"]
  107. supInfo["detail"] = (*data)["detail"]
  108. supInfo["province"] = (*data)["province"]
  109. supInfo["city"] = (*data)["city"]
  110. if !model.SaveSupplyInfo(entName, supInfo) {
  111. resp.ErrCode = -3
  112. resp.ErrMsg = "供应信息: 调用SaveSupplyInfo 信息发布失败"
  113. }
  114. }
  115. if !md.Mysql.Update("supply_info", query, upData) {
  116. resp.ErrCode = -1
  117. resp.ErrMsg = resp.ErrMsg + "供应信息:敏感词过滤成功,更新库信息状态失败"
  118. }
  119. }
  120. default:
  121. resp.ErrCode = -1
  122. resp.ErrMsg = "信息类型错误"
  123. }
  124. return &resp, nil
  125. }