sensitivemethodlogic.go 5.8 KB

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