1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package logic
- import (
- IC "app.yhyue.com/moapp/jyInfo/rpc/consumer/init"
- "app.yhyue.com/moapp/jyInfo/rpc/model/es"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- "context"
- "log"
- "strconv"
- "strings"
- se "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
- "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type SupplyInfoSearchLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewSupplyInfoSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplyInfoSearchLogic {
- return &SupplyInfoSearchLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 供应信息查询
- func (l *SupplyInfoSearchLogic) SupplyInfoSearch(in *consumerinfo.SupplyInfoSearchReq) (*consumerinfo.SupplyInfoSearchResp, error) {
- //默认每页五十条
- if in.PageSize == 0 {
- in.PageSize = 50
- }
- //默认第一页
- if in.PageIndex == 0 {
- in.PageIndex = 1
- }
- //空格多个关键词
- if strings.Contains(in.Keywords, "+") {
- in.Keywords = strings.ReplaceAll(in.Keywords, " ", "+")
- }
- list, total := model.GetSupplyInfoList(in)
- logx.Info(list, "-------", total)
- if total == 0 && len([]rune(in.Keywords)) > 3 {
- if secondKWS := util.HttpEsGetWords(in.Keywords, "ik_smart", IC.C.Es.Addr); secondKWS != "" {
- log.Println("secondKWS:", secondKWS)
- in.Keywords = secondKWS
- list, total = model.GetSupplyInfoList(in)
- }
- }
- var infos []*consumerinfo.SupplyList
- if len(*list) > 0 {
- for _, v := range *list {
- detail := []string{}
- if v["highlight"] != nil {
- highlight, ok := v["highlight"].(map[string][]string)
- if ok && highlight["detail"] != nil {
- detail = highlight["detail"]
- }
- }
- logx.Info(se.SE.EncodeString(common.InterfaceToStr(v["_id"])), "---------", common.InterfaceToStr(v["_id"]))
- info := consumerinfo.SupplyList{
- Title: common.InterfaceToStr(v["title"]),
- Detail: common.InterfaceToStr(v["detail"]),
- Id: se.SE.EncodeString(common.InterfaceToStr(v["_id"])),
- Province: common.InterfaceToStr(v["province"]),
- City: common.InterfaceToStr(v["city"]),
- PublishTime: strconv.FormatInt(common.Int64All(v["publish_time"]), 10),
- Highlight: detail,
- }
- infos = append(infos, &info)
- }
- log.Println("infos:", infos)
- return &consumerinfo.SupplyInfoSearchResp{
- Data: &consumerinfo.SupplyInfo{
- Total: total,
- List: infos,
- },
- }, nil
- }
- return &consumerinfo.SupplyInfoSearchResp{
- ErrCode: -1,
- ErrMsg: "暂无数据",
- }, nil
- }
|