package bus import ( "assetcenter/db" "assetcenter/db/repo" "context" "fmt" "github.com/nats-io/nats.go" "infish.cn/comm" ) type BusTreeSearchImageReq struct { DbName string Coll string Result []*MlivusSearchRes } // func BusTreeSearchImage(req *BusTreeSearchImageReq) (out interface{}, err error) { // err = NatsCenter.RequestPackApi("tree.search.image", // req, // &out, &comm.RequestOptions{ // DeployPack: "queentree", // }) // return out, err // } func RegTreeSearchImage() *comm.NatsMsgReplyer { return &comm.NatsMsgReplyer{ Subject: "tree.search.image", Entity: func() interface{} { return &BusTreeSearchImageReq{} }, Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) { req, ok := entity.(*BusTreeSearchImageReq) if !ok { return nil, fmt.Errorf("参数错误不是BusTreeSearchImageReq类型") } fmt.Println(*req) var CreateRepoCtx = func() *repo.RepoSession { return &repo.RepoSession{ Ctx: context.Background(), Client: db.MongoClient, } } handleLists := make([]map[string]interface{}, 0) for _, list := range req.Result { handleList := make(map[string]interface{}) found, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{ Db: req.DbName, CollectName: req.Coll, Query: repo.Map{"_id": list.ProductId}, }, handleList) if !found || err != nil { continue } handleList["score"] = list.Score handleList["imHash"] = list.ImHash handleLists = append(handleLists, handleList) } return handleLists, nil }, } }