buyerlistlogic.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 > 100 || in.PageSize < 1 {
  39. in.PageSize = 10
  40. }
  41. if in.PageSize > IC.C.BuyerSearchLimit {
  42. in.PageSize = IC.C.BuyerSearchLimit
  43. }
  44. query, CountQuery := "", ""
  45. buyerNames := []string{}
  46. if model.CheckEmpty(in) {
  47. var isBool = true
  48. list := []*bxbuyer.BuyerList{} //100条数据
  49. bs, err := redis.GetBytes("other", fmt.Sprintf(model.P_redis_key))
  50. if err == nil && bs != nil && len(*bs) > 0 {
  51. isBool = false
  52. if err := json.Unmarshal(*bs, &list); err != nil {
  53. isBool = true
  54. logx.Info("获取redis缓存,序列化异常")
  55. } else {
  56. if len(list) > 0 {
  57. // 根据页码返回数据
  58. start := in.PageSize * (in.PageNum - 1)
  59. end := in.PageSize * in.PageNum
  60. count := len(list)
  61. resp.Data.Count = int64(count)
  62. if end > int64(len(list)) {
  63. end = int64(len(list))
  64. }
  65. resp.Data.List = list[start:end]
  66. for i := 0; i < len(resp.Data.List); i++ {
  67. buyerNames = append(buyerNames, resp.Data.List[i].Buyer)
  68. }
  69. } else {
  70. isBool = true
  71. }
  72. }
  73. }
  74. if isBool {
  75. query = model.BuyerListRedisCacheQuery()
  76. buyerNames, resp = model.BuyerListRedisCache(query, in)
  77. }
  78. } else {
  79. query, CountQuery = model.BuyerListQuery(in)
  80. logx.Info("query:", query)
  81. buyerNames, resp = model.GetBuyerList(query, CountQuery, false) // 查询数据
  82. }
  83. if len(resp.Data.List) > 0 && (in.UserId != "" || in.EntUserId != "") {
  84. model.SupplyFollowInfo(in, buyerNames, resp)
  85. }
  86. if resp.Data.Count > IC.C.BuyerSearchLimit {
  87. resp.Data.Count = IC.C.BuyerSearchLimit
  88. }
  89. return resp, nil
  90. }