sent_notification.go 1.1 KB
package domain

import "time"

// 发送出的通知
type SentNotification struct {
	// 发送出的通知ID
	SentNotificationId int64 `json:"sentNotificationId"`
	// 通知
	Notification *Notification `json:"notification"`
	// 通知接收者
	Receiver *EmployeeInfo `json:"receiver"`
	// 是否已读
	IsRead bool `json:"isRead"`
	// 通知读取时间
	ReadTime time.Time `json:"readTime"`
}

type SentNotificationRepository interface {
	Save(sentNotification *SentNotification) (*SentNotification, error)
	Remove(sentNotification *SentNotification) (*SentNotification, error)
	FindOne(queryOptions map[string]interface{}) (*SentNotification, error)
	Find(queryOptions map[string]interface{}) (int64, []*SentNotification, error)
}

func (sentNotification *SentNotification) Identify() interface{} {
	if sentNotification.SentNotificationId == 0 {
		return nil
	}
	return sentNotification.SentNotificationId
}

func (sentNotification *SentNotification) Read() error {
	sentNotification.IsRead = true
	if sentNotification.ReadTime.IsZero() {
		sentNotification.ReadTime = time.Now()
	}
	return nil
}