notice.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package forms
  2. import (
  3. "errors"
  4. "fmt"
  5. "gadmin/internal/admin/consts"
  6. "time"
  7. )
  8. type NoticeV2ListReq struct {
  9. ListReq
  10. Sn string `json:"sn" form:"sn"`
  11. Cdk string `json:"cdk" form:"cdk"`
  12. CreatedAt []int64 `json:"created_at" form:"created_at[]"`
  13. Time []time.Time
  14. }
  15. func (req *NoticeV2ListReq) Check() error {
  16. return nil
  17. }
  18. type NoticeV2AddReq struct {
  19. Id int64 `json:"id" form:"id"`
  20. ServerIds []int32 `json:"server_ids" form:"server_ids"`
  21. NoticeType int32 `json:"notice_type" form:"notice_type"`
  22. Content string `json:"content" form:"content"`
  23. SendInterval int64 `json:"send_interval" form:"send_interval"`
  24. StartAt int64 `json:"start_at" form:"start_at"`
  25. EndAt int64 `json:"end_at" form:"end_at"`
  26. }
  27. func (req *NoticeV2AddReq) Check() error {
  28. if _, ok := consts.NoticeTypeNameMap[req.NoticeType]; !ok {
  29. return errors.New("广播类型不正确")
  30. }
  31. if req.Content == "" {
  32. return errors.New("广播内容不能为空")
  33. }
  34. if req.SendInterval < 1 {
  35. return errors.New("发送时间间隔不能小于1分钟")
  36. }
  37. if req.StartAt >= req.EndAt {
  38. return errors.New("选择的时间区间不正确")
  39. }
  40. if req.EndAt < time.Now().Unix() {
  41. return fmt.Errorf("结束时间不能小于当前时间:%+v", time.Now().Format("2006-01-02_15:04:05"))
  42. }
  43. //if req.ServerIds == "" {
  44. // return errors.New("请选择服务器")
  45. //}
  46. //
  47. //serverIds := strings.Split(req.ServerIds, ",")
  48. if len(req.ServerIds) == 0 {
  49. return errors.New("请选择有效的服务器")
  50. }
  51. if len(req.ServerIds) > 1 {
  52. for _, serverId := range req.ServerIds {
  53. if serverId == 0 {
  54. return errors.New("选择全服时不能再选择其他服务器")
  55. }
  56. }
  57. }
  58. return nil
  59. }
  60. type NoticeV2CancelReq struct {
  61. Id int64 `json:"id" form:"id"`
  62. }
  63. func (req *NoticeV2CancelReq) Check() error {
  64. return nil
  65. }