getsublistlogic.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. //1、推送信息已读标识
  32. //超级订阅 i_apppushunread=0
  33. //大会员 i_member_apppushunread=0
  34. //商机管理 i_entniche_apppushunread=0
  35. if in.IsEnt {
  36. in.UserType = model.EntnicheFlag
  37. }
  38. if in.PageNum == 1 {
  39. go model.UpdateUserPushUnread(in.UserId, in.UserType)
  40. }
  41. accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
  42. positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
  43. entId, _ := strconv.ParseInt(in.EntId, 10, 64)
  44. //判断用户身份
  45. userInfo := IC.Middleground.PowerCheckCenter.Check("10000", in.MgoUserId, in.NewUserId, accountId, entId, in.PositionType, positionId)
  46. //是否是付费用户
  47. isPay := !userInfo.Free.IsFree
  48. isPayUser := false
  49. //付费用户
  50. if in.UserType != "fType" && isPay {
  51. isPayUser = true
  52. }
  53. //分发员工
  54. var staffIds []string
  55. for _, staffId := range strings.Split(in.Staffs, ",") {
  56. if staffId != "" {
  57. staffIds = append(staffIds, staffId)
  58. }
  59. }
  60. if in.Industry = strings.TrimSpace(in.Industry); in.Industry != "" {
  61. //P510 行业:其它
  62. if qt := jy.IndustryHandle(in.Industry); len(qt) > 0 {
  63. in.Industry = fmt.Sprintf("%s,%s", in.Industry, strings.Join(qt, ","))
  64. }
  65. }
  66. spqp := &model.SubPushQueryParam{
  67. Mgo_bidding: IC.MgoBidding, //mongo
  68. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  69. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  70. UserId: in.UserId, //用户id
  71. PageNum: int(in.PageNum), //当前页码
  72. PageSize: int(in.PageSize), //每页多少条数据
  73. SelectTime: in.SelectTime, //时间跨度
  74. Area: in.Area, //省份
  75. City: in.City, //城市
  76. Buyerclass: in.BuyerClass, //采购单位类型
  77. Subtype: in.Subtype, //信息类型
  78. Subscopeclass: in.Industry, //行业
  79. Key: in.KeyWords, //关键词
  80. Price: in.Price, //价格区间
  81. FileExists: in.FileExists, //是否有附件
  82. IsRead: in.IsRead, //
  83. Source: in.Source, //
  84. Staffs: staffIds, //
  85. EntId: in.EntId, //商机管理企业id
  86. EntUserId: in.EntUserId, //商机管理用户id
  87. DeptId: in.DeptId, //商机管理部门id
  88. NewUserId: in.NewUserId,
  89. BaseServiceMysql: IC.BaseServiceMysql,
  90. IsEnt: in.IsEnt,
  91. BuySubject: 0,
  92. UserType: in.UserType,
  93. PositionType: in.PositionType,
  94. IsPayUser: isPayUser,
  95. NotReturnCount: in.NotReturnCount,
  96. Item: in.Item,
  97. District: in.District,
  98. }
  99. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  100. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag || in.UserType == model.SubFreeFlag {
  101. if in.PositionType == 1 {
  102. in.UserType = model.EntnicheFlag
  103. }
  104. }
  105. if in.UserType == model.EntnicheFlag {
  106. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  107. }
  108. sp := model.NewSubscribePush(in.UserType)
  109. //用户信息
  110. bsp := sp.GetUserInfo(spqp)
  111. hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp, bsp)
  112. start1 := time.Now().Unix()
  113. logx.Info("1、查询数据用户", start1-start)
  114. /*
  115. *无推送记录生成推送记录
  116. *免费用户默认推送50条
  117. *大会员、新版商机管理、超级订阅用户 默认推送1000条记录
  118. */
  119. isRecommend := "1" //1:老数据 2:历史(clickhouse) 3:新数据
  120. if in.PageNum == 1 && spqp.IsEmpty() && (len(list) == 0 || (in.PositionType == 0 && spqp.SubPushInactive == -1)) && in.IsEnt == false {
  121. hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp, bsp, in.UserType)
  122. if in.Stag == "home" {
  123. if len(list) == 0 {
  124. isRecommend = "2"
  125. hasNextPage, total, list = model.NewSubscribePush(in.UserType).SubRecList(common.ObjToString(common.If(in.PositionType == 0, spqp.UserId, spqp.EntUserId)), bsp.Keyword)
  126. }
  127. if len(list) == 0 {
  128. isRecommend = "3"
  129. hasNextPage, total, list = model.NewSubscribePush(in.UserType).GetRecListByEs()
  130. }
  131. }
  132. }
  133. start2 := time.Now().Unix()
  134. logx.Info("2、查询数据用户", start2-start1)
  135. //查询是否收藏
  136. model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
  137. start3 := time.Now().Unix()
  138. logx.Info("3、查询数据用户", start3-start2)
  139. logx.Info("总共查询数据用户", start3-start)
  140. return &bxsubscribe.SubscribeInfosResp{
  141. Data: &bxsubscribe.SubscribeData{
  142. List: list,
  143. Count: total,
  144. HasNextPage: hasNextPage,
  145. IsRecommend: isRecommend,
  146. },
  147. }, nil
  148. }