getsublistlogic.go 6.4 KB

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