data_notice.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. "strconv"
  5. "strings"
  6. "time"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. )
  9. const (
  10. DefaultDataLatencyMinutes = 40
  11. DataLatencyTitle = "脖环数据延迟"
  12. )
  13. type DataNotice struct {
  14. Id int64 `json:"id"`
  15. PastureId int64 `json:"pastureId"`
  16. Title string `json:"title"`
  17. Content string `json:"content"`
  18. KnownUsers string `json:"knownUsers"`
  19. NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
  20. StartDate string `json:"startDate"`
  21. EndDate string `json:"endDate"`
  22. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (d *DataNotice) TableName() string {
  27. return "data_notice"
  28. }
  29. func (d *DataNotice) GetUserIds() []int64 {
  30. userIds := make([]int64, 0)
  31. if d.KnownUsers != "" {
  32. userIdStr := strings.Split(d.KnownUsers, ",")
  33. for _, u := range userIdStr {
  34. uId, _ := strconv.ParseInt(u, 10, 64)
  35. userIds = append(userIds, uId)
  36. }
  37. }
  38. return userIds
  39. }
  40. func (d *DataNotice) UpdateNotice(content string) {
  41. d.Content = content
  42. d.KnownUsers = ""
  43. }
  44. func NewDataNotice(pastureId int64, title, content string, noticeKind pasturePb.NoticeType_Kind) *DataNotice {
  45. nowTime := time.Now().Local()
  46. return &DataNotice{
  47. Title: title,
  48. Content: content,
  49. StartDate: nowTime.Format(LayoutDate2),
  50. EndDate: nowTime.Format(LayoutDate2),
  51. IsShow: pasturePb.IsShow_Ok,
  52. PastureId: pastureId,
  53. NoticeKind: noticeKind,
  54. KnownUsers: "",
  55. }
  56. }
  57. type DataNoticeSlice []*DataNotice
  58. func (d DataNoticeSlice) ToPB(currentUserId int64) []*NoticeContent {
  59. res := make([]*NoticeContent, 0)
  60. for _, v := range d {
  61. uIds := v.GetUserIds()
  62. if len(uIds) > 0 && util.InArray(currentUserId, uIds) {
  63. continue
  64. }
  65. res = append(res, &NoticeContent{
  66. Id: v.Id,
  67. Title: v.Title,
  68. Content: v.Content,
  69. NoticeKind: v.NoticeKind,
  70. })
  71. }
  72. return res
  73. }
  74. type DataNoticeResponse struct {
  75. Code int32 `json:"code"`
  76. Msg string `json:"msg"`
  77. Data []*NoticeContent `json:"data"`
  78. }
  79. type NoticeContent struct {
  80. Id int64 `json:"id"`
  81. Title string `json:"title"`
  82. Content string `json:"content"`
  83. NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
  84. }