bypushhistorylogic.go 4.5 KB

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