8 天以前 48de66e32e3f509a0d212af54cda814bb7c3d4dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cn.iocoder.yudao.module.mes.enums.dv;
 
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
 
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
 
/**
 * MES 计量器具到期状态枚举
 *
 * @author 超级管理员
 */
@Getter
@AllArgsConstructor
public enum MesDvMeteringExpireStatusEnum implements ArrayValuable<Integer> {
 
    OVERDUE(1, "已过期"),
    WITHIN(2, "即将到期"),
    NORMAL(3, "正常");
 
    public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvMeteringExpireStatusEnum::getStatus).toArray(Integer[]::new);
 
    /**
     * 状态值
     */
    private final Integer status;
    /**
     * 状态名
     */
    private final String name;
 
    /**
     * 计算到期状态
     *
     * @param nextCheckDate 下次检测日期(到期日)
     * @param remindDays 提前提醒天数
     * @return 到期状态
     */
    public static Integer compute(LocalDate nextCheckDate, int remindDays) {
        if (nextCheckDate == null) {
            return NORMAL.getStatus();
        }
        long days = ChronoUnit.DAYS.between(LocalDate.now(), nextCheckDate);
        if (days < 0) {
            return OVERDUE.getStatus();
        }
        if (days <= remindDays) {
            return WITHIN.getStatus();
        }
        return NORMAL.getStatus();
    }
 
    @Override
    public Integer[] array() {
        return ARRAYS;
    }
 
}