purchasesearchlogic.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // 精准模式不足50条的非空标讯查询 匹配模糊查询数
  59. if ps.Total < IC.C.PaySearchLimit.PrecisionNum && in.SearchMode == 0 && !ps.IsEmptySearch() {
  60. ps.SearchMode = 1
  61. ps.FilterCriteriaFormat()
  62. res.Data.BCount = ps.GetPurchaseCount()
  63. log.Println("精准查询数据不足 匹配模糊查询数:", res.Data.BCount)
  64. }
  65. res.Data.PageNum = ps.PageNum
  66. res.Data.PageSize = ps.PageSize
  67. res.Data.TipMsg = ps.TipMsg
  68. res.Data.HighlightWords = ps.HighlightWords
  69. res.Data.Total = ps.Total
  70. res.Data.Count = ps.Count
  71. res.Data.KeyWords = ps.HighlightWords
  72. res.Data.InterceptLimit = int64(MC.IntAllDef(IC.C.KeywordsLimit, 35))
  73. res.Data.InterceptKeywords = ps.InterceptKeyWords
  74. res.Data.InterceptOtherWords = ps.TipMsg
  75. return res, err
  76. }