purchasesearchlogic.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. return &bxcore.PurchaseResp{}, fmt.Errorf("暂无数据")
  50. }
  51. }
  52. list, err := ps.GetPurchaseData()
  53. if err == nil && len(list) > 0 {
  54. res.Data.List = list
  55. }
  56. res.Data.PageNum = ps.PageNum
  57. res.Data.PageSize = ps.PageSize
  58. res.Data.TipMsg = ps.TipMsg
  59. res.Data.HighlightWords = ps.HighlightWords
  60. res.Data.Total = ps.Total
  61. return res, err
  62. }