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