purchasesearchlogic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package logic
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
  7. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
  8. "context"
  9. "fmt"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. "log"
  12. )
  13. type PurchaseSearchLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewPurchaseSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PurchaseSearchLogic {
  19. return &PurchaseSearchLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 采购信息搜索
  26. func (l *PurchaseSearchLogic) PurchaseSearch(in *bxcore.PurchaseReq) (*bxcore.PurchaseResp, error) {
  27. var (
  28. res = &bxcore.PurchaseResp{
  29. Data: &bxcore.PurchaseData{
  30. List: []*bxcore.PurchaseList{},
  31. },
  32. }
  33. )
  34. ps := service.NewPurchase(in)
  35. ps.FilterCriteriaFormat()
  36. //更新历史记录
  37. go ps.HistoryKeywords()
  38. if IC.C.NoLoginSearch.Switch && ps.UserId == "" {
  39. flag := IC.ReqLimitInit.Limit(context.Background())
  40. if flag == 1 {
  41. defer IC.ReqLimitInit.Release()
  42. } else {
  43. if flag == -2 {
  44. log.Println("等待队列已满")
  45. } else if flag == -1 {
  46. log.Println("等待超时")
  47. }
  48. }
  49. if flag < 0 {
  50. log.Println("--并发队列--", fmt.Errorf("暂无数据"))
  51. return &bxcore.PurchaseResp{}, nil
  52. }
  53. }
  54. list, err := ps.GetPurchaseData()
  55. if err == nil && len(list) > 0 {
  56. res.Data.List = list
  57. }
  58. res.Data.PageNum = ps.PageNum
  59. res.Data.PageSize = ps.PageSize
  60. res.Data.TipMsg = ps.TipMsg
  61. res.Data.HighlightWords = ps.HighlightWords
  62. res.Data.Total = ps.Total
  63. res.Data.Count = ps.Count
  64. res.Data.Keywords = ps.HighlightWords
  65. res.Data.InterceptLimit = int64(MC.IntAllDef(IC.C.KeywordsLimit, 35))
  66. res.Data.InterceptKeywords = ps.InterceptKeyWords
  67. res.Data.InterceptOtherWords = ps.TipMsg
  68. return res, err
  69. }