infoonekeyactionlogic.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. "app.yhyue.com/moapp/jyInfo/rpc/util"
  8. mc "app.yhyue.com/moapp/jybase/common"
  9. se "app.yhyue.com/moapp/jybase/encrypt"
  10. "context"
  11. "fmt"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type InfoOneKeyActionLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewInfoOneKeyActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoOneKeyActionLogic {
  20. return &InfoOneKeyActionLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. // 管理后台一键操作 1:管理后台一键敏感词过滤;2:管理后台一键发布;3管理后台一键删除;
  27. func (l *InfoOneKeyActionLogic) InfoOneKeyAction(in *manager.OneKeyActionReq) (*manager.InfoResp, error) {
  28. var resp = &manager.InfoResp{}
  29. if in.UserId != "" && MI.MUserIdMap[in.UserId] {
  30. msgId := se.SE.DecodeString(in.MsgId)
  31. var tname = mc.If(in.MsgType == "3", "supply_info", "information")
  32. data := model.Mysql.SelectBySql(`SELECT a.title,a.detail,a.attach FROM ? a WHERE a.id = ? AND a.type = ?`, tname, msgId, in.MsgType)
  33. if len(*data) > 0 {
  34. res := (*data)[0]
  35. switch in.Type {
  36. case 1: //一键敏感词过滤
  37. appendInfo := make(map[string]interface{})
  38. if res["title"] != nil {
  39. appendInfo["title"] = mc.InterfaceToStr(res["title"])
  40. }
  41. if res["detail"] != nil {
  42. appendInfo["detail"] = mc.InterfaceToStr(res["detail"])
  43. }
  44. if res["attach"] != nil && mc.InterfaceToStr(res["attach"]) != "{}" {
  45. appendInfo["attach"] = mc.StringToMap(mc.InterfaceToStr(res["attach"]))
  46. }
  47. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
  48. if err != nil || nsq.NsqPushInfo() != nil {
  49. resp.ErrCode = -1
  50. resp.ErrMsg = fmt.Sprintf("nsq 发布异常:%s", res["id"])
  51. logx.Info(resp.ErrMsg)
  52. }
  53. case 2: //一键信息发布
  54. switch in.MsgType {
  55. case "3": //供应信息
  56. case "1", "2": //招标信息,采购信息
  57. //nsq发布信息
  58. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "2", mc.InterfaceToStr(in.MsgType), false, res)
  59. if err != nil || nsq.NsqPushInfo() != nil {
  60. resp.ErrCode = -1
  61. resp.ErrMsg = "调用nsq失败"
  62. }
  63. if model.Mysql.UpdateOrDeleteBySql(``) < 1 {
  64. resp.ErrCode = -1
  65. resp.ErrMsg = resp.ErrMsg + "更新信息失败"
  66. }
  67. }
  68. }
  69. }
  70. }
  71. return resp, nil
  72. }