article.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package article
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. "strconv"
  6. "strings"
  7. artMdl "go-common/app/interface/main/creative/model/article"
  8. "go-common/app/interface/openplatform/article/model"
  9. "go-common/library/ecode"
  10. )
  11. // Articles get article list.
  12. func (d *Dao) Articles(c context.Context, mid int64, pn, ps, sort, group, category int, ip string) (res *model.CreationArts, err error) {
  13. var arg = &model.ArgCreationArts{
  14. Mid: mid,
  15. Pn: pn,
  16. Ps: ps,
  17. Sort: sort,
  18. Group: group,
  19. Category: category,
  20. RealIP: ip,
  21. }
  22. if res, err = d.art.CreationUpperArticles(c, arg); err != nil {
  23. log.Error("d.art.CreationUpperArticles (%v) error(%v)", arg, err)
  24. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  25. err = ecode.CreativeArticleRPCErr
  26. }
  27. }
  28. return
  29. }
  30. // Categories list all category contain child.
  31. func (d *Dao) Categories(c context.Context, ip string) (res *model.Categories, err error) {
  32. var arg = &model.ArgIP{
  33. RealIP: ip,
  34. }
  35. if res, err = d.art.Categories(c, arg); err != nil {
  36. log.Error("d.art.Categories (%v) error(%v)", arg, err)
  37. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  38. err = ecode.CreativeArticleRPCErr
  39. }
  40. }
  41. return
  42. }
  43. // CategoriesMap list all category.
  44. func (d *Dao) CategoriesMap(c context.Context, ip string) (res map[int64]*model.Category, err error) {
  45. var arg = &model.ArgIP{
  46. RealIP: ip,
  47. }
  48. if res, err = d.art.CategoriesMap(c, arg); err != nil {
  49. log.Error("d.art.CategoriesMap (%v) error(%v)", arg, err)
  50. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  51. err = ecode.CreativeArticleRPCErr
  52. }
  53. }
  54. return
  55. }
  56. // Article get article detail.
  57. func (d *Dao) Article(c context.Context, aid, mid int64, ip string) (res *model.Article, err error) {
  58. var arg = &model.ArgAidMid{
  59. Aid: aid,
  60. Mid: mid,
  61. RealIP: ip,
  62. }
  63. if res, err = d.art.CreationArticle(c, arg); err != nil {
  64. log.Error("d.art.CreationArticle (%v) error(%v)", arg, err)
  65. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  66. err = ecode.CreativeArticleRPCErr
  67. }
  68. }
  69. if res == nil || res.Meta == nil {
  70. return
  71. }
  72. log.Info("d.art.CreationArticle id (%d) words (%d)", res.Meta.ID, len(res.Content))
  73. return
  74. }
  75. // AddArticle add article.
  76. func (d *Dao) AddArticle(c context.Context, art *artMdl.ArtParam) (id int64, err error) {
  77. var arg = &model.ArgArticle{
  78. Aid: art.AID,
  79. Mid: art.MID,
  80. Category: art.Category,
  81. State: art.State,
  82. Reprint: art.Reprint,
  83. TemplateID: art.TemplateID,
  84. Title: art.Title,
  85. BannerURL: art.BannerURL,
  86. Content: art.Content,
  87. Summary: art.Summary,
  88. RealIP: art.RealIP,
  89. Words: art.Words,
  90. DynamicIntro: art.DynamicIntro,
  91. ImageURLs: art.ImageURLs,
  92. OriginImageURLs: art.OriginImageURLs,
  93. ActivityID: art.ActivityID,
  94. }
  95. if art.Tags != "" {
  96. arg.Tags = strings.Split(art.Tags, ",")
  97. } else {
  98. arg.Tags = []string{}
  99. }
  100. log.Info("d.art.AddArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
  101. if id, err = d.art.AddArticle(c, arg); err != nil {
  102. arg.Content = ""
  103. log.Error("d.art.AddArticle (%v) error(%v)", arg, err)
  104. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  105. err = ecode.CreativeArticleRPCErr
  106. }
  107. }
  108. return
  109. }
  110. // UpdateArticle update article.
  111. func (d *Dao) UpdateArticle(c context.Context, art *artMdl.ArtParam) (err error) {
  112. var arg = &model.ArgArticle{
  113. Aid: art.AID,
  114. Mid: art.MID,
  115. Category: art.Category,
  116. State: art.State,
  117. Reprint: art.Reprint,
  118. TemplateID: art.TemplateID,
  119. Title: art.Title,
  120. BannerURL: art.BannerURL,
  121. Content: art.Content,
  122. Summary: art.Summary,
  123. RealIP: art.RealIP,
  124. Words: art.Words,
  125. DynamicIntro: art.DynamicIntro,
  126. ImageURLs: art.ImageURLs,
  127. OriginImageURLs: art.OriginImageURLs,
  128. }
  129. if art.Tags != "" {
  130. arg.Tags = strings.Split(art.Tags, ",")
  131. } else {
  132. arg.Tags = []string{}
  133. }
  134. log.Info("d.art.UpdateArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
  135. if err = d.art.UpdateArticle(c, arg); err != nil {
  136. arg.Content = ""
  137. log.Error("d.art.UpdateArticle (%v) error(%v)", arg, err)
  138. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  139. err = ecode.CreativeArticleRPCErr
  140. }
  141. }
  142. return
  143. }
  144. // DelArticle delete article.
  145. func (d *Dao) DelArticle(c context.Context, aid, mid int64, ip string) (err error) {
  146. var arg = &model.ArgAidMid{
  147. Aid: aid,
  148. Mid: mid,
  149. RealIP: ip,
  150. }
  151. if err = d.art.DelArticle(c, arg); err != nil {
  152. log.Error("d.art.AddArticle (%v) error(%v)", arg, err)
  153. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  154. err = ecode.CreativeArticleRPCErr
  155. }
  156. }
  157. return
  158. }
  159. // WithDrawArticle withdraw article.
  160. func (d *Dao) WithDrawArticle(c context.Context, aid, mid int64, ip string) (err error) {
  161. var arg = &model.ArgAidMid{
  162. Aid: aid,
  163. Mid: mid,
  164. RealIP: ip,
  165. }
  166. if err = d.art.CreationWithdrawArticle(c, arg); err != nil {
  167. log.Error("d.art.CreationWithdrawArticle (%v) error(%v)", arg, err)
  168. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  169. err = ecode.CreativeArticleRPCErr
  170. }
  171. }
  172. return
  173. }
  174. // IsAuthor checks that whether user has permission to write article.
  175. func (d *Dao) IsAuthor(c context.Context, mid int64, ip string) (res bool, err error) {
  176. var arg = &model.ArgMid{
  177. Mid: mid,
  178. RealIP: ip,
  179. }
  180. if res, err = d.art.IsAuthor(c, arg); err != nil {
  181. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  182. log.Error("d.art.IsAuthor (%v) error(%v)", arg, err)
  183. err = ecode.CreativeArticleRPCErr
  184. }
  185. }
  186. return
  187. }
  188. // RemainCount article up limit.
  189. func (d *Dao) RemainCount(c context.Context, mid int64, ip string) (res int, err error) {
  190. var arg = &model.ArgMid{
  191. Mid: mid,
  192. RealIP: ip,
  193. }
  194. if res, err = d.art.ArticleRemainCount(c, arg); err != nil {
  195. log.Error("d.art.ArticleRemainCount (%v) error(%v)", arg, err)
  196. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  197. err = ecode.CreativeArticleRPCErr
  198. }
  199. }
  200. return
  201. }
  202. // ArticleStat article stat
  203. func (d *Dao) ArticleStat(c context.Context, mid int64, ip string) (res model.UpStat, err error) {
  204. arg := &model.ArgMid{Mid: mid, RealIP: ip}
  205. if res, err = d.art.CreationUpStat(c, arg); err != nil {
  206. log.Error("d.art.UpStat(%+v) error(%v)", arg, err)
  207. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  208. err = ecode.CreativeArticleRPCErr
  209. }
  210. }
  211. return
  212. }
  213. // ThirtyDayArticle thirty day article
  214. func (d *Dao) ThirtyDayArticle(c context.Context, mid int64, ip string) (res []*model.ThirtyDayArticle, err error) {
  215. arg := &model.ArgMid{Mid: mid, RealIP: ip}
  216. if res, err = d.art.CreationUpThirtyDayStat(c, arg); err != nil {
  217. log.Error("d.art.CreationUpThirtyDayStat(%+v) error(%v)", arg, err)
  218. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  219. err = ecode.CreativeArticleRPCErr
  220. }
  221. }
  222. return
  223. }
  224. // ArticleMetas batch get articles by aids.
  225. func (d *Dao) ArticleMetas(c context.Context, aids []int64, ip string) (res map[int64]*model.Meta, err error) {
  226. arg := &model.ArgAids{Aids: aids, RealIP: ip}
  227. if res, err = d.art.ArticleMetas(c, arg); err != nil {
  228. log.Error("d.art.ArticleMetas(%+v) error(%v)", arg, err)
  229. if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
  230. err = ecode.CreativeArticleRPCErr
  231. }
  232. }
  233. log.Info("d.art.ArticleMetas aids(%v)", aids)
  234. return
  235. }