event_topic.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package popular
  2. import (
  3. "context"
  4. "go-common/app/admin/main/feed/model/common"
  5. "go-common/app/admin/main/feed/model/show"
  6. "go-common/app/admin/main/feed/util"
  7. "go-common/library/log"
  8. )
  9. const (
  10. //ActionAddCEventTopic log action
  11. ActionAddCEventTopic = "ActAddEventTopic"
  12. //ActionUpCEventTopic log action
  13. ActionUpCEventTopic = "ActUpEventTopic"
  14. //ActionDelCEventTopic log action
  15. ActionDelCEventTopic = "ActDelEventTopic"
  16. )
  17. //EventTopicList channel EventTopic list
  18. func (s *Service) EventTopicList(lp *show.EventTopicLP) (pager *show.EventTopicPager, err error) {
  19. pager = &show.EventTopicPager{
  20. Page: common.Page{
  21. Num: lp.Pn,
  22. Size: lp.Ps,
  23. },
  24. }
  25. w := map[string]interface{}{
  26. "deleted": common.NotDeleted,
  27. }
  28. query := s.showDao.DB.Model(&show.EventTopic{})
  29. if lp.ID > 0 {
  30. w["id"] = lp.ID
  31. }
  32. if lp.Person != "" {
  33. query = query.Where("person like ?", "%"+lp.Person+"%")
  34. }
  35. if lp.Title != "" {
  36. query = query.Where("title like ?", "%"+lp.Title+"%")
  37. }
  38. if err = query.Where(w).Count(&pager.Page.Total).Error; err != nil {
  39. log.Error("popularSvc.EventTopicList count error(%v)", err)
  40. return
  41. }
  42. EventTopics := make([]*show.EventTopic, 0)
  43. if err = query.Where(w).Order("`id` DESC").Offset((lp.Pn - 1) * lp.Ps).Limit(lp.Ps).Find(&EventTopics).Error; err != nil {
  44. log.Error("popularSvc.EventTopicList Find error(%v)", err)
  45. return
  46. }
  47. pager.Item = EventTopics
  48. return
  49. }
  50. //AddEventTopic add channel EventTopic
  51. func (s *Service) AddEventTopic(c context.Context, param *show.EventTopicAP, name string, uid int64) (err error) {
  52. if err = s.showDao.EventTopicAdd(param); err != nil {
  53. return
  54. }
  55. if err = util.AddLogs(common.LogEventTopic, name, uid, 0, ActionAddCEventTopic, param); err != nil {
  56. log.Error("popularSvc.AddEventTopic AddLog error(%v)", err)
  57. return
  58. }
  59. return
  60. }
  61. //UpdateEventTopic update channel EventTopic
  62. func (s *Service) UpdateEventTopic(c context.Context, param *show.EventTopicUP, name string, uid int64) (err error) {
  63. if err = s.showDao.EventTopicUpdate(param); err != nil {
  64. return
  65. }
  66. if err = util.AddLogs(common.LogEventTopic, name, uid, 0, ActionUpCEventTopic, param); err != nil {
  67. log.Error("popularSvc.UpdateEventTopic AddLog error(%v)", err)
  68. return
  69. }
  70. return
  71. }
  72. //DeleteEventTopic delete channel EventTopic
  73. func (s *Service) DeleteEventTopic(id int64, name string, uid int64) (err error) {
  74. if err = s.showDao.EventTopicDelete(id); err != nil {
  75. return
  76. }
  77. if err = util.AddLogs(common.LogEventTopic, name, uid, id, ActionDelCEventTopic, id); err != nil {
  78. log.Error("popularSvc.DeleteEventTopic AddLog error(%v)", err)
  79. return
  80. }
  81. return
  82. }