draft.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package article
  2. import (
  3. "context"
  4. artMdl "go-common/app/interface/main/creative/model/article"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "strconv"
  9. "strings"
  10. )
  11. // AddDraft add draft.
  12. func (d *Dao) AddDraft(c context.Context, art *artMdl.ArtParam) (id int64, err error) {
  13. var arg = &model.ArgArticle{
  14. Aid: art.AID,
  15. Mid: art.MID,
  16. Category: art.Category,
  17. State: art.State,
  18. Reprint: art.Reprint,
  19. TemplateID: art.TemplateID,
  20. Title: art.Title,
  21. BannerURL: art.BannerURL,
  22. Content: art.Content,
  23. Summary: art.Summary,
  24. RealIP: art.RealIP,
  25. Words: art.Words,
  26. DynamicIntro: art.DynamicIntro,
  27. ImageURLs: art.ImageURLs,
  28. OriginImageURLs: art.OriginImageURLs,
  29. }
  30. if art.Tags != "" {
  31. arg.Tags = strings.Split(art.Tags, ",")
  32. } else {
  33. arg.Tags = []string{}
  34. }
  35. log.Info("d.art.AddDraft id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
  36. if id, err = d.art.AddArtDraft(c, arg); err != nil {
  37. arg.Content = ""
  38. log.Error("d.art.AddArtDraft (%v) error(%v)", arg, err)
  39. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  40. err = ecode.CreativeArticleRPCErr
  41. }
  42. }
  43. return
  44. }
  45. // DelDraft delete draft.
  46. func (d *Dao) DelDraft(c context.Context, aid, mid int64, ip string) (err error) {
  47. var arg = &model.ArgAidMid{
  48. Aid: aid,
  49. Mid: mid,
  50. RealIP: ip,
  51. }
  52. if err = d.art.DelArtDraft(c, arg); err != nil {
  53. log.Error("d.art.DelArtDraft (%v) error(%v)", arg, err)
  54. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  55. err = ecode.CreativeArticleRPCErr
  56. }
  57. }
  58. return
  59. }
  60. // Draft get draft detail.
  61. func (d *Dao) Draft(c context.Context, aid, mid int64, ip string) (res *model.Draft, err error) {
  62. var arg = &model.ArgAidMid{
  63. Aid: aid,
  64. Mid: mid,
  65. RealIP: ip,
  66. }
  67. if res, err = d.art.ArtDraft(c, arg); err != nil {
  68. log.Error("d.art.ArtDraft (%v) error(%v)", arg, err)
  69. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  70. err = ecode.CreativeArticleRPCErr
  71. }
  72. }
  73. if res == nil || res.Meta == nil {
  74. return
  75. }
  76. log.Info("d.art.CreationArticle id (%d) words (%d)", res.Meta.ID, len(res.Content))
  77. return
  78. }
  79. // Drafts get draft list.
  80. func (d *Dao) Drafts(c context.Context, mid int64, pn, ps int, ip string) (res *model.Drafts, err error) {
  81. var arg = &model.ArgUpDraft{
  82. Mid: mid,
  83. Pn: pn,
  84. Ps: ps,
  85. RealIP: ip,
  86. }
  87. if res, err = d.art.UpperDrafts(c, arg); err != nil {
  88. log.Error("d.art.UpperDrafts (%v) error(%v)", arg, err)
  89. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  90. err = ecode.CreativeArticleRPCErr
  91. }
  92. }
  93. return
  94. }