getsublistlogic.go 5.2 KB

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