提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.common.enums; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.ArrayUtil; |
|
4 |
import com.iailab.framework.common.core.IntArrayValuable; |
|
5 |
import lombok.AllArgsConstructor; |
|
6 |
import lombok.Getter; |
|
7 |
|
|
8 |
import java.util.Arrays; |
|
9 |
|
|
10 |
/** |
|
11 |
* 时间间隔的枚举 |
|
12 |
* |
|
13 |
* @author dhb52 |
|
14 |
*/ |
|
15 |
@Getter |
|
16 |
@AllArgsConstructor |
|
17 |
public enum DateIntervalEnum implements IntArrayValuable { |
|
18 |
|
|
19 |
DAY(1, "天"), |
|
20 |
WEEK(2, "周"), |
|
21 |
MONTH(3, "月"), |
|
22 |
QUARTER(4, "季度"), |
|
23 |
YEAR(5, "年") |
|
24 |
; |
|
25 |
|
|
26 |
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DateIntervalEnum::getInterval).toArray(); |
|
27 |
|
|
28 |
/** |
|
29 |
* 类型 |
|
30 |
*/ |
|
31 |
private final Integer interval; |
|
32 |
/** |
|
33 |
* 名称 |
|
34 |
*/ |
|
35 |
private final String name; |
|
36 |
|
|
37 |
@Override |
|
38 |
public int[] array() { |
|
39 |
return ARRAYS; |
|
40 |
} |
|
41 |
|
|
42 |
public static DateIntervalEnum valueOf(Integer interval) { |
|
43 |
return ArrayUtil.firstMatch(item -> item.getInterval().equals(interval), DateIntervalEnum.values()); |
|
44 |
} |
|
45 |
|
|
46 |
} |