tileResult.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package bus
  2. import (
  3. "3dshow-supplier/conf"
  4. "3dshow-supplier/db"
  5. "3dshow-supplier/db/model"
  6. "3dshow-supplier/db/repo"
  7. "context"
  8. "fmt"
  9. "strings"
  10. "github.com/nats-io/nats.go"
  11. "infish.cn/comm"
  12. )
  13. type TileConvertorResult struct {
  14. AssetId string `json:"assetId"`
  15. GroupId string `json:"groupId"`
  16. SourcePath string `json:"sourcePath"`
  17. TilePath string `json:"tilePath"`
  18. }
  19. func CreateTileConvResultWather(app *conf.AppConf) *comm.NatsStreamWather {
  20. topics := strings.Split(app.Nats.TileConvStreamTopic, "#")
  21. return &comm.NatsStreamWather{
  22. Stream: topics[0],
  23. Topic: topics[1],
  24. Queue: topics[2],
  25. Entity: func() interface{} { return &TileConvertorResult{} },
  26. Cb: func(msg *nats.Msg, entity interface{}) {
  27. result := entity.(*TileConvertorResult)
  28. if len(result.TilePath) < 1 || len(result.AssetId) < 1 || len(result.GroupId) < 1 {
  29. msg.AckSync()
  30. return
  31. }
  32. err := RepoTileConvResult(result)
  33. if err != nil {
  34. msg.Nak()
  35. return
  36. }
  37. msg.AckSync()
  38. },
  39. }
  40. }
  41. func CreateRepoCtx() *repo.RepoSession {
  42. return &repo.RepoSession{
  43. Client: db.MongoClient,
  44. Ctx: context.Background(),
  45. }
  46. }
  47. func RepoTileConvResult(data *TileConvertorResult) error {
  48. fmt.Println("RepoTileConvResult", data.AssetId, data.GroupId, data.TilePath)
  49. asset := &model.Asset360Fake3d{}
  50. ok, _ := repo.RepoSeachDoc(CreateRepoCtx(), &repo.DocSearchOptions{
  51. CollectName: repo.CollectionAssets,
  52. Query: repo.Map{"_id": data.AssetId},
  53. }, asset)
  54. if !ok {
  55. fmt.Println("RepoTileConvResult will be loss no asset find")
  56. return nil
  57. }
  58. if asset.Groups != nil {
  59. for _, g := range asset.Groups {
  60. if g.Id == data.GroupId {
  61. host := "https://www.3dqueen.cloud/asset360/index.html?apath="
  62. g.Url = fmt.Sprintf("%s%s", host, data.TilePath)
  63. g.State = model.GROUPSTATE_SUCC
  64. }
  65. }
  66. }
  67. ret, err := repo.RepoUpdateSetDoc(CreateRepoCtx(), repo.CollectionAssets, data.AssetId, asset)
  68. fmt.Println("RepoTileConvResult update state=>", ret)
  69. return err
  70. }