1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package forms
- import (
- "errors"
- "fmt"
- "gadmin/internal/admin/consts"
- "time"
- )
- type NoticeV2ListReq struct {
- ListReq
- Sn string `json:"sn" form:"sn"`
- Cdk string `json:"cdk" form:"cdk"`
- CreatedAt []int64 `json:"created_at" form:"created_at[]"`
- Time []time.Time
- }
- func (req *NoticeV2ListReq) Check() error {
- return nil
- }
- type NoticeV2AddReq struct {
- Id int64 `json:"id" form:"id"`
- ServerIds []int32 `json:"server_ids" form:"server_ids"`
- NoticeType int32 `json:"notice_type" form:"notice_type"`
- Content string `json:"content" form:"content"`
- SendInterval int64 `json:"send_interval" form:"send_interval"`
- StartAt int64 `json:"start_at" form:"start_at"`
- EndAt int64 `json:"end_at" form:"end_at"`
- }
- func (req *NoticeV2AddReq) Check() error {
- if _, ok := consts.NoticeTypeNameMap[req.NoticeType]; !ok {
- return errors.New("广播类型不正确")
- }
- if req.Content == "" {
- return errors.New("广播内容不能为空")
- }
- if req.SendInterval < 1 {
- return errors.New("发送时间间隔不能小于1分钟")
- }
- if req.StartAt >= req.EndAt {
- return errors.New("选择的时间区间不正确")
- }
- if req.EndAt < time.Now().Unix() {
- return fmt.Errorf("结束时间不能小于当前时间:%+v", time.Now().Format("2006-01-02_15:04:05"))
- }
- //if req.ServerIds == "" {
- // return errors.New("请选择服务器")
- //}
- //
- //serverIds := strings.Split(req.ServerIds, ",")
- if len(req.ServerIds) == 0 {
- return errors.New("请选择有效的服务器")
- }
- if len(req.ServerIds) > 1 {
- for _, serverId := range req.ServerIds {
- if serverId == 0 {
- return errors.New("选择全服时不能再选择其他服务器")
- }
- }
- }
- return nil
- }
- type NoticeV2CancelReq struct {
- Id int64 `json:"id" form:"id"`
- }
- func (req *NoticeV2CancelReq) Check() error {
- return nil
- }
|