service-database-package.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package api
  2. import (
  3. "assetcenter/bus"
  4. "assetcenter/conf"
  5. "assetcenter/db/repo"
  6. funcgraph "assetcenter/funcGraph"
  7. "time"
  8. "go.mongodb.org/mongo-driver/bson/primitive"
  9. "infish.cn/comm"
  10. )
  11. func UpdateAssetPackageComm(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetPackage) (interface{}, error) {
  12. asset := body
  13. asset.UpdateTime = time.Now()
  14. if conf.AppConfig.IsSaveLocal() {
  15. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  16. }
  17. id := asset.Id.Hex()
  18. asset.Id = primitive.NilObjectID
  19. collectionName := dbConf.AssetConf.Collection
  20. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  21. }
  22. type OsgConvRequest struct {
  23. AssetId string `json:"assetId"`
  24. DbId string `json:"dbId"`
  25. Table string `json:"table"`
  26. MeshUrl string `json:"meshUrl"`
  27. LocalPath string `json:"localPath"`
  28. WkDir string `json:"wkDir"`
  29. }
  30. func UploadAssetPackage(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetPackage) (interface{}, error) {
  31. asset := body
  32. asset.Enable = BoolValue(false)
  33. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  34. transTask := asset.TransTask
  35. shadowTask := asset.ShadowTask
  36. if comm.TransTaskIsNotEmpty(transTask) {
  37. // 转换文件存在,更新状态
  38. asset.Source = nil
  39. }
  40. asset.CreateTime = time.Now()
  41. asset.UpdateTime = time.Now()
  42. collectionName := dbConf.AssetConf.Collection
  43. assetId, err := repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  44. if err != nil {
  45. return nil, err
  46. }
  47. url, err := bus.NatsCenter.RequestConfig("bus-network")
  48. if err != nil {
  49. return nil, err
  50. }
  51. if comm.TransTaskIsNotEmpty(transTask) {
  52. // 模型转换
  53. funcgraph.OsgConvRequest(transTask.File.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection, url)
  54. }
  55. if comm.ShadowIsNotEmpty(shadowTask) {
  56. // 阴影转换
  57. funcgraph.CreateShadow(shadowTask.File.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection, 15, 512, url)
  58. }
  59. return assetId, err
  60. }
  61. func UpdateAssetPackageSource(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetPackage) (interface{}, error) {
  62. asset := body
  63. asset.UpdateTime = time.Now()
  64. id := asset.Id.Hex()
  65. asset.Id = primitive.NilObjectID
  66. if conf.AppConfig.IsSaveLocal() {
  67. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  68. }
  69. collectionName := dbConf.AssetConf.Collection
  70. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  71. }