sensitivemethodlogic.go 3.8 KB

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