|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+package com.ruoyi.web.modules.industryservice.support;
|
|
|
2
|
+
|
|
|
3
|
+import java.time.YearMonth;
|
|
|
4
|
+import java.util.ArrayList;
|
|
|
5
|
+import java.util.Collections;
|
|
|
6
|
+import java.util.List;
|
|
|
7
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
8
|
+
|
|
|
9
|
+/**
|
|
|
10
|
+ * 填报月份选项与年月合法性校验
|
|
|
11
|
+ */
|
|
|
12
|
+public final class YakHerdInventoryMonthSupport
|
|
|
13
|
+{
|
|
|
14
|
+ public static final int MIN_MONTH = 1;
|
|
|
15
|
+
|
|
|
16
|
+ public static final int MAX_MONTH = 12;
|
|
|
17
|
+
|
|
|
18
|
+ private YakHerdInventoryMonthSupport()
|
|
|
19
|
+ {
|
|
|
20
|
+ }
|
|
|
21
|
+
|
|
|
22
|
+ public static List<Integer> resolveMonthOptions()
|
|
|
23
|
+ {
|
|
|
24
|
+ List<Integer> months = new ArrayList<>();
|
|
|
25
|
+ for (int m = MIN_MONTH; m <= MAX_MONTH; m++)
|
|
|
26
|
+ {
|
|
|
27
|
+ months.add(m);
|
|
|
28
|
+ }
|
|
|
29
|
+ return Collections.unmodifiableList(months);
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
|
32
|
+ public static boolean isValidMonth(Integer statMonth)
|
|
|
33
|
+ {
|
|
|
34
|
+ return statMonth != null && statMonth >= MIN_MONTH && statMonth <= MAX_MONTH;
|
|
|
35
|
+ }
|
|
|
36
|
+
|
|
|
37
|
+ /**
|
|
|
38
|
+ * 校验填报年月:年份在可选范围内、月份 1–12、不可填报未来月份。
|
|
|
39
|
+ */
|
|
|
40
|
+ public static void validateStatPeriod(Integer statYear, Integer statMonth)
|
|
|
41
|
+ {
|
|
|
42
|
+ if (statYear == null)
|
|
|
43
|
+ {
|
|
|
44
|
+ throw new ServiceException("所属年份不能为空");
|
|
|
45
|
+ }
|
|
|
46
|
+ if (!YakHerdInventoryYearSupport.isAllowedYear(statYear))
|
|
|
47
|
+ {
|
|
|
48
|
+ throw new ServiceException("所属年份不在可选范围内");
|
|
|
49
|
+ }
|
|
|
50
|
+ if (!isValidMonth(statMonth))
|
|
|
51
|
+ {
|
|
|
52
|
+ throw new ServiceException("所属月份不合法");
|
|
|
53
|
+ }
|
|
|
54
|
+ YearMonth selected = YearMonth.of(statYear, statMonth);
|
|
|
55
|
+ if (selected.isAfter(YearMonth.now()))
|
|
|
56
|
+ {
|
|
|
57
|
+ throw new ServiceException("不能填报未来月份");
|
|
|
58
|
+ }
|
|
|
59
|
+ }
|
|
|
60
|
+}
|