12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package model
- import (
- "kpt-pasture/util"
- "strconv"
- "strings"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- const DefaultDataLatencyMinutes = 40
- type DataNotice struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- Title string `json:"title"`
- Content string `json:"content"`
- KnownUsers string `json:"knownUsers"`
- NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
- StartDate string `json:"startDate"`
- EndDate string `json:"endDate"`
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (d *DataNotice) TableName() string {
- return "data_notice"
- }
- func (d *DataNotice) GetUserIds() []int64 {
- userIds := make([]int64, 0)
- if d.KnownUsers != "" {
- userIdStr := strings.Split(d.KnownUsers, ",")
- for _, u := range userIdStr {
- uId, _ := strconv.ParseInt(u, 10, 64)
- userIds = append(userIds, uId)
- }
- }
- return userIds
- }
- func NewDataNotice(pastureId int64, title, content string, noticeKind pasturePb.NoticeType_Kind) *DataNotice {
- nowTime := time.Now().Local()
- return &DataNotice{
- Title: title,
- Content: content,
- StartDate: nowTime.Format(LayoutDate2),
- EndDate: nowTime.Format(LayoutDate2),
- IsShow: pasturePb.IsShow_Ok,
- PastureId: pastureId,
- NoticeKind: noticeKind,
- KnownUsers: "",
- }
- }
- type DataNoticeSlice []*DataNotice
- func (d DataNoticeSlice) ToPB(currentUserId int64) []*NoticeContent {
- res := make([]*NoticeContent, 0)
- for _, v := range d {
- uIds := v.GetUserIds()
- if len(uIds) > 0 && util.InArray(currentUserId, uIds) {
- continue
- }
- res = append(res, &NoticeContent{
- Id: v.Id,
- Title: v.Title,
- Content: v.Content,
- NoticeKind: v.NoticeKind,
- })
- }
- return res
- }
- type DataNoticeResponse struct {
- Code int32 `json:"code"`
- Msg string `json:"msg"`
- Data []*NoticeContent `json:"data"`
- }
- type NoticeContent struct {
- Id int64 `json:"id"`
- Title string `json:"title"`
- Content string `json:"content"`
- NoticeKind pasturePb.NoticeType_Kind `json:"noticeKind"`
- }
|