12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package bus
- import (
- "assetcenter/db"
- "assetcenter/db/repo"
- "context"
- "fmt"
- "github.com/nats-io/nats.go"
- "infish.cn/comm"
- )
- func RegTreeAssetDetailMeshPack() *comm.NatsMsgReplyer {
- return &comm.NatsMsgReplyer{
- Subject: "tree.asset.detail.pack",
- Entity: func() interface{} { return &AssetReq{} },
- Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
- req, ok := entity.(*AssetReq)
- if !ok {
- return nil, fmt.Errorf("参数错误不是AssetReq类型")
- }
- if len(req.DbName) < 1 || len(req.Collection) < 1 || len(req.AssetId) < 1 {
- return nil, fmt.Errorf("DbName Collection AssetId 不能为空")
- }
- var CreateRepoCtx = func() *repo.RepoSession {
- return &repo.RepoSession{
- Ctx: context.Background(),
- Client: db.MongoClient,
- }
- }
- out := &comm.AssetPackage{}
- ok, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{Db: req.DbName, CollectName: req.Collection, Query: repo.Map{"_id": req.AssetId}}, out)
- if err != nil {
- return nil, err
- }
- if !ok {
- return nil, fmt.Errorf("查询的色卡不存在")
- }
- return out, nil
- },
- }
- }
|