bypushhistorylogic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. }
  66. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  67. <<<<<<< HEAD
  68. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag {
  69. if in.PositionType == 1 {
  70. =======
  71. infoCount := int64(0)
  72. if in.UserType == model.MemberFlag {
  73. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%大会员%' ", in.EntId)
  74. } else if in.UserType == model.SubVipFlag {
  75. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%VIP订阅%' ", in.EntId)
  76. }
  77. if infoCount > 0 {
  78. in.UserType = model.EntnicheFlag
  79. vipType = model.EntnicheFlag
  80. //主体等于企业的
  81. spqp.BuySubject = 1
  82. }
  83. if in.IsEnt == true {
  84. newCount := IC.MainMysql.CountBySql("select count(id) from entniche_info where id =? and status=1", spqp.EntId)
  85. if newCount > 0 {
  86. >>>>>>> master
  87. in.UserType = model.EntnicheFlag
  88. vipType = model.EntnicheFlag
  89. }
  90. }
  91. <<<<<<< HEAD
  92. =======
  93. if in.UserType == model.EntnicheFlag {
  94. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  95. }
  96. >>>>>>> master
  97. logx.Info("数据导出查询参数", in)
  98. if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
  99. spqp.SelectInfoIds = strings.Split(selectIds, ",")
  100. }
  101. _, _, list := model.NewSubscribePush(vipType).Datas(spqp)
  102. if list == nil || len(list) == 0 {
  103. return &bxsubscribe.ByPushHistoryResp{
  104. ErrorCode: 1,
  105. ErrorMsg: "未查询到数据",
  106. }, nil
  107. }
  108. ids := make([]string, 0, len(list))
  109. keyWords := make([]string, 0, len(list))
  110. listMap := make(map[string]string)
  111. //去重 防止list有重复数据
  112. for _, pushData := range list {
  113. if pushData.XId != "" {
  114. listMap[pushData.XId] = strings.Join(pushData.MatchKeys, ",")
  115. }
  116. }
  117. logx.Info("数据导出搜索条数与去重后对比+++++++++++++", len(list), len(listMap))
  118. //获取id与对应关键词
  119. for k, v := range listMap {
  120. if xid := util.DecodeId(k); len(xid) > 0 {
  121. ids = append(ids, xid)
  122. keyWords = append(keyWords, v)
  123. }
  124. }
  125. saveData := map[string]interface{}{
  126. "s_userid": in.UserId,
  127. "comeinfrom": "pushHistory",
  128. "comeintime": time.Now().Unix(),
  129. "selectIds": ids,
  130. "pushKeyWords": keyWords,
  131. }
  132. _id := IC.Mgo.Save("export_search", saveData)
  133. if _id == "" {
  134. return &bxsubscribe.ByPushHistoryResp{
  135. ErrorCode: 1,
  136. ErrorMsg: "创建导出异常",
  137. }, nil
  138. }
  139. return &bxsubscribe.ByPushHistoryResp{
  140. Data: encrypt.SE.Encode2Hex(_id),
  141. }, nil
  142. }