123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package bus
- import (
- "assetcenter/conf"
- "assetcenter/db"
- "assetcenter/db/repo"
- "assetcenter/log"
- "context"
- "fmt"
- "go.mongodb.org/mongo-driver/bson"
- "infish.cn/comm"
- )
- const (
- AssetState_Empty = 0
- AssetState_Waiting = 100 //等待处理
- AssetState_Proccing = 101 //正在处理
- AssetState_Failed = 102 //处理失败!
- AssetState_Succ = 200 //处理成功
- )
- func CreateRepoCtx() *repo.RepoSession {
- return &repo.RepoSession{
- Client: db.MongoClient,
- Ctx: context.Background(),
- }
- }
- func RepoOsgconvResult(data *OsgConvertorResult) error {
- fmt.Println("begin update asset state=>", data.DbId, data.Table)
- log.Info("osgconv result: ", *data)
- // 查询源资源文档,是否存在config.source
- // 存在,下载源source文件,更新对应模型路径后上传到原本位置
- asset := &comm.AssetPackage{}
- _, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
- Db: data.DbId,
- CollectName: data.Table,
- Query: repo.Map{"_id": data.AssetId},
- Project: []string{"transTask"},
- }, asset)
- if err != nil {
- log.Info("%#v/n", data)
- log.Info("查询资源错误", err)
- return err
- }
- update := bson.M{}
- if comm.TransTaskIsNotEmpty(asset.TransTask) {
- update["transTask.osgjs"] = &comm.OssType{
- Url: data.Osgjs.Url,
- Size: data.Osgjs.Size,
- }
- }
- if conf.AppConfig.IsSaveLocal() {
- data.Osgjs.Url = conf.AppConfig.TrimSaveLocalUrl(data.Osgjs.Url)
- }
- log.Info("osgconv更新条件:", update)
- ret, err := repo.RepoUpdateSetDbDocProps(CreateRepoCtx(), data.DbId, data.Table, data.AssetId, bson.M{"$set": update})
- fmt.Println("RepoOsgconvResult update state=>", ret)
- log.Infof("osgconv更新结果:%#v,err:%#v", ret, err)
- return err
- }
- func RepoShadowResult(data *OsgShadowResult) error {
- log.Infof("shadow result: %#v\n", *data)
- asset := &comm.AssetPackage{}
- _, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
- Db: data.DbId,
- CollectName: data.Table,
- Query: repo.Map{"_id": data.AssetId},
- Project: []string{"source", "config"},
- }, asset)
- if err != nil {
- log.Info("%#v/n", data)
- log.Info("查询资源错误", err)
- return err
- }
- update := bson.M{}
- if len(asset.Config) > 0 {
- // 解析文件拿到file
- // 更新到 shadowTask
- source := &comm.Queen3dPackageSource{}
- err := comm.FetchAndParseJSON(asset.Config, source)
- if err != nil {
- log.Error("shadow parse json err: ", err)
- return err
- }
- update["shadowTask"] = &comm.ShadowTask{
- File: &comm.TransFile{
- Id: source.Geoms[0].Id,
- Url: source.Geoms[0].File.Url,
- },
- Shadow: &comm.OssType{
- Url: data.Shadow.Url,
- Size: data.Shadow.Size,
- },
- }
- } else if asset.Source != nil {
- update["source.geoms.0.shadow"] = data.Shadow
- }
- ret, err := repo.RepoUpdateSetDbDocProps(CreateRepoCtx(), data.DbId, data.Table, data.AssetId, bson.M{"$set": update})
- fmt.Println("updated shadow=>", ret)
- return err
- }
|