supplysearchlogic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package logic
  2. import (
  3. "context"
  4. "jyInfo/rpc/consumer/consumer"
  5. "strings"
  6. "app.yhyue.com/moapp/jybase/common"
  7. "jyInfo/api/internal/svc"
  8. "jyInfo/api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type SupplySearchLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewSupplySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplySearchLogic {
  17. return &SupplySearchLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *SupplySearchLogic) SupplySearch(req *types.PubSupplyInfoReq) (resp *types.CommonRes, err error) {
  24. //默认每页五十条
  25. if req.PageSize == 0 {
  26. req.PageSize = 50
  27. }
  28. //默认第一页
  29. if req.PageIndex == 0 {
  30. req.PageIndex = 1
  31. }
  32. //空格多个关键词
  33. if strings.Contains(req.Keywords, "+") {
  34. req.Keywords = strings.ReplaceAll(req.Keywords, " ", "+")
  35. }
  36. supplySearch, err0 := l.svcCtx.Consumer.SupplyInfoSearch(l.ctx, &consumer.SupplyInfoSearchReq{
  37. Keywords: req.Keywords,
  38. SearchType: req.SearchType,
  39. Province: req.Province,
  40. City: req.City,
  41. Time: req.Time,
  42. Status: req.Status,
  43. PageSize: req.PageSize,
  44. PageIndex: req.PageIndex,
  45. })
  46. if err0 != nil {
  47. return &types.CommonRes{
  48. Err_code: -1,
  49. Err_msg: "错误",
  50. Data: nil,
  51. }, nil
  52. }
  53. return &types.CommonRes{
  54. Err_code: common.IntAll(supplySearch.ErrCode),
  55. Err_msg: supplySearch.ErrMsg,
  56. Data: supplySearch.Data,
  57. }, nil
  58. }