data_notice.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 DefaultDataLatencyMinutes = 40
  10. type DataNotice struct {
  11. Id int64 `json:"id"`
  12. PastureId int64 `json:"pastureId"`
  13. Title string `json:"title"`
  14. Content string `json:"content"`
  15. KnownUsers string `json:"knownUsers"`
  16. NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
  17. StartDate string `json:"startDate"`
  18. EndDate string `json:"endDate"`
  19. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  20. CreatedAt int64 `json:"createdAt"`
  21. UpdatedAt int64 `json:"updatedAt"`
  22. }
  23. func (d *DataNotice) TableName() string {
  24. return "data_notice"
  25. }
  26. func (d *DataNotice) GetUserIds() []int64 {
  27. userIds := make([]int64, 0)
  28. if d.KnownUsers != "" {
  29. userIdStr := strings.Split(d.KnownUsers, ",")
  30. for _, u := range userIdStr {
  31. uId, _ := strconv.ParseInt(u, 10, 64)
  32. userIds = append(userIds, uId)
  33. }
  34. }
  35. return userIds
  36. }
  37. func NewDataNotice(pastureId int64, title, content string, noticeKind pasturePb.NoticeType_Kind) *DataNotice {
  38. nowTime := time.Now().Local()
  39. return &DataNotice{
  40. Title: title,
  41. Content: content,
  42. StartDate: nowTime.Format(LayoutDate2),
  43. EndDate: nowTime.Format(LayoutDate2),
  44. IsShow: pasturePb.IsShow_Ok,
  45. PastureId: pastureId,
  46. NoticeKind: noticeKind,
  47. KnownUsers: "",
  48. }
  49. }
  50. type DataNoticeSlice []*DataNotice
  51. func (d DataNoticeSlice) ToPB(currentUserId int64) []*NoticeContent {
  52. res := make([]*NoticeContent, 0)
  53. for _, v := range d {
  54. uIds := v.GetUserIds()
  55. if len(uIds) > 0 && util.InArray(currentUserId, uIds) {
  56. continue
  57. }
  58. res = append(res, &NoticeContent{
  59. Id: v.Id,
  60. Title: v.Title,
  61. Content: v.Content,
  62. NoticeKind: v.NoticeKind,
  63. })
  64. }
  65. return res
  66. }
  67. type DataNoticeResponse struct {
  68. Code int32 `json:"code"`
  69. Msg string `json:"msg"`
  70. Data []*NoticeContent `json:"data"`
  71. }
  72. type NoticeContent struct {
  73. Id int64 `json:"id"`
  74. Title string `json:"title"`
  75. Content string `json:"content"`
  76. NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
  77. }