sensitivemethodlogic.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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["status"]) != "200" {
  45. isAttach = true
  46. msg = append(msg, "附件校验敏感词失败")
  47. } else if s, ok := vs["sensitive"]; ok && s != nil && len(s.([]string)) > 0 {
  48. isAttach = true
  49. msg, _ = vs["sensitive"].([]string)
  50. }
  51. sensitiveAttach[k] = strings.Join(msg, ",")
  52. }
  53. if in.Title != nil || in.Detail != nil || isAttach {
  54. isSensitive = true
  55. }
  56. if !isSensitive && !md.Sensitive.Information {
  57. isPublishInfo = true
  58. }
  59. if !isSensitive && !md.Sensitive.SupplyInfo {
  60. isPublishSup = true
  61. }
  62. if in.Title != nil {
  63. upData["sensitive_title"] = strings.Join(in.Title, ",")
  64. }
  65. if in.Detail != nil {
  66. upData["sensitive_detail"] = strings.Join(in.Detail, ",")
  67. }
  68. if isAttach {
  69. upData["sensitive_attach"] = mc.MapToJson(sensitiveAttach)
  70. }
  71. if in.AttachTxt != "" && in.MsgType != "3" {
  72. upData["discern_attach"] = in.AttachTxt
  73. }
  74. log.Println("敏感词回调参数in:", in)
  75. query["id"] = in.Id
  76. upData["status"] = 2
  77. switch in.MsgType {
  78. case "1", "2": //招标信息
  79. data := md.Mysql.FindOne("information", query, "", "")
  80. if data != nil && len(*data) > 0 {
  81. isDel := cm.IntAll((*data)["is_del"]) == 1
  82. //感觉没有必要
  83. if !isDel {
  84. delete(upData, "status")
  85. } else if isPublishInfo {
  86. upData["status"] = 3
  87. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  88. upData["review_desc"] = "自动审批通过"
  89. //调用发布功能
  90. nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
  91. if err != nil || nsq.NsqPushInfo() != nil {
  92. resp.ErrCode = 1
  93. resp.ErrMsg = "发布nsq失败"
  94. break
  95. }
  96. }
  97. if !md.Mysql.Update("information", query, upData) {
  98. log.Println("调用信息发布成功,更新信息失败", query, upData)
  99. resp.ErrCode = 1
  100. resp.ErrMsg = "调用nsq发布信息成功,更新信息失败"
  101. }
  102. }
  103. case "3": //供应信息
  104. data := md.Mysql.FindOne("supply_info", query, "", "")
  105. if data != nil && len(*data) > 0 {
  106. isDel := cm.IntAll((*data)["is_del"]) == 1
  107. //感觉没有必要
  108. if !isDel {
  109. delete(upData, "status")
  110. } else if isPublishSup {
  111. upData["status"] = 3
  112. upData["published"] = 2
  113. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  114. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  115. upData["review_desc"] = "自动审批通过"
  116. //调用发布功能
  117. entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
  118. entName := redis.GetStr("other", entNameKye)
  119. supInfo := make(map[string]interface{})
  120. supInfo["id"] = (*data)["id"]
  121. supInfo["title"] = (*data)["title"]
  122. supInfo["detail"] = (*data)["detail"]
  123. supInfo["province"] = (*data)["province"]
  124. supInfo["city"] = (*data)["city"]
  125. if !model.SaveSupplyInfo(entName, supInfo) {
  126. log.Println("调用信息发布成功,更新信息失败", entName, supInfo)
  127. resp.ErrCode = 1
  128. resp.ErrMsg = "调用SaveSupplyInfo失败,供应信息发布失败"
  129. break
  130. }
  131. }
  132. if !md.Mysql.Update("supply_info", query, upData) {
  133. log.Println("调用信息发布成功,更新信息失败", query, upData)
  134. resp.ErrCode = 1
  135. resp.ErrMsg = "调用信息发布成功,更新信息失败"
  136. }
  137. }
  138. default:
  139. resp.ErrCode = 1
  140. resp.ErrMsg = "信息类型错误"
  141. }
  142. return &resp, nil
  143. }