service-database-upload-mat.go 3.0 KB

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