buyerlistlogic.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "context"
  5. "encoding/json"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "jyBXBuyer/rpc/internal/svc"
  8. "jyBXBuyer/rpc/model"
  9. "jyBXBuyer/rpc/type/bxbuyer"
  10. "log"
  11. )
  12. type BuyerListLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewBuyerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BuyerListLogic {
  18. return &BuyerListLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 采购单位搜索
  25. func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerListResp, error) {
  26. log.Println("----:", model.CheckEmpty(in))
  27. query := ""
  28. resp := &bxbuyer.BuyerListResp{}
  29. if model.CheckEmpty(in) {
  30. //获取缓存数据
  31. var isBool = true
  32. bs, err := redis.GetBytes("other", model.P_redis_key)
  33. if err == nil && bs != nil && len(*bs) > 0 {
  34. isBool = false
  35. if err := json.Unmarshal(*bs, &resp.Data); err != nil {
  36. isBool = true
  37. logx.Info("获取redis缓存,序列化异常")
  38. }
  39. }
  40. if isBool {
  41. query = model.BuyerListRedisCacheQuery()
  42. resp = model.GetBuyerList(query, in)
  43. b, err := json.Marshal(resp.Data)
  44. if err == nil {
  45. redis.PutBytes("other", model.P_redis_key, &b, model.P_redis_time)
  46. } else {
  47. logx.Info("缓存数据 序列化异常")
  48. }
  49. }
  50. } else {
  51. query = model.BuyerListQuery(in)
  52. resp = model.GetBuyerList(query, in)
  53. }
  54. return &bxbuyer.BuyerListResp{
  55. Data: resp.Data,
  56. ErrMsg: resp.ErrMsg,
  57. ErrCode: resp.ErrCode,
  58. }, nil
  59. }