buyerlistlogic.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. IC "jyBXBuyer/rpc/init"
  9. "jyBXBuyer/rpc/internal/svc"
  10. "jyBXBuyer/rpc/model"
  11. "jyBXBuyer/rpc/type/bxbuyer"
  12. )
  13. type BuyerListLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewBuyerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BuyerListLogic {
  19. return &BuyerListLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 采购单位搜索
  26. func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerListResp, error) {
  27. logx.Info("----:", model.CheckEmpty(in))
  28. resp := &bxbuyer.BuyerListResp{
  29. Data: &bxbuyer.BuyerData{},
  30. }
  31. // 采购单位搜索过来的 最多查100条
  32. if in.PageSize*in.PageNum > IC.C.BuyerSearchLimit {
  33. in.PageNum = IC.C.BuyerSearchLimit / in.PageSize
  34. }
  35. if in.PageNum < 1 {
  36. in.PageNum = 1
  37. }
  38. if in.PageSize < 1 || in.PageSize > IC.C.BuyerSearchLimit {
  39. in.PageSize = IC.C.BuyerSearchLimit / in.PageNum
  40. }
  41. query, CountQuery := "", ""
  42. buyerNames := []string{}
  43. if model.CheckEmpty(in) {
  44. var isBool = true
  45. list := []*bxbuyer.BuyerList{} //100条数据
  46. bs, err := redis.GetBytes("other", fmt.Sprintf(model.P_redis_key))
  47. if err == nil && bs != nil && len(*bs) > 0 {
  48. isBool = false
  49. if err := json.Unmarshal(*bs, &list); err != nil {
  50. isBool = true
  51. logx.Info("获取redis缓存,序列化异常")
  52. } else {
  53. if len(list) > 0 {
  54. // 根据页码返回数据
  55. start := in.PageSize * (in.PageNum - 1)
  56. end := in.PageSize * in.PageNum
  57. count := len(list)
  58. resp.Data.Count = int64(count)
  59. if end > int64(len(list)-1) {
  60. end = int64(len(list) - 1)
  61. }
  62. resp.Data.List = list[start:end]
  63. for i := 0; i < len(resp.Data.List); i++ {
  64. buyerNames = append(buyerNames, resp.Data.List[i].Buyer)
  65. }
  66. } else {
  67. isBool = true
  68. }
  69. }
  70. }
  71. if isBool {
  72. /*
  73. 空搜索
  74. 1. 聚合出来200条采购单位数据 项目数量 采购单位规模 可以直接一块出来
  75. 2. 查采购单位库确认100条数据有效
  76. 3. 存一周缓存
  77. */
  78. query = model.BuyerListRedisCacheQuery(in.PageNum, in.PageSize)
  79. buyerNames, resp = model.BuyerListRedisCache(query, in)
  80. }
  81. } else {
  82. query, CountQuery = model.BuyerListQuery(in)
  83. logx.Info("query:", query)
  84. buyerNames, resp = model.GetBuyerList(query, CountQuery, false) // 查询数据
  85. }
  86. if len(resp.Data.List) > 0 && (in.UserId != "" || in.EntUserId != "") {
  87. model.SupplyFollowInfo(in, buyerNames, resp)
  88. }
  89. if resp.Data.Count > IC.C.BuyerSearchLimit {
  90. resp.Data.Count = IC.C.BuyerSearchLimit
  91. }
  92. return resp, nil
  93. }