service-database-package.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package api
  2. import (
  3. "mats/db/model"
  4. "mats/db/repo"
  5. funcgraph "mats/funcGraph"
  6. "time"
  7. "go.mongodb.org/mongo-driver/bson"
  8. "go.mongodb.org/mongo-driver/bson/primitive"
  9. )
  10. func UpdateAssetPackageComm(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetPackage) (interface{}, error) {
  11. asset := body
  12. asset.UpdateTime = time.Now()
  13. id := asset.Id.Hex()
  14. asset.Id = primitive.NilObjectID
  15. collectionName := dbConf.AssetConf.Collection
  16. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  17. }
  18. func UploadAssetPackage(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetPackage) (interface{}, error) {
  19. asset := body
  20. asset.Enable = BoolValue(false)
  21. source := asset.Source.Geoms[0]
  22. if source == nil || source.Glb.Size < 1 || len(source.Glb.Url) < 1 {
  23. asset.AssetState = model.AssetState_Empty
  24. } else {
  25. asset.AssetState = model.AssetState_Waiting
  26. }
  27. asset.CreateTime = time.Now()
  28. asset.UpdateTime = time.Now()
  29. collectionName := dbConf.AssetConf.Collection
  30. assetId, err := repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  31. if err != nil {
  32. return nil, err
  33. }
  34. if asset.AssetState == model.AssetState_Waiting { //模型转换请求
  35. // err = bus.NatsCenter.MeshAssetProcessReq(dbConf.Db.Name, dbConf.AssetConf.Collection, assetId, source.Glb.Url, apictx.User.ID)
  36. // if err != nil {
  37. // update := bson.M{"$set": bson.M{"assetState": model.AssetState_Failed}}
  38. // repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, assetId, update)
  39. // }
  40. err = funcgraph.OsgConvRequest(source.Glb.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection)
  41. if err != nil {
  42. update := bson.M{"$set": bson.M{"assetState": model.AssetState_Failed}}
  43. repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, assetId, update)
  44. }
  45. funcgraph.CreateShadow(source.Glb.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection, 15, 512)
  46. }
  47. return assetId, err
  48. }
  49. func UpdateAssetPackageSource(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetPackage) (interface{}, error) {
  50. asset := body
  51. asset.UpdateTime = time.Now()
  52. id := asset.Id.Hex()
  53. asset.Id = primitive.NilObjectID
  54. collectionName := dbConf.AssetConf.Collection
  55. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  56. }