198 lines
5.8 KiB
Go
198 lines
5.8 KiB
Go
package infmtser
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/common/pageopt"
|
|
"91porn-server/models/v/noticefmtmod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type ObjectID = primitive.ObjectID
|
|
|
|
type Sender = noticefmtmod.Sender
|
|
|
|
type Receiver = noticefmtmod.Receiver
|
|
|
|
type UIDSlice = noticefmtmod.UIDSlice
|
|
|
|
type NoticeType = noticefmtmod.NoticeType
|
|
|
|
type RegularNotice = noticefmtmod.RegularNotice
|
|
|
|
type PlanNotice = noticefmtmod.PlanNotice
|
|
|
|
type SpecifyNotice = noticefmtmod.SpecifyNotice
|
|
|
|
type AfterRegistNotice = noticefmtmod.AfterRegistNotice
|
|
|
|
type MailNotice = noticefmtmod.MailNotice
|
|
|
|
type TimeUnit = noticefmtmod.TimeUnit
|
|
|
|
type TimeSlice = noticefmtmod.TimeSlice
|
|
|
|
type Record struct {
|
|
ID ObjectID `json:"_id,omitempty"` //_id
|
|
NoticeCode string `json:"noticeCode"` //通知码 唯一标记不同的通知计划,可代替_id,方便复制数据
|
|
Title string `json:"title"` //标题
|
|
Sender Sender `json:"sender"` //发送者
|
|
Receiver Receiver `json:"receiver"` //接受者
|
|
Content string `json:"content"` //内容
|
|
Remark string `json:"remark"` //备注
|
|
NoticeType NoticeType `json:"noticeType"` //通知类型
|
|
Enable bool `json:"enable"` //消息开关 true:允许通知Receiver,否则不允许通知Receiver
|
|
UIDList UIDSlice `json:"uidList"` //用户列表
|
|
Rule string `json:"rule"` //描述
|
|
|
|
StartAt *time.Time `json:"startAt"` //缺省字段
|
|
EndAt *time.Time `json:"endAt"` //缺省字段
|
|
TimeUnit *TimeUnit `json:"timeUnit"` //缺省字段
|
|
TimeCount *int64 `json:"timeCount"` //缺省字段
|
|
PlanCount *int64 `json:"planCount"` //缺省字段
|
|
SpecifyTimeList TimeSlice `json:"specifyTimeList"` //缺省字段
|
|
}
|
|
|
|
type NoticePage struct {
|
|
Total int64 `json:"total" bson:"total"`
|
|
List []Record `json:"list" bson:"list"`
|
|
}
|
|
|
|
type TitleMatch = noticefmtmod.TitleMatch
|
|
type NoticeCodeMatch = noticefmtmod.NoticeCodeMatch
|
|
type NoticeTypeMatch = noticefmtmod.NoticeTypeMatch
|
|
type SenderMatch = noticefmtmod.SenderMatch
|
|
type ReceiverMatch = noticefmtmod.ReceiverMatch
|
|
type EnableMatch = noticefmtmod.EnableMatch
|
|
|
|
func NoticePages(skip, limit int64,
|
|
titleMatch TitleMatch,
|
|
noticeCodeMatch NoticeCodeMatch,
|
|
noticeTypeMatch NoticeTypeMatch,
|
|
senderMatch SenderMatch,
|
|
receiverMatch ReceiverMatch,
|
|
enableMatch EnableMatch,
|
|
) (NoticePage, error) {
|
|
mats := []pageopt.Matcher{
|
|
titleMatch.New(),
|
|
noticeCodeMatch.New(),
|
|
noticeTypeMatch.New(),
|
|
senderMatch.New(),
|
|
receiverMatch.New(),
|
|
enableMatch.New(),
|
|
}
|
|
sort := bson.D{{Key: "createdAt", Value: -1}}
|
|
list, err := noticefmtmod.List(sort, skip, limit, mats...)
|
|
if err != nil {
|
|
return NoticePage{}, err
|
|
}
|
|
recordList := make([]Record, len(list))
|
|
for i, v := range list {
|
|
record := Record{
|
|
ID: v.ID,
|
|
NoticeCode: v.NoticeCode,
|
|
Title: v.Title,
|
|
Sender: v.Sender,
|
|
Receiver: v.Receiver,
|
|
Content: v.Content,
|
|
Remark: v.Remark,
|
|
NoticeType: v.NoticeType,
|
|
Enable: v.Enable,
|
|
UIDList: v.UIDList,
|
|
}
|
|
switch v.NoticeType {
|
|
case noticefmtmod.RegularNoticeType:
|
|
record.Rule = v.RegularNotice.Rule()
|
|
record.StartAt = v.RegularNotice.StartAt
|
|
record.TimeUnit = v.RegularNotice.TimeUnit
|
|
record.TimeCount = v.RegularNotice.TimeCount
|
|
case noticefmtmod.PlanNoticeType:
|
|
record.Rule = v.PlanNotice.Rule()
|
|
record.StartAt = v.PlanNotice.StartAt
|
|
record.EndAt = v.PlanNotice.EndAt
|
|
record.PlanCount = v.PlanNotice.PlanCount
|
|
case noticefmtmod.SpecifyNoticeType:
|
|
record.Rule = v.SpecifyNotice.Rule()
|
|
record.SpecifyTimeList = v.SpecifyNotice.SpecifyTimeList
|
|
case noticefmtmod.AfterRegistNoticeType:
|
|
record.Rule = v.AfterRegistNotice.Rule()
|
|
record.TimeUnit = v.AfterRegistNotice.TimeUnit
|
|
record.TimeCount = v.AfterRegistNotice.TimeCount
|
|
}
|
|
recordList[i] = record
|
|
}
|
|
count, err := noticefmtmod.Count(mats...)
|
|
if err != nil {
|
|
return NoticePage{}, err
|
|
}
|
|
return NoticePage{
|
|
count,
|
|
recordList,
|
|
}, nil
|
|
}
|
|
|
|
type Mail struct {
|
|
ID ObjectID `json:"_id,omitempty"` //_id
|
|
NoticeCode string `json:"noticeCode"` //通知码 唯一标记不同的通知计划,可代替_id,方便复制数据
|
|
Title string `json:"title"` //标题
|
|
Receiver Receiver `json:"receiver"` //接受者
|
|
Content string `json:"content"` //内容
|
|
Remark string `json:"remark"` //备注
|
|
Enable bool `json:"-"` //消息开关 true:允许通知Receiver,否则不允许通知Receiver
|
|
UIDList UIDSlice `json:"uidList"` //用户列表
|
|
SendAt time.Time `json:"sendAt"` //发送时间
|
|
}
|
|
|
|
type MailPage struct {
|
|
Total int64 `json:"total" bson:"total"`
|
|
List []Mail `json:"list" bson:"list"`
|
|
}
|
|
|
|
func MailPages(skip, limit int64,
|
|
titleMatch TitleMatch,
|
|
noticeCodeMatch NoticeCodeMatch,
|
|
receiverMatch ReceiverMatch,
|
|
) (MailPage, error) {
|
|
noticeType := noticefmtmod.MailNoticeType
|
|
mats := []pageopt.Matcher{
|
|
(&NoticeTypeMatch{NoticeType: ¬iceType}).New(),
|
|
titleMatch.New(),
|
|
noticeCodeMatch.New(),
|
|
receiverMatch.New(),
|
|
}
|
|
sort := bson.D{{Key: "createdAt", Value: -1}}
|
|
list, err := noticefmtmod.List(sort, skip, limit, mats...)
|
|
if err != nil {
|
|
return MailPage{}, err
|
|
}
|
|
recordList := make([]Mail, len(list))
|
|
for i, v := range list {
|
|
record := Mail{
|
|
ID: v.ID,
|
|
NoticeCode: v.NoticeCode,
|
|
Title: v.Title,
|
|
Receiver: v.Receiver,
|
|
Content: v.Content,
|
|
Remark: v.Remark,
|
|
Enable: v.Enable,
|
|
UIDList: v.UIDList,
|
|
}
|
|
if v.NoticeType == noticefmtmod.MailNoticeType {
|
|
if v.MailNotice.SendAt != nil {
|
|
record.SendAt = *v.MailNotice.SendAt
|
|
}
|
|
}
|
|
recordList[i] = record
|
|
}
|
|
count, err := noticefmtmod.Count(mats...)
|
|
if err != nil {
|
|
return MailPage{}, err
|
|
}
|
|
return MailPage{
|
|
count,
|
|
recordList,
|
|
}, nil
|
|
}
|