bypushhistorylogic.go 5.3 KB

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