sensitivemethodlogic.go 3.9 KB

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