sensitivemethodlogic.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. mc "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/redis"
  8. "context"
  9. "fmt"
  10. "log"
  11. "strings"
  12. "time"
  13. "app.yhyue.com/moapp/jyInfo/rpc/common/commoninfo"
  14. "app.yhyue.com/moapp/jyInfo/rpc/common/internal/svc"
  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 *commoninfo.SensitiveRequest) (*commoninfo.SensitiveResponse, error) {
  31. var (
  32. resp commoninfo.SensitiveResponse
  33. //isSensitive 是否有敏感词 isPublishInfo招标信息是否需要自动发布 isPublishSup 供应信息是否需要自动发布
  34. isSensitive, isPublishInfo, isPublishSup, isAttach bool
  35. )
  36. log.Println("接收到敏感词回调----------------------", in)
  37. upData := make(map[string]interface{})
  38. query := make(map[string]interface{})
  39. attachments := make(map[string]interface{})
  40. if in.Attachments != "" {
  41. attachments = mc.StringToMap(in.Attachments)
  42. }
  43. sensitiveAttach := make(map[string]interface{})
  44. for k, v := range attachments {
  45. vs := mc.StructToMapMore(v)
  46. var msg []string
  47. if mc.InterfaceToStr(vs["state"]) != "200" {
  48. isAttach = true
  49. if mc.InterfaceToStr(vs["state"]) == "300" {
  50. msg = append(msg, "敏感词校验附件下载错误")
  51. } else if mc.InterfaceToStr(vs["state"]) == "400" {
  52. msg = append(msg, "敏感词校验附件解析错误")
  53. } else {
  54. msg = append(msg, "敏感词识别失败")
  55. }
  56. } else if s, ok := vs["sensitive"]; ok && s != nil && len(s.([]interface{})) > 0 {
  57. msg = mc.ObjArrToStringArr(vs["sensitive"].([]interface{}))
  58. }
  59. msgStr := strings.Join(msg, ",")
  60. if msgStr != "" {
  61. isAttach = true
  62. log.Println("附件敏感词:", msgStr)
  63. }
  64. sensitiveAttach[k] = msgStr
  65. }
  66. if in.Title != nil || in.Detail != nil || isAttach {
  67. isSensitive = true
  68. }
  69. if !isSensitive && !md.Sensitive.Information {
  70. isPublishInfo = true
  71. }
  72. if !isSensitive && !md.Sensitive.SupplyInfo {
  73. isPublishSup = true
  74. }
  75. if in.Title != nil {
  76. upData["sensitive_title"] = strings.Join(in.Title, ",")
  77. }
  78. if in.Detail != nil {
  79. upData["sensitive_detail"] = strings.Join(in.Detail, ",")
  80. }
  81. if isAttach {
  82. upData["sensitive_attach"] = mc.MapToJson(sensitiveAttach)
  83. }
  84. if in.AttachTxt != "" && in.MsgType != "3" {
  85. upData["discern_attach"] = in.AttachTxt
  86. }
  87. //当前信息是否已被删除 默认:false;删除:true
  88. isDel := false
  89. query["id"] = in.Id
  90. upData["status"] = 2
  91. switch in.MsgType {
  92. case "1", "2": //招标信息
  93. data := md.Mysql.FindOne("information", query, "", "")
  94. if data != nil && len(*data) > 0 {
  95. //是否已被删除
  96. isDel = mc.IntAll((*data)["is_del"]) == -1
  97. //未删除 且 不用人工审核 直接入消息队列 进行发布流程
  98. if !isDel && isPublishInfo {
  99. upData["status"] = 3
  100. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  101. upData["review_desc"] = "自动审批通过"
  102. //调用发布功能
  103. nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
  104. if err != nil || nsq.NsqPushInfo() != nil {
  105. resp.ErrCode = -2
  106. resp.ErrMsg = "发布信息:信息入nsq消息队列失败"
  107. //break
  108. }
  109. }
  110. //修改此信息敏感词过滤结果
  111. if !md.Mysql.Update("information", query, upData) {
  112. log.Println("调用信息发布成功,更新信息失败", query, upData)
  113. resp.ErrCode = -1
  114. resp.ErrMsg = resp.ErrMsg + "敏感词过滤成功,更新库数据信息失败"
  115. }
  116. }
  117. case "3": //供应信息
  118. data := md.Mysql.FindOne("supply_info", query, "", "")
  119. if data != nil && len(*data) > 0 {
  120. //是否已被删除
  121. isDel = mc.IntAll((*data)["is_del"]) == -1
  122. //信息未被删除 且 不用人工审核 直接进入es 发布信息
  123. if !isDel && isPublishSup {
  124. upData["status"] = 3
  125. upData["published"] = 2
  126. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  127. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  128. upData["review_desc"] = "自动审批通过"
  129. //调用发布功能
  130. entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
  131. entName := redis.GetStr("other", entNameKye)
  132. supInfo := make(map[string]interface{})
  133. supInfo["id"] = (*data)["id"]
  134. supInfo["title"] = (*data)["title"]
  135. supInfo["detail"] = (*data)["detail"]
  136. supInfo["province"] = (*data)["province"]
  137. supInfo["city"] = (*data)["city"]
  138. if !model.SaveSupplyInfo(entName, supInfo) {
  139. log.Println("调用信息发布成功,更新信息失败", entName, supInfo)
  140. resp.ErrCode = -3
  141. resp.ErrMsg = "供应信息: 调用SaveSupplyInfo 信息发布失败"
  142. }
  143. }
  144. if !md.Mysql.Update("supply_info", query, upData) {
  145. log.Println("调用信息发布成功,更新信息失败", query, upData)
  146. resp.ErrCode = -1
  147. resp.ErrMsg = resp.ErrMsg + "供应信息:敏感词过滤成功,更新库信息状态失败"
  148. }
  149. }
  150. default:
  151. resp.ErrCode = -1
  152. resp.ErrMsg = "信息类型错误"
  153. }
  154. return &resp, nil
  155. }