getsublistlogic.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. "jyBXSubscribe/rpc/util"
  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. // 获取订阅推送列表
  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. isPayUser := false
  40. userInfo := util.GetVipState(IC.MainMysql, IC.Mgo, in.UserId)
  41. //付费用户
  42. if in.UserType != "fType" && userInfo.IsPayedUser() {
  43. isPayUser = true
  44. }
  45. //分发员工
  46. var staffIds []string
  47. for _, staffId := range strings.Split(in.Staffs, ",") {
  48. if staffId != "" {
  49. staffIds = append(staffIds, staffId)
  50. }
  51. }
  52. spqp := &model.SubPushQueryParam{
  53. Mgo_bidding: IC.MgoBidding, //mongo
  54. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  55. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  56. UserId: in.UserId, //用户id
  57. PageNum: int(in.PageNum), //当前页码
  58. PageSize: int(in.PageSize), //每页多少条数据
  59. SelectTime: in.SelectTime, //时间跨度
  60. Area: in.Area, //省份
  61. City: in.City, //城市
  62. Buyerclass: in.BuyerClass, //采购单位类型
  63. Subtype: in.Subtype, //信息类型
  64. Subscopeclass: in.Industry, //行业
  65. Key: in.KeyWords, //关键词
  66. Price: in.Price, //价格区间
  67. FileExists: in.FileExists, //是否有附件
  68. IsRead: in.IsRead,
  69. Source: in.Source,
  70. Staffs: staffIds,
  71. EntId: in.EntId, //商机管理企业id
  72. EntUserId: in.EntUserId, //商机管理用户id
  73. DeptId: in.DeptId, //商机管理部门id
  74. NewUserId: in.NewUserId,
  75. BaseServiceMysql: IC.BaseServiceMysql,
  76. PushMysql: IC.PushMysql,
  77. IsEnt: in.IsEnt,
  78. BuySubject: 0,
  79. UserType: in.UserType,
  80. PositionType: in.PositionType,
  81. IsPayUser: isPayUser,
  82. }
  83. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  84. if in.UserType == model.MemberFlag || in.UserType == model.SubVipFlag || in.UserType == model.SubFreeFlag {
  85. if in.PositionType == 1 {
  86. in.UserType = model.EntnicheFlag
  87. }
  88. }
  89. if in.UserType == model.EntnicheFlag {
  90. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  91. }
  92. hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp)
  93. start1 := time.Now().Unix()
  94. logx.Info("1、查询数据用户", start1-start)
  95. /*
  96. *无推送记录生成推送记录
  97. *免费用户默认推送50条
  98. *大会员、新版商机管理、超级订阅用户 默认推送1000条记录
  99. */
  100. if in.PageNum == 1 && spqp.IsEmpty() && len(list) == 0 && in.IsEnt == false {
  101. hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp)
  102. }
  103. start2 := time.Now().Unix()
  104. logx.Info("2、查询数据用户", start2-start1)
  105. //查询是否收藏
  106. model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
  107. start3 := time.Now().Unix()
  108. logx.Info("3、查询数据用户", start3-start2)
  109. logx.Info("总共查询数据用户", start3-start)
  110. return &bxsubscribe.SubscribeInfosResp{
  111. Data: &bxsubscribe.SubscribeData{
  112. List: list,
  113. Count: total,
  114. HasNextPage: hasNextPage,
  115. },
  116. }, nil
  117. }