service-database-upload.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 UpdateStaticMeshComm(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetStaticMesh) (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 UpdateStaticMeshSource(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetStaticMesh) (interface{}, error) {
  19. asset := body
  20. asset.UpdateTime = time.Now()
  21. id := asset.Id.Hex()
  22. asset.Id = primitive.NilObjectID
  23. collectionName := dbConf.AssetConf.Collection
  24. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  25. }
  26. func ProcessPackage(apictx *ApiSession, dbConf *model.AssetDbConf, id string) (interface{}, error) {
  27. mesh := &model.AssetPackage{}
  28. ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
  29. Db: dbConf.Db.Name,
  30. CollectName: dbConf.AssetConf.Collection,
  31. Query: repo.Map{"_id": id},
  32. Project: []string{"source.geoms"},
  33. }, mesh)
  34. if err != nil {
  35. return nil, err
  36. }
  37. if !ok {
  38. return nil, NewError("模型已删除!")
  39. }
  40. if mesh.Source == nil || len(mesh.Source.Geoms) < 1 {
  41. return nil, NewError("数据模型异常!")
  42. }
  43. geom := mesh.Source.Geoms[0]
  44. meshUrl := ""
  45. if geom.File != nil {
  46. meshUrl = geom.File.Url
  47. }
  48. if geom.Glb != nil && len(geom.Glb.Url) > 0 {
  49. meshUrl = geom.Glb.Url
  50. }
  51. if len(meshUrl) < 1 {
  52. return nil, NewError("数据模型异常!")
  53. }
  54. err = funcgraph.OsgConvRequest(meshUrl, id, dbConf.Db.Name, dbConf.AssetConf.Collection)
  55. assetState := model.AssetState_Waiting
  56. if err != nil {
  57. assetState = model.AssetState_Failed
  58. }
  59. update := bson.M{"$set": bson.M{"assetState": assetState}}
  60. return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, dbConf.AssetConf.Collection, id, update)
  61. }
  62. func ProcessPackageShadow(apictx *ApiSession, dbConf *model.AssetDbConf, id string, scale, width int32) (interface{}, error) {
  63. mesh := &model.AssetPackage{}
  64. ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
  65. Db: dbConf.Db.Name,
  66. CollectName: dbConf.AssetConf.Collection,
  67. Query: repo.Map{"_id": id},
  68. Project: []string{"source.geoms"},
  69. }, mesh)
  70. if err != nil {
  71. return nil, err
  72. }
  73. if !ok {
  74. return nil, NewError("模型已删除!")
  75. }
  76. if mesh.Source == nil || len(mesh.Source.Geoms) < 1 {
  77. return nil, NewError("数据模型异常!")
  78. }
  79. geom := mesh.Source.Geoms[0]
  80. meshUrl := ""
  81. if geom.File != nil {
  82. meshUrl = geom.File.Url
  83. }
  84. if geom.Glb != nil && len(geom.Glb.Url) > 0 {
  85. meshUrl = geom.Glb.Url
  86. }
  87. if len(meshUrl) < 1 {
  88. return nil, NewError("数据模型异常!")
  89. }
  90. err = funcgraph.CreateShadow(meshUrl, id, dbConf.Db.Name, dbConf.AssetConf.Collection, scale, width)
  91. return true, err
  92. }