123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package bus
- import (
- "3dshow-supplier/conf"
- "3dshow-supplier/db"
- "3dshow-supplier/db/model"
- "3dshow-supplier/db/repo"
- "context"
- "fmt"
- "strings"
- "github.com/nats-io/nats.go"
- "infish.cn/comm"
- )
- type TileConvertorResult struct {
- AssetId string `json:"assetId"`
- GroupId string `json:"groupId"`
- SourcePath string `json:"sourcePath"`
- TilePath string `json:"tilePath"`
- }
- func CreateTileConvResultWather(app *conf.AppConf) *comm.NatsStreamWather {
- topics := strings.Split(app.Nats.TileConvStreamTopic, "#")
- return &comm.NatsStreamWather{
- Stream: topics[0],
- Topic: topics[1],
- Queue: topics[2],
- Entity: func() interface{} { return &TileConvertorResult{} },
- Cb: func(msg *nats.Msg, entity interface{}) {
- result := entity.(*TileConvertorResult)
- if len(result.TilePath) < 1 || len(result.AssetId) < 1 || len(result.GroupId) < 1 {
- msg.AckSync()
- return
- }
- err := RepoTileConvResult(result)
- if err != nil {
- msg.Nak()
- return
- }
- msg.AckSync()
- },
- }
- }
- func CreateRepoCtx() *repo.RepoSession {
- return &repo.RepoSession{
- Client: db.MongoClient,
- Ctx: context.Background(),
- }
- }
- func RepoTileConvResult(data *TileConvertorResult) error {
- fmt.Println("RepoTileConvResult", data.AssetId, data.GroupId, data.TilePath)
- asset := &model.Asset360Fake3d{}
- ok, _ := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
- CollectName: repo.CollectionAssets,
- Query: repo.Map{"_id": data.AssetId},
- }, asset)
- if !ok {
- fmt.Println("RepoTileConvResult will be loss no asset find")
- return nil
- }
- if asset.Groups != nil {
- for _, g := range asset.Groups {
- if g.Id == data.GroupId {
- host := "https://www.3dqueen.cloud/asset360/index.html?apath="
- g.Url = fmt.Sprintf("%s%s", host, data.TilePath)
- g.State = model.GROUPSTATE_SUCC
- }
- }
- }
- ret, err := repo.RepoUpdateSetDoc(CreateRepoCtx(), repo.CollectionAssets, data.AssetId, asset)
- fmt.Println("RepoTileConvResult update state=>", ret)
- return err
- }
|