cardpreview.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package common
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/feed/model/common"
  6. showModel "go-common/app/admin/main/feed/model/show"
  7. account "go-common/app/service/main/account/model"
  8. "go-common/app/service/main/archive/api"
  9. seasondao "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
  10. "go-common/library/ecode"
  11. )
  12. //CardPreview card preview
  13. func (s *Service) CardPreview(c context.Context, cType string, id int64) (title string, err error) {
  14. var (
  15. accCard *account.Card
  16. appActive *showModel.AppActive
  17. eventTopic *showModel.EventTopic
  18. webCard *showModel.SearchWebCard
  19. seaCards map[int32]*seasondao.CardInfoProto
  20. arcCard *api.Arc
  21. )
  22. switch cType {
  23. case common.CardPgc:
  24. v := []int32{int32(id)}
  25. if seaCards, err = s.pgcDao.CardsInfoReply(c, v); err != nil {
  26. return
  27. }
  28. if v, ok := seaCards[int32(id)]; ok {
  29. return v.Title, nil
  30. }
  31. return "", fmt.Errorf("无效pgc卡片ID(%d)", id)
  32. case common.CardAv:
  33. if arcCard, err = s.arcDao.Archive3(c, id); err != nil {
  34. if err.Error() == ecode.NothingFound.Error() {
  35. return "", fmt.Errorf("无效稿件ID(%d)", id)
  36. }
  37. return
  38. }
  39. return arcCard.Title, nil
  40. case common.CardUp:
  41. if accCard, err = s.accDao.Card3(c, id); err != nil {
  42. if err.Error() == ecode.MemberNotExist.Error() {
  43. return "", fmt.Errorf("无效up主ID(%d)", id)
  44. }
  45. return
  46. }
  47. return accCard.Name, nil
  48. case common.CardChannelTab:
  49. if appActive, err = s.showDao.AAFindByID(c, int64(id)); err != nil {
  50. return "", err
  51. }
  52. if appActive == nil {
  53. return "", fmt.Errorf("无效tab卡片ID(%d)", id)
  54. }
  55. return appActive.Name, nil
  56. case common.CardEventTopic:
  57. if eventTopic, err = s.showDao.ETFindByID(id); err != nil {
  58. return "", err
  59. }
  60. if eventTopic == nil {
  61. return "", fmt.Errorf("无效事件专题卡片ID(%d)", id)
  62. }
  63. return eventTopic.Title, nil
  64. case common.CardSearchWeb:
  65. if webCard, err = s.showDao.SWBFindByID(id); err != nil {
  66. return "", err
  67. }
  68. if webCard == nil {
  69. return "", fmt.Errorf("无效web卡片ID(%d)", id)
  70. }
  71. return webCard.Title, nil
  72. default:
  73. err = fmt.Errorf("参数错误")
  74. return "", err
  75. }
  76. }