infoonekeyactionlogic.go 5.0 KB

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