12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package logic
- import (
- "app.yhyue.com/moapp/jybase/redis"
- "context"
- "encoding/json"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- IC "jyBXBuyer/rpc/init"
- "jyBXBuyer/rpc/internal/svc"
- "jyBXBuyer/rpc/model"
- "jyBXBuyer/rpc/type/bxbuyer"
- "time"
- )
- 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) {
- start2 := time.Now()
- logx.Info("----:", model.CheckEmpty(in))
- query, CountQuery := "", ""
- resp := &bxbuyer.BuyerListResp{}
- // 采购单位搜索过来的 最多查100条
- if in.PageSize*in.PageNum > IC.C.BuyerSearchLimit {
- in.PageNum = IC.C.BuyerSearchLimit / in.PageSize
- }
- if in.PageNum < 1 {
- in.PageNum = 1
- }
- if in.PageSize < 1 {
- in.PageNum = 10
- }
- if model.CheckEmpty(in) {
- //获取缓存数据
- var isBool = true
- bs, err := redis.GetBytes("other", fmt.Sprintf(model.P_redis_key, in.PageNum, in.PageSize))
- 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, CountQuery = model.BuyerListRedisCacheQuery(in.PageNum, in.PageSize)
- resp = model.GetBuyerList(query, CountQuery, in, true)
- if len(resp.Data.List) > 0 {
- model.SupplyBuyerListData(resp)
- }
- b, err := json.Marshal(resp.Data)
- if err == nil {
- redis.PutBytes("other", fmt.Sprintf(model.P_redis_key, in.PageNum, in.PageSize), &b, model.P_redis_time)
- } else {
- logx.Info("缓存数据 序列化异常")
- }
- }
- } else {
- query, CountQuery = model.BuyerListQuery(in)
- logx.Info("query:", query)
- resp = model.GetBuyerList(query, CountQuery, in, false) // 查询数据
- if len(resp.Data.List) > 0 {
- model.SupplyBuyerListData(resp)
- }
- }
- if resp.Data.Count > IC.C.BuyerSearchLimit {
- resp.Data.Count = IC.C.BuyerSearchLimit
- }
- logx.Info("SupplyBuyerListData耗时:", time.Since(start2))
- return resp, nil
- }
|