notice.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/space/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "go-common/library/queue/databus/report"
  9. )
  10. // Notice get notice data.
  11. func (s *Service) Notice(c context.Context, mid int64) (data *model.Notice, err error) {
  12. data = &model.Notice{Mid: mid}
  13. if err = s.dao.DB.Table(data.TableName()).Where("mid=?", mid).First(&data).Error; err != nil {
  14. log.Error("Notice (mid:%d) error (%v)", mid, err)
  15. if err == ecode.NothingFound {
  16. err = nil
  17. }
  18. }
  19. return
  20. }
  21. // NoticeUp notice clear and forbid.
  22. func (s *Service) NoticeUp(c context.Context, arg *model.NoticeUpArg) (err error) {
  23. var action string
  24. notice := &model.Notice{Mid: arg.Mid}
  25. if err = s.dao.DB.Table(notice.TableName()).Where("mid=?", arg.Mid).First(&notice).Error; err != nil {
  26. log.Error("NoticeForbid error (mid:%d) (%v)", arg.Mid, err)
  27. if err != ecode.NothingFound {
  28. return
  29. }
  30. }
  31. up := make(map[string]interface{})
  32. switch arg.Type {
  33. case model.NoticeTypeClear:
  34. up["notice"] = ""
  35. action = model.NoticeClear
  36. case model.NoticeTypeClearAndForbid:
  37. up["notice"] = ""
  38. up["is_forbid"] = model.NoticeForbid
  39. action = model.NoticeClearAndForbid
  40. case model.NoticeTypeUnForbid:
  41. up["is_forbid"] = model.NoticeNoForbid
  42. action = model.NoticeUnForbid
  43. }
  44. if err != ecode.NothingFound {
  45. if err = s.dao.DB.Table(notice.TableName()).Where("id=?", notice.ID).Update(up).Error; err != nil {
  46. log.Error("NoticeForbid (mid:%d) update error (%v)", arg.Mid, err)
  47. return
  48. }
  49. } else {
  50. create := &model.Notice{Mid: arg.Mid}
  51. if arg.Type == model.NoticeTypeClearAndForbid {
  52. create.IsForbid = model.NoticeForbid
  53. }
  54. if err = s.dao.DB.Table(notice.TableName()).Create(create).Error; err != nil {
  55. log.Error("NoticeForbid (mid:%d) insert error (%v)", arg.Mid, err)
  56. return
  57. }
  58. }
  59. if err = report.Manager(&report.ManagerInfo{
  60. Uname: arg.Uname,
  61. UID: arg.UID,
  62. Business: model.NoticeLogID,
  63. Type: 0,
  64. Oid: arg.Mid,
  65. Action: action,
  66. Ctime: time.Now(),
  67. Content: map[string]interface{}{
  68. "old": notice,
  69. },
  70. }); err != nil {
  71. return
  72. }
  73. return
  74. }