supplyinfosearchlogic.go 2.6 KB

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