purchasesearchlogic.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/internal/svc"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
  7. "context"
  8. "fmt"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. "log"
  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. var (
  27. res = &bxcore.PurchaseResp{
  28. Data: &bxcore.PurchaseData{
  29. List: []*bxcore.PurchaseList{},
  30. },
  31. }
  32. )
  33. ps := service.NewPurchase(in)
  34. ps.FilterCriteriaFormat()
  35. //更新历史记录
  36. go ps.HistoryKeywords()
  37. if IC.C.NoLoginSearch.Switch && ps.UserId == "" {
  38. flag := IC.ReqLimitInit.Limit(context.Background())
  39. if flag == 1 {
  40. defer IC.ReqLimitInit.Release()
  41. } else {
  42. if flag == -2 {
  43. log.Println("等待队列已满")
  44. } else if flag == -1 {
  45. log.Println("等待超时")
  46. }
  47. }
  48. if flag < 0 {
  49. log.Println("--并发队列--", fmt.Errorf("暂无数据"))
  50. return &bxcore.PurchaseResp{}, nil
  51. }
  52. }
  53. list, err := ps.GetPurchaseData()
  54. if err == nil && len(list) > 0 {
  55. res.Data.List = list
  56. }
  57. res.Data.PageNum = ps.PageNum
  58. res.Data.PageSize = ps.PageSize
  59. res.Data.TipMsg = ps.TipMsg
  60. res.Data.HighlightWords = ps.HighlightWords
  61. res.Data.Total = ps.Total
  62. res.Data.Count = ps.Count
  63. return res, err
  64. }