1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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))
- 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.PageSize > 100 {
- in.PageSize = 10
- }
- query, CountQuery := "", ""
- buyerNames := []string{}
- 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)
- buyerNames, resp = model.GetBuyerList(query, CountQuery, true)
- if len(resp.Data.List) > 0 {
- 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)
- buyerNames, resp = model.GetBuyerList(query, CountQuery, false) // 查询数据
- }
- if len(resp.Data.List) > 0 {
- model.SupplyFollowInfo(in, buyerNames, resp)
- model.SupplyBuyerListData(buyerNames, resp)
- }
- if resp.Data.Count > IC.C.BuyerSearchLimit {
- resp.Data.Count = IC.C.BuyerSearchLimit
- }
- logx.Info("SupplyBuyerListData耗时:", time.Since(start2))
- return resp, nil
- }
|