bypushhistorylogic.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. IC "jyBXSubscribe/rpc/init"
  6. "jyBXSubscribe/rpc/internal/svc"
  7. "jyBXSubscribe/rpc/model"
  8. "jyBXSubscribe/rpc/type/bxsubscribe"
  9. "jyBXSubscribe/rpc/util"
  10. "strings"
  11. "time"
  12. )
  13. type ByPushHistoryLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewByPushHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ByPushHistoryLogic {
  19. return &ByPushHistoryLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 推送页面筛选导出
  26. func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*bxsubscribe.ByPushHistoryResp, error) {
  27. // todo: add your logic here and delete this line
  28. vipType := in.UserType
  29. spqp := &model.SubPushQueryParam{
  30. Mgo_bidding: IC.MgoBidding, //mongo
  31. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  32. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  33. UserId: in.UserId, //用户id
  34. PageNum: 1, //当前页码
  35. PageSize: 20000,
  36. Export: true,
  37. SelectTime: in.SelectTime, //时间跨度
  38. Area: in.Area, //省份
  39. City: in.City, //城市
  40. Buyerclass: in.BuyerClass, //采购单位类型
  41. Subtype: in.Subtype, //信息类型
  42. Subscopeclass: in.Industry, //行业
  43. Key: in.KeyWords, //关键词
  44. Price: in.Price, //价格区间
  45. FileExists: in.FileExists, //是否有附件
  46. }
  47. if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
  48. //encodeArr := strings.Split(selectIds, ",")
  49. //idArr := make([]string, 0, len(encodeArr))
  50. //for _, encodeId := range encodeArr {
  51. // if tmp := util.DecodeId(encodeId); tmp != "" {
  52. // idArr = append(idArr, tmp)
  53. // }
  54. //}
  55. spqp.SelectInfoIds = strings.Split(selectIds, ",")
  56. }
  57. _, _, list := model.NewSubscribePush(vipType).Datas(spqp)
  58. if list == nil || len(list) == 0 {
  59. return &bxsubscribe.ByPushHistoryResp{
  60. ErrorCode: 1,
  61. ErrorMsg: "未查询到数据",
  62. }, nil
  63. }
  64. ids := make([]string, 0, len(list))
  65. keyWords := make([]string, 0, len(list))
  66. for _, pushData := range list {
  67. if pushData.XId != "" {
  68. if xid := util.EncodeId(pushData.XId); len(xid) > 0 {
  69. ids = append(ids, xid)
  70. keyWords = append(keyWords, strings.Join(pushData.MatchKeys, ","))
  71. }
  72. }
  73. }
  74. saveData := map[string]interface{}{
  75. "s_userid": in.UserId,
  76. "comeinfrom": "pushHistory",
  77. "comeintime": time.Now().Unix(),
  78. "selectIds": ids,
  79. "pushKeyWords": keyWords,
  80. }
  81. _id := IC.Mgo.Save("export_search", saveData)
  82. if _id == "" {
  83. return &bxsubscribe.ByPushHistoryResp{
  84. ErrorCode: 1,
  85. ErrorMsg: "创建导出异常",
  86. }, nil
  87. }
  88. return &bxsubscribe.ByPushHistoryResp{
  89. Data: util.EncodeId(_id),
  90. }, nil
  91. }