mongo.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package bus
  2. import (
  3. "assetcenter/conf"
  4. "assetcenter/db"
  5. "assetcenter/db/repo"
  6. "assetcenter/log"
  7. "context"
  8. "fmt"
  9. "go.mongodb.org/mongo-driver/bson"
  10. "infish.cn/comm"
  11. )
  12. const (
  13. AssetState_Empty = 0
  14. AssetState_Waiting = 100 //等待处理
  15. AssetState_Proccing = 101 //正在处理
  16. AssetState_Failed = 102 //处理失败!
  17. AssetState_Succ = 200 //处理成功
  18. )
  19. func CreateRepoCtx() *repo.RepoSession {
  20. return &repo.RepoSession{
  21. Client: db.MongoClient,
  22. Ctx: context.Background(),
  23. }
  24. }
  25. func RepoOsgconvResult(data *OsgConvertorResult) error {
  26. fmt.Println("begin update asset state=>", data.DbId, data.Table)
  27. log.Info("osgconv result: ", *data)
  28. // 查询源资源文档,是否存在config.source
  29. // 存在,下载源source文件,更新对应模型路径后上传到原本位置
  30. asset := &comm.AssetPackage{}
  31. _, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
  32. Db: data.DbId,
  33. CollectName: data.Table,
  34. Query: repo.Map{"_id": data.AssetId},
  35. Project: []string{"transTask"},
  36. }, asset)
  37. if err != nil {
  38. log.Info("%#v/n", data)
  39. log.Info("查询资源错误", err)
  40. return err
  41. }
  42. update := bson.M{}
  43. if comm.TransTaskIsNotEmpty(asset.TransTask) {
  44. update["transTask.osgjs"] = &comm.OssType{
  45. Url: data.Osgjs.Url,
  46. Size: data.Osgjs.Size,
  47. }
  48. }
  49. if conf.AppConfig.IsSaveLocal() {
  50. data.Osgjs.Url = conf.AppConfig.TrimSaveLocalUrl(data.Osgjs.Url)
  51. }
  52. log.Info("osgconv更新条件:", update)
  53. ret, err := repo.RepoUpdateSetDbDocProps(CreateRepoCtx(), data.DbId, data.Table, data.AssetId, bson.M{"$set": update})
  54. fmt.Println("RepoOsgconvResult update state=>", ret)
  55. log.Infof("osgconv更新结果:%#v,err:%#v", ret, err)
  56. return err
  57. }
  58. func RepoShadowResult(data *OsgShadowResult) error {
  59. log.Infof("shadow result: %#v\n", *data)
  60. asset := &comm.AssetPackage{}
  61. _, err := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
  62. Db: data.DbId,
  63. CollectName: data.Table,
  64. Query: repo.Map{"_id": data.AssetId},
  65. Project: []string{"source", "config"},
  66. }, asset)
  67. if err != nil {
  68. log.Info("%#v/n", data)
  69. log.Info("查询资源错误", err)
  70. return err
  71. }
  72. update := bson.M{}
  73. if len(asset.Config) > 0 {
  74. // 解析文件拿到file
  75. // 更新到 shadowTask
  76. source := &comm.Queen3dPackageSource{}
  77. err := comm.FetchAndParseJSON(asset.Config, source)
  78. if err != nil {
  79. log.Error("shadow parse json err: ", err)
  80. return err
  81. }
  82. update["shadowTask"] = &comm.ShadowTask{
  83. File: &comm.TransFile{
  84. Id: source.Geoms[0].Id,
  85. Url: source.Geoms[0].File.Url,
  86. },
  87. Shadow: &comm.OssType{
  88. Url: data.Shadow.Url,
  89. Size: data.Shadow.Size,
  90. },
  91. }
  92. } else if asset.Source != nil {
  93. update["source.geoms.0.shadow"] = data.Shadow
  94. }
  95. ret, err := repo.RepoUpdateSetDbDocProps(CreateRepoCtx(), data.DbId, data.Table, data.AssetId, bson.M{"$set": update})
  96. fmt.Println("updated shadow=>", ret)
  97. return err
  98. }