package logic import ( "context" "app.yhyue.com/moapp/jyInfo/rpc/model/es" "log" "strconv" "strings" se "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer" "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 *consumer.SupplyInfoSearchReq) (*consumer.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) var infos []*consumer.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"] } } info := consumer.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 &consumer.SupplyInfoSearchResp{ Data: &consumer.SupplyInfo{ Total: total, List: infos, }, }, nil } return &consumer.SupplyInfoSearchResp{ ErrCode: -1, ErrMsg: "暂无数据", }, nil }