| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | 
							- package model
 
- import (
 
- 	"kpt-pasture/util"
 
- 	"strconv"
 
- 	"strings"
 
- 	"time"
 
- 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
- )
 
- const (
 
- 	DefaultDataLatencyMinutes = 40
 
- 	DataLatencyTitle          = "脖环数据延迟"
 
- )
 
- 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 (d *DataNotice) UpdateNotice(content string) {
 
- 	d.Content = content
 
- 	d.KnownUsers = ""
 
- }
 
- 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"`
 
- }
 
 
  |