service-database-upload-mat.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package api
  2. import (
  3. "assetcenter/conf"
  4. "assetcenter/db/model"
  5. "assetcenter/db/repo"
  6. "time"
  7. "go.mongodb.org/mongo-driver/bson/primitive"
  8. "infish.cn/comm"
  9. )
  10. func UploadMaterial(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) {
  11. asset := body
  12. // source := asset.Source
  13. asset.Enable = BoolValue(false)
  14. asset.AssetState = model.AssetState_Succ
  15. if conf.AppConfig.IsSaveLocal() {
  16. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  17. }
  18. asset.CreateTime = time.Now()
  19. asset.UpdateTime = time.Now()
  20. collectionName := dbConf.AssetConf.Collection
  21. return repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  22. }
  23. func UploadMaterialGroup(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMatGroup) (interface{}, error) {
  24. asset := body
  25. // source := asset.Source
  26. asset.Enable = BoolValue(false)
  27. asset.AssetState = model.AssetState_Succ
  28. if conf.AppConfig.IsSaveLocal() {
  29. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  30. }
  31. asset.CreateTime = time.Now()
  32. asset.UpdateTime = time.Now()
  33. collectionName := dbConf.AssetConf.Collection
  34. return repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  35. }
  36. func UpdateMaterialGroup(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMatGroup) (interface{}, error) {
  37. asset := body
  38. asset.UpdateTime = time.Now()
  39. id := asset.Id.Hex()
  40. asset.Id = primitive.NilObjectID
  41. if conf.AppConfig.IsSaveLocal() {
  42. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  43. }
  44. collectionName := dbConf.AssetConf.Collection
  45. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  46. }
  47. func UpdateMaterialComm(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) {
  48. asset := body
  49. asset.UpdateTime = time.Now()
  50. id := asset.Id.Hex()
  51. asset.Id = primitive.NilObjectID
  52. if conf.AppConfig.IsSaveLocal() {
  53. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  54. }
  55. collectionName := dbConf.AssetConf.Collection
  56. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  57. }
  58. func UpdateMaterialSource(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) {
  59. asset := body
  60. asset.UpdateTime = time.Now()
  61. id := asset.Id.Hex()
  62. asset.Id = primitive.NilObjectID
  63. if conf.AppConfig.IsSaveLocal() {
  64. body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  65. }
  66. collectionName := dbConf.AssetConf.Collection
  67. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  68. }
  69. func ProcessMat(apictx *ApiSession, dbConf *comm.AssetDbConf, id string) (interface{}, error) {
  70. // mesh := &model.AssetMat{}
  71. // ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
  72. // Db: dbConf.DbName,
  73. // CollectName: dbConf.AssetConf.Collection,
  74. // Query: repo.Map{"_id": id},
  75. // Project: []string{"source.file"},
  76. // }, mesh)
  77. // if err != nil {
  78. // return nil, err
  79. // }
  80. // if !ok {
  81. // return nil, NewError("hdr已删除!")
  82. // }
  83. // err = bus.NatsCenter.HdrAssetProcessReq(dbConf.DbName, dbConf.AssetConf.Collection, id, mesh.Source.File.Url)
  84. // assetState := model.AssetState_Waiting
  85. // if err != nil {
  86. // assetState = model.AssetState_Failed
  87. // }
  88. // update := bson.M{"$set": bson.M{"assetState": assetState}}
  89. // return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.DbName, dbConf.AssetConf.Collection, id, update)
  90. return nil, NewError("no impl!")
  91. }