sensitivemethodlogic.go 5.3 KB

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