31 lines
705 B
Go
31 lines
705 B
Go
package service
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
|
|
"nl-pms-api/internal/commonservice"
|
|
"nl-pms-api/internal/model"
|
|
)
|
|
|
|
// NoticeService 团队通知增量拉取。
|
|
type NoticeService struct {
|
|
DB *gorm.DB
|
|
}
|
|
|
|
// ListNotices 拉取 to_user=本人且 id>afterID 的通知,按 id 升序,最多 200 条。
|
|
func (s *NoticeService) ListNotices(userID, afterID int64) ([]model.TeamNotice, error) {
|
|
if afterID < 0 {
|
|
afterID = 0
|
|
}
|
|
var rows []model.TeamNotice
|
|
err := s.DB.Where("to_user = ? AND id > ?", userID, afterID).
|
|
Order("id ASC").Limit(200).Find(&rows).Error
|
|
if err != nil {
|
|
return nil, commonservice.Internal("QUERY_FAILED")
|
|
}
|
|
if rows == nil {
|
|
rows = []model.TeamNotice{}
|
|
}
|
|
return rows, nil
|
|
}
|