sensitivemethodlogic.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. "app.yhyue.com/moapp/jybase/redis"
  7. "context"
  8. "fmt"
  9. "log"
  10. "strings"
  11. "time"
  12. "app.yhyue.com/moapp/jyInfo/rpc/common/internal/svc"
  13. "app.yhyue.com/moapp/jyInfo/rpc/common/type/common"
  14. cm "app.yhyue.com/moapp/jybase/common"
  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. //敏感词过滤后接受结果
  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 bool
  35. )
  36. log.Println("接收到敏感词回调----------------------", in)
  37. upData := make(map[string]interface{})
  38. query := make(map[string]interface{})
  39. if in.Title != nil || in.Detail != nil || in.Attachments != "" || in.AttachTxt != "" {
  40. isSensitive = true
  41. }
  42. if !isSensitive && !md.Sensitive.Information {
  43. isPublishInfo = true
  44. }
  45. if !isSensitive && !md.Sensitive.SupplyInfo {
  46. isPublishSup = true
  47. }
  48. if in.Title != nil {
  49. upData["sensitive_title"] = strings.Join(in.Title, ",")
  50. }
  51. if in.Detail != nil {
  52. upData["sensitive_detail"] = strings.Join(in.Detail, ",")
  53. }
  54. if in.Attachments != "" {
  55. upData["sensitive_attach"] = in.Attachments
  56. }
  57. if in.AttachTxt != "" {
  58. upData["discern_attach"] = in.AttachTxt
  59. }
  60. query["id"] = in.Id
  61. upData["status"] = 2
  62. switch in.MsgType {
  63. case "1", "2": //招标信息
  64. data := md.Mysql.FindOne("information", query, "", "")
  65. if data != nil && len(*data) > 0 {
  66. isDel := cm.IntAll((*data)["is_del"]) == 1
  67. //感觉没有必要
  68. if !isDel {
  69. delete(upData, "status")
  70. } else if isPublishInfo {
  71. upData["status"] = 3
  72. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  73. upData["review_desc"] = "自动审批通过"
  74. //调用发布功能
  75. nsq, err := util.NewNsqInfo(md.NsqConfig.Ip, md.NsqConfig.Topic, in.Id, "2", in.MsgType, false, *data)
  76. if err != nil || nsq.NsqPushInfo() != nil {
  77. resp.ErrCode = 1
  78. resp.ErrMsg = "发布nsq失败"
  79. break
  80. }
  81. }
  82. if !md.Mysql.Update("information", query, upData) {
  83. resp.ErrCode = 1
  84. resp.ErrMsg = "调用nsq发布信息成功,更新信息失败"
  85. }
  86. }
  87. case "3": //供应信息
  88. data := md.Mysql.FindOne("supply_info", query, "", "")
  89. if data != nil && len(*data) > 0 {
  90. isDel := cm.IntAll((*data)["is_del"]) == 1
  91. //感觉没有必要
  92. if !isDel {
  93. delete(upData, "status")
  94. } else if isPublishSup {
  95. upData["status"] = 3
  96. upData["published"] = 2
  97. upData["review_time"] = time.Now().Format("2006-01-02 15:04:05")
  98. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  99. upData["review_desc"] = "自动审批通过"
  100. //调用发布功能
  101. entNameKye := fmt.Sprintf("userEntName_%s_%s_%s", (*data)["user_id"], in.Id, in.MsgType)
  102. entName := redis.GetStr("other", entNameKye)
  103. supInfo := make(map[string]interface{})
  104. supInfo["id"] = (*data)["id"]
  105. supInfo["title"] = (*data)["title"]
  106. supInfo["detail"] = (*data)["detail"]
  107. supInfo["province"] = (*data)["province"]
  108. supInfo["city"] = (*data)["city"]
  109. if !model.SaveSupplyInfo(entName, supInfo) {
  110. resp.ErrCode = -1
  111. resp.ErrMsg = "调用SaveSupplyInfo失败,供应信息发布失败"
  112. break
  113. }
  114. }
  115. if !md.Mysql.Update("supply_info", query, upData) {
  116. resp.ErrCode = -1
  117. resp.ErrMsg = "调用信息发布成功,更新信息失败"
  118. }
  119. }
  120. default:
  121. resp.ErrCode = -2
  122. resp.ErrMsg = "信息类型错误"
  123. }
  124. return &resp, nil
  125. }