infoonekeyactionlogic.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. entName := in.EntName
  73. if res["ent_name"] != nil && mc.InterfaceToStr(res["ent_name"]) != "" {
  74. entName = mc.InterfaceToStr(res["ent_name"])
  75. }
  76. supInfo := make(map[string]interface{})
  77. supInfo["id"] = msgId
  78. supInfo["title"] = res["title"]
  79. supInfo["detail"] = res["detail"]
  80. supInfo["province"] = res["province"]
  81. supInfo["city"] = res["city"]
  82. supInfo["ent_id"] = res["ent_id"]
  83. validityTime := time.Now().Unix()
  84. if res["validity_time"] != nil && res["validity_time"] != "" {
  85. validity, _ := time.ParseInLocation("2006-01-02 15:04:05", mc.InterfaceToStr(res["validity_time"]), time.Local)
  86. validityTime = validity.Unix()
  87. }
  88. supInfo["validity_time"] = validityTime
  89. if ok := es.SaveSupplyInfo(entName, supInfo); ok {
  90. if !model.Mysql.Update(tname, query, map[string]interface{}{
  91. "published": 1,
  92. "is_del": 1,
  93. }) {
  94. resp.ErrCode = -1
  95. resp.ErrMsg = "更新信息失败-"
  96. }
  97. break
  98. }
  99. resp.ErrCode = -1
  100. resp.ErrMsg = resp.ErrMsg + "信息发布调用失败"
  101. case "1", "2", "4", "5", "6": //招标信息,采购信息
  102. //nsq发布信息
  103. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "2", mc.InterfaceToStr(in.MsgType), false, res)
  104. if err != nil || nsq.NsqPushInfo() != nil {
  105. resp.ErrCode = -1
  106. resp.ErrMsg = "调用nsq失败"
  107. }
  108. if !model.Mysql.Update(tname, query, map[string]interface{}{
  109. "status": 4,
  110. "review_time": time.Now().Format("2006-01-02 15:04:05"),
  111. }) {
  112. resp.ErrCode = -1
  113. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  114. }
  115. }
  116. case 3: //一键删除
  117. query := map[string]interface{}{
  118. "id": msgId,
  119. "app_id": in.AppId,
  120. }
  121. if data := model.Mysql.FindOne(tname, query, "", ""); data != nil && len(*data) > 0 {
  122. update := map[string]interface{}{"is_del": -1}
  123. if !model.Mysql.Update(tname, query, update) {
  124. resp.ErrCode = -1
  125. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  126. }
  127. }
  128. switch in.MsgType {
  129. case "3": //删除供应信息索引
  130. if mc.IntAll(res["published"]) == 2 {
  131. if !es.DelSupplyInfo(mc.InterfaceToStr(msgId)) {
  132. resp.ErrCode = -1
  133. resp.ErrMsg = "es删除供应信息失败"
  134. }
  135. }
  136. case "1", "2", "4", "5", "6": //删除 招标信息,采购信息 索引
  137. if mc.IntAll(res["published"]) == 2 {
  138. //如果是已经正常发布的信息 同步调用nsq删除
  139. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "3", in.MsgType, false, res)
  140. if err != nil || nsq.NsqPushInfo() != nil {
  141. resp.ErrCode = -1
  142. resp.ErrMsg = "nsq回调删除,同步删除信息失败"
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. return resp, nil
  150. }