purchasesearchlogic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package logic
  2. import (
  3. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  4. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
  5. "context"
  6. "fmt"
  7. "log"
  8. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
  9. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type PurchaseSearchLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewPurchaseSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PurchaseSearchLogic {
  18. return &PurchaseSearchLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 采购信息搜索
  25. func (l *PurchaseSearchLogic) PurchaseSearch(in *bxcore.PurchaseReq) (*bxcore.PurchaseResp, error) {
  26. if IC.C.NoLoginSearch.Switch {
  27. flag := IC.ReqLimitInit.Limit(context.Background())
  28. if flag == 1 {
  29. defer IC.ReqLimitInit.Release()
  30. } else {
  31. if flag == -2 {
  32. log.Println("等待队列已满")
  33. } else if flag == -1 {
  34. log.Println("等待超时")
  35. }
  36. }
  37. if flag < 0 {
  38. return &bxcore.PurchaseResp{}, fmt.Errorf("暂无数据")
  39. }
  40. }
  41. var (
  42. res = &bxcore.PurchaseResp{}
  43. )
  44. ps := service.NewPurchase(in)
  45. ps.FilterCriteriaFormat()
  46. list, err := ps.GetPurchaseData()
  47. if err == nil && len(list) > 0 {
  48. res.Data.List = list
  49. }
  50. res.Data.PageNum = ps.PageNum
  51. res.Data.PageSize = ps.PageSize
  52. res.Data.TipMsg = ps.TipMsg
  53. res.Data.HighlightWords = ps.HighlightWords
  54. res.Data.Total = ps.Total
  55. return res, err
  56. }