getsublistlogic.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. "strings"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetSubListLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewGetSubListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubListLogic {
  19. return &GetSubListLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 获取订阅推送列表
  26. func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubscribe.SubscribeInfosResp, error) {
  27. start := time.Now().Unix()
  28. //1、推送信息已读标识
  29. //超级订阅 i_apppushunread=0
  30. //大会员 i_member_apppushunread=0
  31. //商机管理 i_entniche_apppushunread=0
  32. if in.IsEnt {
  33. in.UserType = model.EntnicheFlag
  34. }
  35. if in.PageNum == 1 {
  36. go model.UpdateUserPushUnread(in.UserId, in.UserType)
  37. }
  38. //分发员工
  39. var staffIds []string
  40. for _, staffId := range strings.Split(in.Staffs, ",") {
  41. if staffId != "" {
  42. staffIds = append(staffIds, staffId)
  43. }
  44. }
  45. spqp := &model.SubPushQueryParam{
  46. Mgo_bidding: IC.MgoBidding, //mongo
  47. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  48. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  49. UserId: in.UserId, //用户id
  50. PageNum: int(in.PageNum), //当前页码
  51. PageSize: int(in.PageSize), //每页多少条数据
  52. SelectTime: in.SelectTime, //时间跨度
  53. Area: in.Area, //省份
  54. City: in.City, //城市
  55. Buyerclass: in.BuyerClass, //采购单位类型
  56. Subtype: in.Subtype, //信息类型
  57. Subscopeclass: in.Industry, //行业
  58. Key: in.KeyWords, //关键词
  59. Price: in.Price, //价格区间
  60. FileExists: in.FileExists, //是否有附件
  61. IsRead: in.IsRead,
  62. Source: in.Source,
  63. Staffs: staffIds,
  64. EntId: in.EntId, //商机管理企业id
  65. EntUserId: in.EntUserId, //商机管理用户id
  66. DeptId: in.DeptId, //商机管理部门id
  67. NewUserId: in.NewUserId,
  68. BaseServiceMysql: IC.BaseServiceMysql,
  69. IsEnt: in.IsEnt,
  70. BuySubject: 0,
  71. UserType: in.UserType,
  72. }
  73. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  74. infoCount := int64(0)
  75. if in.UserType == model.MemberFlag {
  76. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%大会员%' ", in.EntId)
  77. } else if in.UserType == model.SubVipFlag {
  78. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%VIP订阅%' ", in.EntId)
  79. }
  80. if infoCount > 0 {
  81. in.UserType = model.EntnicheFlag
  82. //主体等于企业的
  83. spqp.BuySubject = 1
  84. }
  85. if in.UserType == model.EntnicheFlag {
  86. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  87. }
  88. hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp)
  89. start1 := time.Now().Unix()
  90. logx.Info("1、查询数据用户", start1-start)
  91. /*
  92. *无推送记录生成推送记录
  93. *免费用户默认推送50条
  94. *大会员、新版商机管理、超级订阅用户 默认推送1000条记录
  95. */
  96. if in.PageNum == 1 && spqp.IsEmpty() && len(list) == 0 && in.IsEnt == false {
  97. hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp)
  98. }
  99. start2 := time.Now().Unix()
  100. logx.Info("2、查询数据用户", start2-start1)
  101. //查询是否收藏
  102. model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
  103. start3 := time.Now().Unix()
  104. logx.Info("3、查询数据用户", start3-start2)
  105. logx.Info("总共查询数据用户", start3-start)
  106. return &bxsubscribe.SubscribeInfosResp{
  107. Data: &bxsubscribe.SubscribeData{
  108. List: list,
  109. Count: total,
  110. HasNextPage: hasNextPage,
  111. },
  112. }, nil
  113. }