12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package repo
- import (
- "errors"
- "mats/conf"
- "mats/db/model"
- "time"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- type ProjectDecorateRepo struct {
- Conf *conf.AppAsset
- Model *model.AssetDecorateMesh
- }
- func (repo *ProjectDecorateRepo) GetEntity() interface{} {
- return repo.Model
- }
- func (repo *ProjectDecorateRepo) Upload(ctx *RepoSession, userId string) (interface{}, error) {
- asset := repo.Model
- if asset.File == nil || asset.File.Size < 1 || len(asset.File.Url) < 1 {
- return nil, errors.New("模型文件不能为空")
- }
- asset.CreateTime = time.Now()
- asset.UserId, _ = primitive.ObjectIDFromHex(userId)
- asset.UpdateTime = time.Now()
- asset.State = model.AssetState_Created
- collectionName := "asset-" + repo.Conf.Type
- assetId, err := RepoAddDoc(ctx, collectionName, asset)
- if err != nil {
- return nil, err
- }
- _, err = CreateMeshConvTask(ctx, asset.File, assetId, collectionName, userId)
- if err != nil { //模型转换失败,删除对应的模型
- RepoDeleteDoc(ctx, collectionName, assetId)
- return nil, err
- }
- // _, err = CreateShadowTask(ctx, asset.File, assetId, collectionName, userId)
- // if err != nil {
- // log.Error("CreateShadowTask err ", err)
- // fmt.Println("CreateShadowTask err ", err)
- // }
- return assetId, err
- }
- func (repo *ProjectDecorateRepo) Update(ctx *RepoSession) (interface{}, error) {
- asset := repo.Model
- if len(asset.Id) < 1 {
- return nil, errors.New("id不能为空!")
- }
- id := asset.Id.Hex()
- asset.Id = primitive.NilObjectID
- asset.UpdateTime = time.Now()
- collectionName := "asset-" + repo.Conf.Type
- return RepoUpdateSetDoc(ctx, collectionName, id, asset)
- }
- func (repo *ProjectDecorateRepo) Detail(ctx *RepoSession, id string) (interface{}, error) {
- return nil, errors.New("no impl")
- }
|