supplyinfosearchlogic.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package logic
  2. import (
  3. "context"
  4. "app.yhyue.com/moapp/jyInfo/rpc/model/es"
  5. "log"
  6. "strconv"
  7. "strings"
  8. se "app.yhyue.com/moapp/jybase/encrypt"
  9. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
  10. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  11. "app.yhyue.com/moapp/jybase/common"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type SupplyInfoSearchLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewSupplyInfoSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplyInfoSearchLogic {
  20. return &SupplyInfoSearchLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. // 供应信息查询
  27. func (l *SupplyInfoSearchLogic) SupplyInfoSearch(in *consumer.SupplyInfoSearchReq) (*consumer.SupplyInfoSearchResp, error) {
  28. //默认每页五十条
  29. if in.PageSize == 0 {
  30. in.PageSize = 50
  31. }
  32. //默认第一页
  33. if in.PageIndex == 0 {
  34. in.PageIndex = 1
  35. }
  36. //空格多个关键词
  37. if strings.Contains(in.Keywords, "+") {
  38. in.Keywords = strings.ReplaceAll(in.Keywords, " ", "+")
  39. }
  40. list, total := model.GetSupplyInfoList(in)
  41. var infos []*consumer.SupplyList
  42. if len(*list) > 0 {
  43. for _, v := range *list {
  44. detail := []string{}
  45. if v["highlight"] != nil {
  46. highlight, ok := v["highlight"].(map[string][]string)
  47. if ok && highlight["detail"] != nil {
  48. detail = highlight["detail"]
  49. }
  50. }
  51. info := consumer.SupplyList{
  52. Title: common.InterfaceToStr(v["title"]),
  53. Detail: common.InterfaceToStr(v["detail"]),
  54. Id: se.SE.EncodeString(common.InterfaceToStr(v["_id"])),
  55. Province: common.InterfaceToStr(v["province"]),
  56. City: common.InterfaceToStr(v["city"]),
  57. PublishTime: strconv.FormatInt(common.Int64All(v["publish_time"]), 10),
  58. Highlight: detail,
  59. }
  60. infos = append(infos, &info)
  61. }
  62. log.Println("infos:", infos)
  63. return &consumer.SupplyInfoSearchResp{
  64. Data: &consumer.SupplyInfo{
  65. Total: total,
  66. List: infos,
  67. },
  68. }, nil
  69. }
  70. return &consumer.SupplyInfoSearchResp{
  71. ErrCode: -1,
  72. ErrMsg: "暂无数据",
  73. }, nil
  74. }