bypushhistorylogic.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "context"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. IC "jyBXSubscribe/rpc/init"
  8. "jyBXSubscribe/rpc/internal/svc"
  9. "jyBXSubscribe/rpc/model"
  10. "jyBXSubscribe/rpc/type/bxsubscribe"
  11. "jyBXSubscribe/rpc/util"
  12. "strings"
  13. "time"
  14. )
  15. type ByPushHistoryLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewByPushHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ByPushHistoryLogic {
  21. return &ByPushHistoryLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. // 推送页面筛选导出
  28. func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*bxsubscribe.ByPushHistoryResp, error) {
  29. // todo: add your logic here and delete this line
  30. vipType := in.UserType
  31. //分发员工
  32. var staffIds []string
  33. for _, staffId := range strings.Split(in.Staffs, ",") {
  34. if staffId != "" {
  35. staffIds = append(staffIds, staffId)
  36. }
  37. }
  38. spqp := &model.SubPushQueryParam{
  39. Mgo_bidding: IC.MgoBidding, //mongo
  40. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  41. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  42. UserId: in.UserId, //用户id
  43. PageNum: 1, //当前页码
  44. PageSize: 20000, //每页多少条数据
  45. SelectTime: in.SelectTime, //时间跨度
  46. Area: in.Area, //省份
  47. City: in.City, //城市
  48. Export: true,
  49. Buyerclass: in.BuyerClass, //采购单位类型
  50. Subtype: in.Subtype, //信息类型
  51. Subscopeclass: in.Industry, //行业
  52. Key: in.KeyWords, //关键词
  53. Price: in.Price, //价格区间
  54. FileExists: in.FileExists, //是否有附件
  55. EntId: in.EntId, //商机管理企业id
  56. EntUserId: in.EntUserId, //商机管理用户id
  57. DeptId: in.DeptId, //商机管理部门id
  58. IsRead: in.IsRead,
  59. Source: in.Source,
  60. Staffs: staffIds,
  61. NewUserId: in.NewUserId,
  62. BaseServiceMysql: IC.BaseServiceMysql,
  63. IsEnt: in.IsEnt,
  64. UserType: in.UserType,
  65. PositionType: in.PositionType,
  66. NotReturnCount: in.NotReturnCount,
  67. Item: in.Item,
  68. }
  69. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  70. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag || in.UserType == model.SubFreeFlag {
  71. if in.PositionType == 1 {
  72. in.UserType = model.EntnicheFlag
  73. vipType = model.EntnicheFlag
  74. }
  75. }
  76. if in.UserType == model.EntnicheFlag {
  77. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  78. }
  79. logx.Info("数据导出查询参数", in)
  80. if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
  81. spqp.SelectInfoIds = strings.Split(selectIds, ",")
  82. }
  83. _, _, list := model.NewSubscribePush(vipType).Datas(spqp)
  84. if list == nil || len(list) == 0 {
  85. return &bxsubscribe.ByPushHistoryResp{
  86. ErrorCode: 1,
  87. ErrorMsg: "未查询到数据",
  88. }, nil
  89. }
  90. ids := make([]string, 0, len(list))
  91. keyWords := make([]string, 0, len(list))
  92. listMap := make(map[string]string)
  93. //去重 防止list有重复数据
  94. for _, pushData := range list {
  95. if pushData.XId != "" {
  96. listMap[pushData.XId] = strings.Join(pushData.MatchKeys, ",")
  97. }
  98. }
  99. logx.Info("数据导出搜索条数与去重后对比+++++++++++++", len(list), len(listMap))
  100. //获取id与对应关键词
  101. for k, v := range listMap {
  102. if xid := util.DecodeId(k); len(xid) > 0 {
  103. ids = append(ids, xid)
  104. keyWords = append(keyWords, v)
  105. }
  106. }
  107. saveData := map[string]interface{}{
  108. "s_userid": in.UserId,
  109. "comeinfrom": "pushHistory",
  110. "comeintime": time.Now().Unix(),
  111. "selectIds": ids,
  112. "pushKeyWords": keyWords,
  113. }
  114. _id := IC.Mgo.Save("export_search", saveData)
  115. if _id == "" {
  116. return &bxsubscribe.ByPushHistoryResp{
  117. ErrorCode: 1,
  118. ErrorMsg: "创建导出异常",
  119. }, nil
  120. }
  121. return &bxsubscribe.ByPushHistoryResp{
  122. Data: encrypt.SE.Encode2Hex(_id),
  123. }, nil
  124. }