bypushhistorylogic.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init"
  8. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc"
  9. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/model"
  10. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe"
  11. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/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. District: in.District,
  69. }
  70. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  71. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag || in.UserType == model.SubFreeFlag {
  72. if in.PositionType == 1 {
  73. in.UserType = model.EntnicheFlag
  74. vipType = model.EntnicheFlag
  75. }
  76. }
  77. if in.UserType == model.EntnicheFlag {
  78. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  79. }
  80. logx.Info("数据导出查询参数", in)
  81. if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
  82. spqp.SelectInfoIds = strings.Split(selectIds, ",")
  83. }
  84. if selectKeys := strings.TrimSpace(in.SelectKeys); selectKeys != "" {
  85. spqp.SelectKeys = strings.Split(selectKeys, ",")
  86. }
  87. //P385 优化订阅列表数据导出
  88. var (
  89. ids, keyWords []string
  90. )
  91. bsp := model.NewSubscribePush(vipType).GetUserInfo(spqp)
  92. if len(spqp.SelectInfoIds) > 0 {
  93. ids, keyWords = spqp.ExportPushFormat()
  94. } else {
  95. _, _, list := model.NewSubscribePush(vipType).Datas(spqp, bsp)
  96. if list == nil || len(list) == 0 {
  97. return &bxsubscribe.ByPushHistoryResp{
  98. ErrorCode: 1,
  99. ErrorMsg: "未查询到数据",
  100. }, nil
  101. }
  102. ids = make([]string, 0, len(list))
  103. keyWords = make([]string, 0, len(list))
  104. listMap := make(map[string]string)
  105. //去重 防止list有重复数据
  106. for _, pushData := range list {
  107. if pushData.XId != "" {
  108. listMap[pushData.XId] = strings.Join(pushData.MatchKeys, ",")
  109. }
  110. }
  111. logx.Info("数据导出搜索条数与去重后对比+++++++++++++", len(list), len(listMap))
  112. //获取id与对应关键词
  113. for k, v := range listMap {
  114. if xid := util.DecodeId(k); len(xid) > 0 {
  115. ids = append(ids, xid)
  116. keyWords = append(keyWords, v)
  117. }
  118. }
  119. }
  120. if len(ids) > 0 {
  121. saveData := map[string]interface{}{
  122. "s_userid": in.UserId,
  123. "comeinfrom": "pushHistory",
  124. "comeintime": time.Now().Unix(),
  125. "selectIds": ids,
  126. "pushKeyWords": keyWords,
  127. }
  128. _id := IC.Mgo.Save("export_search", saveData)
  129. if _id == "" {
  130. return &bxsubscribe.ByPushHistoryResp{
  131. ErrorCode: 1,
  132. ErrorMsg: "保存导出数据异常",
  133. }, nil
  134. }
  135. return &bxsubscribe.ByPushHistoryResp{
  136. Data: encrypt.SE.Encode2Hex(_id),
  137. }, nil
  138. }
  139. return &bxsubscribe.ByPushHistoryResp{
  140. ErrorCode: 1,
  141. ErrorMsg: "导出数据异常,请联系管理员",
  142. }, nil
  143. }