infoonekeyactionlogic.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package logic
  2. import (
  3. MI "app.yhyue.com/moapp/jyInfo/rpc/manager/init"
  4. "app.yhyue.com/moapp/jyInfo/rpc/manager/internal/svc"
  5. "app.yhyue.com/moapp/jyInfo/rpc/manager/type/manager"
  6. "app.yhyue.com/moapp/jyInfo/rpc/model"
  7. es "app.yhyue.com/moapp/jyInfo/rpc/model/es"
  8. "app.yhyue.com/moapp/jyInfo/rpc/util"
  9. mc "app.yhyue.com/moapp/jybase/common"
  10. se "app.yhyue.com/moapp/jybase/encrypt"
  11. "app.yhyue.com/moapp/jybase/redis"
  12. "context"
  13. "fmt"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. "log"
  16. "time"
  17. )
  18. type InfoOneKeyActionLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewInfoOneKeyActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoOneKeyActionLogic {
  24. return &InfoOneKeyActionLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. // 管理后台一键操作 1:管理后台一键敏感词过滤;2:管理后台一键发布;3管理后台一键删除;
  31. func (l *InfoOneKeyActionLogic) InfoOneKeyAction(in *manager.OneKeyActionReq) (*manager.InfoResp, error) {
  32. var resp = &manager.InfoResp{}
  33. if in.UserId != "" && MI.MUserIdMap[in.UserId] {
  34. msgId := se.SE.DecodeString(in.MsgId)
  35. var tname = mc.If(in.MsgType == "3", "supply_info", "information").(string)
  36. data := model.Mysql.SelectBySql(fmt.Sprintf(`SELECT title,detail,attach FROM %s WHERE id = ? AND type = ?`, tname), msgId, in.MsgType)
  37. log.Println("---:", *data)
  38. if len(*data) > 0 {
  39. res := (*data)[0]
  40. switch in.Type {
  41. case 1: //一键敏感词过滤
  42. appendInfo := make(map[string]interface{})
  43. if res["title"] != nil {
  44. appendInfo["title"] = mc.InterfaceToStr(res["title"])
  45. }
  46. if res["detail"] != nil {
  47. appendInfo["detail"] = mc.InterfaceToStr(res["detail"])
  48. }
  49. if res["attach"] != nil && mc.InterfaceToStr(res["attach"]) != "{}" {
  50. appendInfo["attach"] = mc.StringToMap(mc.InterfaceToStr(res["attach"]))
  51. }
  52. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
  53. if err != nil || nsq.NsqPushInfo() != nil {
  54. resp.ErrCode = -1
  55. resp.ErrMsg = fmt.Sprintf("nsq 发布异常:%s", res["id"])
  56. logx.Info(resp.ErrMsg)
  57. }
  58. case 2: //一键信息发布
  59. query := map[string]interface{}{
  60. "id": msgId,
  61. "app_id": in.AppId,
  62. }
  63. switch in.MsgType {
  64. case "3": //供应信息生成索引
  65. upData := make(map[string]interface{})
  66. upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
  67. upData["published"] = 2
  68. entNameKye := fmt.Sprintf("userEntName_%s_%s_%d", mc.InterfaceToStr(res["user_id"]), in.MsgId, in.MsgType)
  69. entName := redis.GetStr("other", entNameKye)
  70. supInfo := make(map[string]interface{})
  71. supInfo["id"] = msgId
  72. supInfo["title"] = res["title"]
  73. supInfo["detail"] = res["detail"]
  74. supInfo["province"] = res["province"]
  75. supInfo["city"] = res["city"]
  76. if !es.SaveSupplyInfo(entName, supInfo) {
  77. resp.ErrCode = -1
  78. resp.ErrMsg = "信息发布调用失败"
  79. }
  80. if !model.Mysql.Update(tname, query, map[string]interface{}{
  81. "publish_time": time.Now().Format("2006-01-02 15:04:05"),
  82. "published": 2,
  83. }) {
  84. resp.ErrCode = -1
  85. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  86. }
  87. case "1", "2": //招标信息,采购信息
  88. //nsq发布信息
  89. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "2", mc.InterfaceToStr(in.MsgType), false, res)
  90. if err != nil || nsq.NsqPushInfo() != nil {
  91. resp.ErrCode = -1
  92. resp.ErrMsg = "调用nsq失败"
  93. }
  94. if !model.Mysql.Update(tname, query, map[string]interface{}{
  95. "status": 4,
  96. }) {
  97. resp.ErrCode = -1
  98. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  99. }
  100. }
  101. case 3: //一键删除
  102. query := map[string]interface{}{
  103. "id": msgId,
  104. "app_id": in.AppId,
  105. }
  106. if data := model.Mysql.FindOne(tname, query, "", ""); data != nil && len(*data) > 0 {
  107. update := map[string]interface{}{"is_del": -1}
  108. if !model.Mysql.Update(tname, query, update) {
  109. resp.ErrCode = -1
  110. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  111. }
  112. }
  113. switch in.MsgType {
  114. case "3": //删除供应信息索引
  115. if mc.IntAll(res["published"]) == 2 {
  116. if !es.DelSupplyInfo(mc.InterfaceToStr(msgId)) {
  117. resp.ErrCode = -1
  118. resp.ErrMsg = "es删除供应信息失败"
  119. }
  120. }
  121. case "1", "2": //删除 招标信息,采购信息 索引
  122. if mc.IntAll(res["published"]) == 2 {
  123. //如果是已经正常发布的信息 同步调用nsq删除
  124. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "3", in.MsgType, false, res)
  125. if err != nil || nsq.NsqPushInfo() != nil {
  126. resp.ErrCode = -1
  127. resp.ErrMsg = "nsq回调删除,同步删除信息失败"
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. return resp, nil
  135. }