getsublistlogic.go 4.8 KB

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