123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package logic
- import (
- "app.yhyue.com/moapp/jybase/redis"
- "context"
- "encoding/json"
- "github.com/zeromicro/go-zero/core/logx"
- "jyBXBuyer/rpc/internal/svc"
- "jyBXBuyer/rpc/model"
- "jyBXBuyer/rpc/type/bxbuyer"
- "log"
- )
- type BuyerListLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewBuyerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BuyerListLogic {
- return &BuyerListLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 采购单位搜索
- func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerListResp, error) {
- log.Println("----:", model.CheckEmpty(in))
- query := ""
- resp := &bxbuyer.BuyerListResp{}
- if model.CheckEmpty(in) {
- //获取缓存数据
- var isBool = true
- bs, err := redis.GetBytes("other", model.P_redis_key)
- if err == nil && bs != nil && len(*bs) > 0 {
- isBool = false
- if err := json.Unmarshal(*bs, &resp.Data); err != nil {
- isBool = true
- logx.Info("获取redis缓存,序列化异常")
- }
- }
- if isBool {
- query = model.BuyerListRedisCacheQuery()
- resp = model.GetBuyerList(query, in)
- b, err := json.Marshal(resp.Data)
- if err == nil {
- redis.PutBytes("other", model.P_redis_key, &b, model.P_redis_time)
- } else {
- logx.Info("缓存数据 序列化异常")
- }
- }
- } else {
- query = model.BuyerListQuery(in)
- resp = model.GetBuyerList(query, in)
- }
- return &bxbuyer.BuyerListResp{
- Data: resp.Data,
- ErrMsg: resp.ErrMsg,
- ErrCode: resp.ErrCode,
- }, nil
- }
|