infoonekeyactionlogic.go 4.8 KB

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