sensitivemethodlogic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/internal/svc"
  14. "app.yhyue.com/moapp/jyInfo/rpc/common/type/common"
  15. cm "app.yhyue.com/moapp/jybase/common"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. )
  18. type SensitiveMethodLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewSensitiveMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SensitiveMethodLogic {
  24. return &SensitiveMethodLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. func (l *SensitiveMethodLogic) SensitiveMethod(in *common.SensitiveRequest) (*common.SensitiveResponse, error) {
  31. var (
  32. resp common.SensitiveResponse
  33. //isSensitive 是否有敏感词 isPublishInfo招标信息是否需要自动发布 isPublishSup 供应信息是否需要自动发布
  34. isSensitive, isPublishInfo, isPublishSup, isAttach bool
  35. )
  36. log.Println("")
  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"]) == "300" {
  49. msg = append(msg, "敏感词校验附件解析错误")
  50. } else {
  51. msg = append(msg, "附件校验敏感词失败")
  52. }
  53. } else if s, ok := vs["sensitive"]; ok && s != nil && len(s.([]string)) > 0 {
  54. isAttach = true
  55. msg, _ = vs["sensitive"].([]string)
  56. }
  57. sensitiveAttach[k] = strings.Join(msg, ",")
  58. }
  59. if in.Title != nil || in.Detail != nil || isAttach {
  60. isSensitive = true
  61. }
  62. if !isSensitive && !md.Sensitive.Information {
  63. isPublishInfo = true
  64. }
  65. if !isSensitive && !md.Sensitive.SupplyInfo {
  66. isPublishSup = true
  67. }
  68. if in.Title != nil {
  69. upData["sensitive_title"] = strings.Join(in.Title, ",")
  70. }
  71. if in.Detail != nil {
  72. upData["sensitive_detail"] = strings.Join(in.Detail, ",")
  73. }
  74. if isAttach {
  75. upData["sensitive_attach"] = mc.MapToJson(sensitiveAttach)
  76. }
  77. if in.AttachTxt != "" && in.MsgType != "3" {
  78. upData["discern_attach"] = in.AttachTxt
  79. }
  80. log.Println("敏感词回调参数in:", in)
  81. query["id"] = in.Id
  82. upData["status"] = 2
  83. switch in.MsgType {
  84. case "1", "2": //招标信息
  85. data := md.Mysql.FindOne("information", query, "", "")
  86. if data != nil && len(*data) > 0 {
  87. isDel := cm.IntAll((*data)["is_del"]) == 1
  88. //感觉没有必要
  89. if !isDel {
  90. delete(upData, "status")
  91. } else if isPublishInfo {
  92. upData["status"] = 3
  93. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  94. upData["review_desc"] = "自动审批通过"
  95. //调用发布功能
  96. nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
  97. if err != nil || nsq.NsqPushInfo() != nil {
  98. resp.ErrCode = 1
  99. resp.ErrMsg = "发布nsq失败"
  100. break
  101. }
  102. }
  103. if !md.Mysql.Update("information", query, upData) {
  104. log.Println("调用信息发布成功,更新信息失败", query, upData)
  105. resp.ErrCode = 1
  106. resp.ErrMsg = "调用nsq发布信息成功,更新信息失败"
  107. }
  108. }
  109. case "3": //供应信息
  110. data := md.Mysql.FindOne("supply_info", query, "", "")
  111. if data != nil && len(*data) > 0 {
  112. isDel := cm.IntAll((*data)["is_del"]) == 1
  113. //感觉没有必要
  114. if !isDel {
  115. delete(upData, "status")
  116. } else if isPublishSup {
  117. upData["status"] = 3
  118. upData["published"] = 2
  119. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  120. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  121. upData["review_desc"] = "自动审批通过"
  122. //调用发布功能
  123. entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
  124. entName := redis.GetStr("other", entNameKye)
  125. supInfo := make(map[string]interface{})
  126. supInfo["id"] = (*data)["id"]
  127. supInfo["title"] = (*data)["title"]
  128. supInfo["detail"] = (*data)["detail"]
  129. supInfo["province"] = (*data)["province"]
  130. supInfo["city"] = (*data)["city"]
  131. if !model.SaveSupplyInfo(entName, supInfo) {
  132. log.Println("调用信息发布成功,更新信息失败", entName, supInfo)
  133. resp.ErrCode = 1
  134. resp.ErrMsg = "调用SaveSupplyInfo失败,供应信息发布失败"
  135. break
  136. }
  137. }
  138. if !md.Mysql.Update("supply_info", query, upData) {
  139. log.Println("调用信息发布成功,更新信息失败", query, upData)
  140. resp.ErrCode = 1
  141. resp.ErrMsg = "调用信息发布成功,更新信息失败"
  142. }
  143. }
  144. default:
  145. resp.ErrCode = 1
  146. resp.ErrMsg = "信息类型错误"
  147. }
  148. return &resp, nil
  149. }