enums.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package constant
  2. import (
  3. "time"
  4. "github.com/jinzhu/now"
  5. )
  6. // 需要自定义类型的常量放在这里
  7. type General = int
  8. // 不在dao层中使用,在dao层使用models.No, models.Yes
  9. const (
  10. YES General = 1 // 是
  11. NO General = 2 // 否
  12. )
  13. // UploadFileType 上传文件类型
  14. type UploadFileType = int
  15. const (
  16. UploadFileTypePic UploadFileType = 1 // 普通图片
  17. UploadFileTypePdf UploadFileType = 2 // pdf
  18. UploadFileTypeExcel UploadFileType = 3 // excel
  19. ExportFileTypeExcel UploadFileType = 3 // 导出的excel文件
  20. )
  21. const MaxFileSize int64 = 10 * 1024 * 1024
  22. // ==========================================
  23. type SearchDateTimeType string
  24. const (
  25. Today SearchDateTimeType = "today" // 今天
  26. Yesterday SearchDateTimeType = "yesterday" // 昨天
  27. ThisWeek SearchDateTimeType = "thisWeek" // 本周
  28. ThisMonth SearchDateTimeType = "thisMonth" // 本月
  29. LastThreeDays SearchDateTimeType = "lastThreeDays" // 近三天
  30. LastSevenDays SearchDateTimeType = "lastSevenDays" // 近七天
  31. LastMonthDays SearchDateTimeType = "lastMonthDays" // 近一个月
  32. )
  33. func (s SearchDateTimeType) GetRangeTime() (startTime, endTime time.Time) {
  34. switch s {
  35. case Today:
  36. return now.BeginningOfDay(), now.EndOfDay()
  37. case Yesterday:
  38. t := time.Now().AddDate(0, 0, -1)
  39. nTime := now.New(t)
  40. return nTime.BeginningOfDay(), nTime.EndOfDay()
  41. case ThisWeek:
  42. return now.BeginningOfWeek(), now.EndOfWeek()
  43. case ThisMonth:
  44. return now.BeginningOfMonth(), now.EndOfMonth()
  45. case LastThreeDays:
  46. return now.New(time.Now().AddDate(0, 0, -2)).BeginningOfDay(), now.EndOfDay()
  47. case LastSevenDays:
  48. return now.New(time.Now().AddDate(0, 0, -6)).BeginningOfDay(), now.EndOfDay()
  49. case LastMonthDays:
  50. return now.New(time.Now().AddDate(0, 0, -29)).BeginningOfDay(), now.EndOfDay()
  51. default:
  52. return time.Time{}, time.Time{}
  53. }
  54. }
  55. type PermissionType = int
  56. const (
  57. PermissionPathSplit string = ";"
  58. PermissionMenu PermissionType = 1 // 菜单权限
  59. PermissionFunc PermissionType = 2 // 功能权限
  60. )
  61. // ExpiredTime 过期时间
  62. type ExpiredTime string
  63. const (
  64. ExpiredTimeOneDay ExpiredTime = "oneDay" // 一天;24小时
  65. ExpiredTimeThreeDay ExpiredTime = "threeDay" // 三天
  66. ExpiredTimeSevenDay ExpiredTime = "sevenDay" // 七天
  67. )
  68. func (e ExpiredTime) GetExpiredTime() time.Time {
  69. switch e {
  70. case ExpiredTimeOneDay:
  71. return time.Now().AddDate(0, 0, 1)
  72. case ExpiredTimeThreeDay:
  73. return time.Now().AddDate(0, 0, 3)
  74. case ExpiredTimeSevenDay:
  75. return time.Now().AddDate(0, 0, 7)
  76. default:
  77. return time.Time{}
  78. }
  79. }