bypushhistorylogic.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. SelectTime: in.SelectTime, //时间跨度
  37. Area: in.Area, //省份
  38. City: in.City, //城市
  39. Export: true,
  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. EntId: in.EntId, //商机管理企业id
  47. EntUserId: in.EntUserId, //商机管理用户id
  48. DeptId: in.DeptId, //商机管理部门id
  49. NewUserId: in.NewUserId,
  50. BaseServiceMysql: IC.BaseServiceMysql,
  51. IsEnt: in.IsEnt,
  52. }
  53. if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
  54. //encodeArr := strings.Split(selectIds, ",")
  55. //idArr := make([]string, 0, len(encodeArr))
  56. //for _, encodeId := range encodeArr {
  57. // if tmp := util.DecodeId(encodeId); tmp != "" {
  58. // idArr = append(idArr, tmp)
  59. // }
  60. //}
  61. spqp.SelectInfoIds = strings.Split(selectIds, ",")
  62. }
  63. _, _, list := model.NewSubscribePush(vipType).Datas(spqp)
  64. if list == nil || len(list) == 0 {
  65. return &bxsubscribe.ByPushHistoryResp{
  66. ErrorCode: 1,
  67. ErrorMsg: "未查询到数据",
  68. }, nil
  69. }
  70. ids := make([]string, 0, len(list))
  71. keyWords := make([]string, 0, len(list))
  72. for _, pushData := range list {
  73. if pushData.XId != "" {
  74. if xid := util.DecodeId(pushData.XId); len(xid) > 0 {
  75. ids = append(ids, xid)
  76. keyWords = append(keyWords, strings.Join(pushData.MatchKeys, ","))
  77. }
  78. }
  79. }
  80. saveData := map[string]interface{}{
  81. "s_userid": in.UserId,
  82. "comeinfrom": "pushHistory",
  83. "comeintime": time.Now().Unix(),
  84. "selectIds": ids,
  85. "pushKeyWords": keyWords,
  86. }
  87. _id := IC.Mgo.Save("export_search", saveData)
  88. if _id == "" {
  89. return &bxsubscribe.ByPushHistoryResp{
  90. ErrorCode: 1,
  91. ErrorMsg: "创建导出异常",
  92. }, nil
  93. }
  94. return &bxsubscribe.ByPushHistoryResp{
  95. Data: util.EncodeId(_id),
  96. }, nil
  97. }