@@ -0,0 +1,459 @@
|
||||
package infmtctrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/noticefmtmod"
|
||||
"91porn-server/web/service/infmtser"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type Sender = noticefmtmod.Sender
|
||||
|
||||
type Receiver = noticefmtmod.Receiver
|
||||
|
||||
type NoticeType = noticefmtmod.NoticeType
|
||||
|
||||
type UIDSlice = noticefmtmod.UIDSlice
|
||||
|
||||
type TimeUnit = noticefmtmod.TimeUnit
|
||||
|
||||
type TimeSlice = noticefmtmod.TimeSlice
|
||||
|
||||
type ObjectID = primitive.ObjectID
|
||||
|
||||
type RegularNotice = noticefmtmod.RegularNotice
|
||||
|
||||
type PlanNotice = noticefmtmod.PlanNotice
|
||||
|
||||
type SpecifyNotice = noticefmtmod.SpecifyNotice
|
||||
|
||||
type MailNotice = noticefmtmod.MailNotice
|
||||
|
||||
type AfterRegistNotice = noticefmtmod.AfterRegistNotice
|
||||
|
||||
// NoticeList doc
|
||||
// @Summary 通知列表
|
||||
// @Description 通知列表
|
||||
// @Tags web-Notice
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param noticeCode query string false "通知码"
|
||||
// @Param title query string false "标题"
|
||||
// @Param noticeType query string false "通知类型"
|
||||
// @Param sender query string false "发送者"
|
||||
// @Param receiver query string false "接受者"
|
||||
// @Param enable query bool false "开关"
|
||||
// @Param pageNumber query int true "当前页"
|
||||
// @Param pageSize query int true "每页条数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/notice/list [get]
|
||||
func NoticeList(c *gin.Context) {
|
||||
type Query struct {
|
||||
NoticeCode *string `form:"noticeCode" json:"noticeCode" binding:""` //通知码 唯一标记不同的通知计划,可代替_id,方便复制数据
|
||||
Title *string `form:"title" json:"title" binding:""` //标题
|
||||
NoticeType *NoticeType `form:"noticeType" json:"noticeType" binding:""` //通知类型
|
||||
Sender *Sender `form:"sender" json:"sender" binding:""` //发送者
|
||||
Receiver *Receiver `form:"receiver" json:"receiver" binding:""` //接受者
|
||||
Enable *bool `form:"enable" json:"enable" binding:""` //开关
|
||||
}
|
||||
var arg struct {
|
||||
commod.Page
|
||||
Query
|
||||
}
|
||||
if err := c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "infmtctrl NoticeList arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
titleMatch := infmtser.TitleMatch{Title: arg.Title}
|
||||
noticeCodeMatch := infmtser.NoticeCodeMatch{NoticeCode: arg.NoticeCode}
|
||||
noticeTypeMatch := infmtser.NoticeTypeMatch{NoticeType: arg.NoticeType}
|
||||
senderMatch := infmtser.SenderMatch{Sender: arg.Sender}
|
||||
receiverMatch := infmtser.ReceiverMatch{Receiver: arg.Receiver}
|
||||
enableMatch := infmtser.EnableMatch{Enable: arg.Enable}
|
||||
skip := int64((arg.PageNumber - 1) * arg.PageSize)
|
||||
limit := int64(arg.PageSize)
|
||||
page, err := infmtser.NoticePages(skip, limit, titleMatch, noticeCodeMatch, noticeTypeMatch, senderMatch, receiverMatch, enableMatch)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.Failure, "web infmtctrl NoticeList error: "+err.Error())
|
||||
return
|
||||
}
|
||||
common.ServeJSON(c, stderr.Success, page)
|
||||
}
|
||||
|
||||
// NoticeUpdate doc
|
||||
// @Summary 编辑通知
|
||||
// @Description 编辑通知
|
||||
// @Tags web-Notice
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param ID formData string true "id"
|
||||
// @Param title query string false "标题"
|
||||
// @Param sender query string false "发送者"
|
||||
// @Param receiver query string false "接受者"
|
||||
// @Param enable query bool false "开关"
|
||||
// @Param uidList query array false "用户列表"
|
||||
// @Param content query string false "内容"
|
||||
// @Param remark query string false "备注"
|
||||
// @Param noticeType query string false "通知类型"
|
||||
// @Param startAt query string false "开始时间"
|
||||
// @Param timeUnit query string false "单位 分钟/小时/天/周"
|
||||
// @Param timeCount query int false "量"
|
||||
// @Param endAt query string false "结束时间"
|
||||
// @Param planCount query int false "执行次数"
|
||||
// @Param specifyTimeList query array false "指定执行时间数组"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/notice/update [post]
|
||||
func NoticeUpdate(c *gin.Context) {
|
||||
manager, err := common.GetAdminAct(c)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
type NoticeFMT struct {
|
||||
StartAt *time.Time `form:"startAt" json:"startAt" binding:""` //开始时间
|
||||
TimeUnit *TimeUnit `form:"timeUnit" json:"timeUnit" binding:""` //单位 分钟/小时/天/周
|
||||
TimeCount *int64 `form:"timeCount" json:"timeCount" binding:""` //量
|
||||
EndAt *time.Time `form:"endAt" json:"endAt" binding:""` //结束时间
|
||||
PlanCount *int64 `form:"planCount" json:"planCount" binding:""` //执行次数
|
||||
SpecifyTimeList TimeSlice `form:"specifyTimeList" json:"specifyTimeList" binding:""` //指定执行时间数组
|
||||
}
|
||||
type Update struct {
|
||||
Title *string `form:"title" json:"title" binding:""` //标题
|
||||
Sender *Sender `form:"sender" json:"sender" binding:""` //发送者
|
||||
Receiver *Receiver `form:"receiver" json:"receiver" binding:""` //接受者
|
||||
Enable *bool `form:"enable" json:"enable" binding:""` //开关
|
||||
UIDList UIDSlice `form:"uidList" json:"uidList" binding:""` //用户列表
|
||||
Content *string `form:"content" json:"content" binding:""` //内容
|
||||
Remark *string `form:"remark" json:"remark" binding:""` //备注
|
||||
NoticeType *NoticeType `form:"noticeType" json:"noticeType" binding:""` //通知类型
|
||||
NoticeFMT
|
||||
}
|
||||
var arg struct {
|
||||
ID ObjectID `form:"id" json:"id" binding:"required"`
|
||||
Update
|
||||
}
|
||||
if err = c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "web infmtctrl NoticeUpdate arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
updateDoc := noticefmtmod.UpdateDoc{
|
||||
Sender: arg.Sender,
|
||||
Receiver: arg.Receiver,
|
||||
UIDList: arg.UIDList,
|
||||
Title: arg.Title,
|
||||
Content: arg.Content,
|
||||
Enable: arg.Enable,
|
||||
Remark: arg.Remark,
|
||||
NoticeType: arg.NoticeType,
|
||||
}
|
||||
if arg.NoticeType != nil {
|
||||
switch *arg.NoticeType {
|
||||
case noticefmtmod.RegularNoticeType:
|
||||
updateDoc.RegularNotice = RegularNotice{
|
||||
StartAt: arg.StartAt,
|
||||
TimeUnit: arg.TimeUnit,
|
||||
TimeCount: arg.TimeCount,
|
||||
}
|
||||
case noticefmtmod.PlanNoticeType:
|
||||
updateDoc.PlanNotice = PlanNotice{
|
||||
StartAt: arg.StartAt,
|
||||
EndAt: arg.EndAt,
|
||||
PlanCount: arg.PlanCount,
|
||||
}
|
||||
case noticefmtmod.SpecifyNoticeType:
|
||||
updateDoc.SpecifyNotice = SpecifyNotice{
|
||||
SpecifyTimeList: arg.SpecifyTimeList,
|
||||
}
|
||||
case noticefmtmod.AfterRegistNoticeType:
|
||||
updateDoc.AfterRegistNotice = AfterRegistNotice{
|
||||
TimeUnit: arg.TimeUnit,
|
||||
TimeCount: arg.TimeCount,
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = noticefmtmod.UpdateOne(arg.ID, updateDoc); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbUpdateError, "web infmtctrl NoticeUpdate error: "+err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(arg)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.UserManageList, constant.Modify, string(log), c.Request.URL.RequestURI())
|
||||
common.ServeJSON(c, stderr.Success, "")
|
||||
}
|
||||
|
||||
// NoticeAdd doc
|
||||
// @Summary 添加通知
|
||||
// @Description 添加通知
|
||||
// @Tags web-Notice
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param noticeType query string true "通知类型"
|
||||
// @Param title query string true "标题"
|
||||
// @Param sender query string true "发送者"
|
||||
// @Param receiver query string true "接受者"
|
||||
// @Param enable query bool true "开关"
|
||||
// @Param uidList query array false "用户列表"
|
||||
// @Param content query string false "内容"
|
||||
// @Param remark query string false "备注"
|
||||
// @Param startAt query string false "开始时间"
|
||||
// @Param timeUnit query string false "单位 分钟/小时/天/周"
|
||||
// @Param timeCount query int false "量"
|
||||
// @Param endAt query string false "结束时间"
|
||||
// @Param planCount query int false "执行次数"
|
||||
// @Param specifyTimeList query array false "指定执行时间数组"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/notice/add [post]
|
||||
func NoticeAdd(c *gin.Context) {
|
||||
manager, err := common.GetAdminAct(c)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
type NoticeFMT struct {
|
||||
StartAt *time.Time `form:"startAt" json:"startAt" binding:""` //开始时间
|
||||
TimeUnit *TimeUnit `form:"timeUnit" json:"timeUnit" binding:""` //单位 分钟/小时/天/周
|
||||
TimeCount *int64 `form:"timeCount" json:"timeCount" binding:""` //量
|
||||
EndAt *time.Time `form:"endAt" json:"endAt" binding:""` //结束时间
|
||||
PlanCount *int64 `form:"planCount" json:"planCount" binding:""` //执行次数
|
||||
SpecifyTimeList TimeSlice `form:"specifyTimeList" json:"specifyTimeList" binding:""` //指定执行时间数组
|
||||
}
|
||||
type Insert struct {
|
||||
NoticeType NoticeType `form:"noticeType" json:"noticeType" binding:"required"` //通知类型
|
||||
Title string `form:"title" json:"title" binding:"required"` //标题
|
||||
Sender Sender `form:"sender" json:"sender" binding:"required"` //发送者
|
||||
Receiver Receiver `form:"receiver" json:"receiver" binding:"required"` //接受者
|
||||
Enable *bool `form:"enable" json:"enable" binding:"required"` //开关
|
||||
UIDList UIDSlice `form:"uidList" json:"uidList" binding:""` //用户列表
|
||||
Content *string `form:"content" json:"content" binding:""` //内容
|
||||
Remark *string `form:"remark" json:"remark" binding:""` //备注
|
||||
NoticeFMT
|
||||
}
|
||||
var arg struct {
|
||||
Insert
|
||||
}
|
||||
if err = c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "web infmtctrl NoticeAdd arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
insertDoc := noticefmtmod.InsertDoc{
|
||||
Sender: arg.Sender,
|
||||
Receiver: arg.Receiver,
|
||||
UIDList: arg.UIDList,
|
||||
Title: arg.Title,
|
||||
NoticeType: arg.NoticeType,
|
||||
Enable: *arg.Enable,
|
||||
}
|
||||
insertDoc.NoticeCode = common.UUID()
|
||||
if arg.Content != nil {
|
||||
insertDoc.Content = *arg.Content
|
||||
}
|
||||
if arg.Remark != nil {
|
||||
insertDoc.Remark = *arg.Remark
|
||||
}
|
||||
switch arg.NoticeType {
|
||||
case noticefmtmod.RegularNoticeType:
|
||||
insertDoc.RegularNotice = RegularNotice{
|
||||
StartAt: arg.StartAt,
|
||||
TimeUnit: arg.TimeUnit,
|
||||
TimeCount: arg.TimeCount,
|
||||
}
|
||||
case noticefmtmod.PlanNoticeType:
|
||||
insertDoc.PlanNotice = PlanNotice{
|
||||
StartAt: arg.StartAt,
|
||||
EndAt: arg.EndAt,
|
||||
PlanCount: arg.PlanCount,
|
||||
}
|
||||
case noticefmtmod.SpecifyNoticeType:
|
||||
insertDoc.SpecifyNotice = SpecifyNotice{
|
||||
SpecifyTimeList: arg.SpecifyTimeList,
|
||||
}
|
||||
case noticefmtmod.AfterRegistNoticeType:
|
||||
insertDoc.AfterRegistNotice = AfterRegistNotice{
|
||||
TimeUnit: arg.TimeUnit,
|
||||
TimeCount: arg.TimeCount,
|
||||
}
|
||||
}
|
||||
sort.Sort(insertDoc.UIDList)
|
||||
if err = noticefmtmod.InsertOne(insertDoc); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbInsertError, "web infmtctrl NoticeAdd InsertOne error: "+err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(arg)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.UserManageList, constant.Add, string(log), c.Request.URL.RequestURI())
|
||||
common.ServeJSON(c, stderr.Success, "")
|
||||
}
|
||||
|
||||
// NoticeDel doc
|
||||
// @Summary 删除通知
|
||||
// @Description 删除通知
|
||||
// @Tags web-Notice
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param ID formData string true "id"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/notice/delete [delete]
|
||||
func NoticeDel(c *gin.Context) {
|
||||
manager, err := common.GetAdminAct(c)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var arg struct {
|
||||
ID ObjectID `form:"id" json:"id" binding:"required"`
|
||||
}
|
||||
if err = c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "web infmtctrl NoticeDel arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
if err = noticefmtmod.DeleteOne(arg.ID); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbDeleteError, "web infmtctrl NoticeDel DeleteOne error: "+err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(arg)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.UserManageList, constant.Delete, string(log), c.Request.URL.RequestURI())
|
||||
common.ServeJSON(c, stderr.Success, "")
|
||||
}
|
||||
|
||||
// MailList doc
|
||||
// @Summary 邮件通知列表
|
||||
// @Description 邮件通知列表
|
||||
// @Tags web-Mail
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param noticeCode query string false "通知码"
|
||||
// @Param title query string false "标题"
|
||||
// @Param receiver query string false "接受者"
|
||||
// @Param pageNumber query int true "当前页"
|
||||
// @Param pageSize query int true "每页条数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/mail/list [get]
|
||||
func MailList(c *gin.Context) {
|
||||
type Query struct {
|
||||
NoticeCode *string `form:"noticeCode" json:"noticeCode" binding:""` //通知码 唯一标记不同的通知计划,可代替_id,方便复制数据
|
||||
Title *string `form:"title" json:"title" binding:""` //标题
|
||||
Receiver *Receiver `form:"receiver" json:"receiver" binding:""` //接受者
|
||||
}
|
||||
var arg struct {
|
||||
commod.Page
|
||||
Query
|
||||
}
|
||||
if err := c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "infmtctrl MailList arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
titleMatch := infmtser.TitleMatch{Title: arg.Title}
|
||||
noticeCodeMatch := infmtser.NoticeCodeMatch{NoticeCode: arg.NoticeCode}
|
||||
receiverMatch := infmtser.ReceiverMatch{Receiver: arg.Receiver}
|
||||
skip := int64((arg.PageNumber - 1) * arg.PageSize)
|
||||
limit := int64(arg.PageSize)
|
||||
page, err := infmtser.MailPages(skip, limit, titleMatch, noticeCodeMatch, receiverMatch)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.Failure, "web infmtctrl MailList error: "+err.Error())
|
||||
return
|
||||
}
|
||||
common.ServeJSON(c, stderr.Success, page)
|
||||
}
|
||||
|
||||
// MailAdd doc
|
||||
// @Summary 添加邮件
|
||||
// @Description 添加邮件
|
||||
// @Tags web-Mail
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param title query string true "标题"
|
||||
// @Param receiver query string true "接受者"
|
||||
// @Param content query string true "内容"
|
||||
// @Param uidList query array false "用户列表"
|
||||
// @Param remark query string false "备注"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/mail/add [post]
|
||||
func MailAdd(c *gin.Context) {
|
||||
manager, err := common.GetAdminAct(c)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
type Insert struct {
|
||||
Title string `form:"title" json:"title" binding:"required"` //标题
|
||||
Receiver Receiver `form:"receiver" json:"receiver" binding:"required"` //接受者
|
||||
Content string `form:"content" json:"content" binding:"required"` //内容
|
||||
UIDList UIDSlice `form:"uidList" json:"uidList" binding:""` //用户列表
|
||||
Remark *string `form:"remark" json:"remark" binding:""` //备注
|
||||
}
|
||||
var arg struct {
|
||||
Insert
|
||||
}
|
||||
if err = c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "web infmtctrl NoticeAdd arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
sendAt := time.Now()
|
||||
insertDoc := noticefmtmod.InsertDoc{
|
||||
NoticeCode: common.UUID(),
|
||||
NoticeType: noticefmtmod.MailNoticeType,
|
||||
Sender: noticefmtmod.System,
|
||||
Enable: true,
|
||||
Receiver: arg.Receiver,
|
||||
UIDList: arg.UIDList,
|
||||
Title: arg.Title,
|
||||
Content: arg.Content,
|
||||
MailNotice: MailNotice{SendAt: &sendAt},
|
||||
}
|
||||
if arg.Remark != nil {
|
||||
insertDoc.Remark = *arg.Remark
|
||||
}
|
||||
if err = noticefmtmod.InsertOne(insertDoc); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbInsertError, "web infmtctrl MailAdd InsertOne error: "+err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(arg)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.UserManageList, constant.Add, string(log), c.Request.URL.RequestURI())
|
||||
common.ServeJSON(c, stderr.Success, "")
|
||||
}
|
||||
|
||||
// MailDel doc
|
||||
// @Summary 删除邮件通知
|
||||
// @Description 删除邮件通知
|
||||
// @Tags web-Mail
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param ID formData string true "id"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /web/infmt/mail/delete [delete]
|
||||
func MailDel(c *gin.Context) {
|
||||
manager, err := common.GetAdminAct(c)
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var arg struct {
|
||||
ID ObjectID `form:"id" json:"id" binding:"required"`
|
||||
}
|
||||
if err = c.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrParamError, "web infmtctrl MailDel arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
if err = noticefmtmod.DeleteOne(arg.ID); err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbDeleteError, "web infmtctrl MailDel DeleteOne error: "+err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(arg)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.UserManageList, constant.Delete, string(log), c.Request.URL.RequestURI())
|
||||
common.ServeJSON(c, stderr.Success, "")
|
||||
}
|
||||
Reference in New Issue
Block a user