getsublistlogic.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  4. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/model"
  7. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe"
  8. "context"
  9. "fmt"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "app.yhyue.com/moapp/jybase/common"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. type GetSubListLogic struct {
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. logx.Logger
  20. }
  21. func NewGetSubListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubListLogic {
  22. return &GetSubListLogic{
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. Logger: logx.WithContext(ctx),
  26. }
  27. }
  28. // GetSubList 获取订阅推送列表
  29. func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubscribe.SubscribeInfosResp, error) {
  30. start := time.Now().Unix()
  31. if in.PageNum <= 0 {
  32. in.PageNum = 1
  33. }
  34. //1、推送信息已读标识
  35. //超级订阅 i_apppushunread=0
  36. //大会员 i_member_apppushunread=0
  37. //商机管理 i_entniche_apppushunread=0
  38. if in.IsEnt {
  39. in.UserType = model.EntnicheFlag
  40. }
  41. if in.PageNum == 1 {
  42. go model.UpdateUserPushUnread(in.UserId, in.UserType)
  43. }
  44. accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
  45. positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
  46. entId, _ := strconv.ParseInt(in.EntId, 10, 64)
  47. //判断用户身份
  48. userInfo := IC.Middleground.PowerCheckCenter.Check("10000", in.MgoUserId, in.NewUserId, accountId, entId, in.PositionType, positionId)
  49. //是否是付费用户
  50. isPay := !userInfo.Free.IsFree
  51. isPayUser := false
  52. //付费用户
  53. if in.UserType != "fType" && isPay {
  54. isPayUser = true
  55. }
  56. //分发员工
  57. var staffIds []string
  58. for _, staffId := range strings.Split(in.Staffs, ",") {
  59. if staffId != "" {
  60. staffIds = append(staffIds, staffId)
  61. }
  62. }
  63. if in.Industry = strings.TrimSpace(in.Industry); in.Industry != "" {
  64. //P510 行业:其它
  65. if qt := jy.IndustryHandle(in.Industry); len(qt) > 0 {
  66. in.Industry = fmt.Sprintf("%s,%s", in.Industry, strings.Join(qt, ","))
  67. }
  68. }
  69. spqp := &model.SubPushQueryParam{
  70. Mgo_bidding: IC.MgoBidding, //mongo
  71. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  72. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  73. UserId: in.UserId, //用户id
  74. PageNum: int(in.PageNum), //当前页码
  75. PageSize: int(in.PageSize), //每页多少条数据
  76. SelectTime: in.SelectTime, //时间跨度
  77. Area: in.Area, //省份
  78. City: in.City, //城市
  79. Buyerclass: in.BuyerClass, //采购单位类型
  80. Subtype: in.Subtype, //信息类型
  81. Subscopeclass: in.Industry, //行业
  82. Key: in.KeyWords, //关键词
  83. Price: in.Price, //价格区间
  84. FileExists: in.FileExists, //是否有附件
  85. IsRead: in.IsRead, //
  86. Source: in.Source, //
  87. Staffs: staffIds, //
  88. EntId: in.EntId, //商机管理企业id
  89. EntUserId: in.EntUserId, //商机管理用户id
  90. DeptId: in.DeptId, //商机管理部门id
  91. NewUserId: in.NewUserId,
  92. BaseServiceMysql: IC.BaseServiceMysql,
  93. IsEnt: in.IsEnt,
  94. BuySubject: 0,
  95. UserType: in.UserType,
  96. PositionType: in.PositionType,
  97. IsPayUser: isPayUser,
  98. NotReturnCount: in.NotReturnCount,
  99. Item: in.Item,
  100. District: in.District,
  101. }
  102. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  103. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag || in.UserType == model.SubFreeFlag {
  104. if in.PositionType == 1 {
  105. in.UserType = model.EntnicheFlag
  106. }
  107. }
  108. if in.UserType == model.EntnicheFlag {
  109. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  110. }
  111. var (
  112. tip string
  113. )
  114. sp := model.NewSubscribePush(in.UserType)
  115. //用户信息
  116. bsp := sp.GetUserInfo(spqp)
  117. hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp, bsp)
  118. start1 := time.Now().Unix()
  119. logx.Info("1、查询数据用户", start1-start)
  120. /*
  121. *无推送记录生成推送记录
  122. *免费用户默认推送 50 条
  123. *大会员、新版商机管理、超级订阅用户 默认推送 1000 条记录
  124. */
  125. isRecommend := "1" //1:老数据 2:历史(clickhouse) 3:新数据
  126. if in.PageNum == 1 && spqp.IsEmpty() && (len(list) == 0 || (in.PositionType == 0 && spqp.SubPushInactive == -1)) && in.IsEnt == false {
  127. hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp, bsp, in.UserType)
  128. if in.Stag == "home" {
  129. if len(list) == 0 {
  130. isRecommend = "2"
  131. hasNextPage, total, list = model.NewSubscribePush(in.UserType).SubRecList(common.ObjToString(common.If(in.PositionType == 0, spqp.UserId, spqp.EntUserId)), bsp.Keyword, bsp.Size)
  132. }
  133. if len(list) == 0 {
  134. isRecommend = "3"
  135. hasNextPage, total, list = model.NewSubscribePush(in.UserType).GetRecListByEs()
  136. }
  137. }
  138. //P618 增加预加载数据提示:为您预加载最近15天发布的【X】商机
  139. //1、首次访问;2、无推送数据;3、数据量满足免费50条,付费用户1000条;4、非活跃用户不参与
  140. if len(list) > 0 {
  141. tip = fmt.Sprintf(IC.C.SubListTip, "")
  142. if total >= int64(bsp.Size) {
  143. tip = fmt.Sprintf(IC.C.SubListTip, fmt.Sprintf("%d条", bsp.Size))
  144. }
  145. }
  146. }
  147. start2 := time.Now().Unix()
  148. logx.Info("2、查询数据用户", start2-start1)
  149. //查询是否收藏
  150. model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
  151. start3 := time.Now().Unix()
  152. logx.Info("3、查询数据用户", start3-start2)
  153. logx.Info("总共查询数据用户", start3-start)
  154. return &bxsubscribe.SubscribeInfosResp{
  155. Data: &bxsubscribe.SubscribeData{
  156. List: list,
  157. Count: total,
  158. HasNextPage: hasNextPage, //前端没用到这个字段
  159. IsRecommend: isRecommend,
  160. SubListTip: tip,
  161. },
  162. }, nil
  163. }