Commit 8574ecef7b2c39dfa53a36d95411b0b32c8542c4

Authored by 王彪总
1 parent d16cb13d

feat(garden): 扩展养护计划周期类型支持

- 新增周期ID选项:5(按次)、6(季度)、7(半年)
- 更新维护计划服务以支持新周期类型校验
- 修改时间间隔工具类以适配新增周期计算逻辑
- 引入字典数据API用于周期类型验证
- 调整按次计划的特殊处理逻辑
- 更新相关文档描述和示例代码
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/vo/MaintainPlanSaveReqVO.java
@@ -48,8 +48,8 @@ public class MaintainPlanSaveReqVO { @@ -48,8 +48,8 @@ public class MaintainPlanSaveReqVO {
48 @NotEmpty(message = "频次值不能为空") 48 @NotEmpty(message = "频次值不能为空")
49 private String rateValue; 49 private String rateValue;
50 50
51 - @Schema(description = "周期ID: 1:日/次;2:周/次;3:月/次;4:年/次", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")  
52 - @NotNull(message = "周期ID: 1:日/次;2:周/次;3:月/次;4:年/次不能为空") 51 + @Schema(description = "周期ID: 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  52 + @NotNull(message = "周期ID: 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年")
53 private Integer cycleId; 53 private Integer cycleId;
54 54
55 @Schema(description = "开始时间") 55 @Schema(description = "开始时间")
@@ -69,4 +69,4 @@ public class MaintainPlanSaveReqVO { @@ -69,4 +69,4 @@ public class MaintainPlanSaveReqVO {
69 public boolean verify(){ 69 public boolean verify(){
70 return StringValidateUtil.validate(rateValue); 70 return StringValidateUtil.validate(rateValue);
71 } 71 }
72 -}  
73 \ No newline at end of file 72 \ No newline at end of file
  73 +}
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java
@@ -30,6 +30,7 @@ import com.zteits.urbanops.module.garden.util.timeinterval.PeriodResult; @@ -30,6 +30,7 @@ import com.zteits.urbanops.module.garden.util.timeinterval.PeriodResult;
30 import com.zteits.urbanops.module.garden.util.timeinterval.TimeIntervalFrequencyUtil; 30 import com.zteits.urbanops.module.garden.util.timeinterval.TimeIntervalFrequencyUtil;
31 import com.zteits.urbanops.module.system.api.dept.DeptApi; 31 import com.zteits.urbanops.module.system.api.dept.DeptApi;
32 import com.zteits.urbanops.module.system.api.dept.dto.DeptRespDTO; 32 import com.zteits.urbanops.module.system.api.dept.dto.DeptRespDTO;
  33 +import com.zteits.urbanops.module.system.api.dict.DictDataApi;
33 import com.zteits.urbanops.module.system.api.permission.RoleApi; 34 import com.zteits.urbanops.module.system.api.permission.RoleApi;
34 import com.zteits.urbanops.module.system.dal.dataobject.permission.RoleDO; 35 import com.zteits.urbanops.module.system.dal.dataobject.permission.RoleDO;
35 import jodd.util.StringUtil; 36 import jodd.util.StringUtil;
@@ -88,6 +89,14 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { @@ -88,6 +89,14 @@ public class MaintainPlanServiceImpl implements MaintainPlanService {
88 @Resource 89 @Resource
89 private RoleApi roleApi; 90 private RoleApi roleApi;
90 91
  92 + @Resource
  93 + private DictDataApi dictDataApi;
  94 +
  95 + /**
  96 + * 字典类型:养护周期类型
  97 + */
  98 + private static final String DICT_TYPE_CYCLE_ID = "cycle_id_type";
  99 +
91 @Override 100 @Override
92 public CommonResult<Integer> createMaintainPlan(MaintainPlanSaveReqVO createReqVO) { 101 public CommonResult<Integer> createMaintainPlan(MaintainPlanSaveReqVO createReqVO) {
93 //存在性校验 102 //存在性校验
@@ -105,8 +114,9 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { @@ -105,8 +114,9 @@ public class MaintainPlanServiceImpl implements MaintainPlanService {
105 List<PeriodResult> calculate; 114 List<PeriodResult> calculate;
106 //计算计划次数 115 //计算计划次数
107 int planNum; 116 int planNum;
108 - //临时计划比较特殊  
109 - if (createReqVO.getPlanAttr().equals(2)) { 117 + //按次计划
  118 + dictDataApi.validateDictDataList(DICT_TYPE_CYCLE_ID, Collections.singleton(createReqVO.getCycleId().toString().trim()));
  119 + if (createReqVO.getCycleId().equals(1)) {
110 calculate = new ArrayList<>(); 120 calculate = new ArrayList<>();
111 PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); 121 PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue()));
112 calculate.add(periodResult); 122 calculate.add(periodResult);
@@ -422,4 +432,4 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { @@ -422,4 +432,4 @@ public class MaintainPlanServiceImpl implements MaintainPlanService {
422 }); 432 });
423 } 433 }
424 434
425 -}  
426 \ No newline at end of file 435 \ No newline at end of file
  436 +}
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/timeinterval/TimeIntervalFrequencyUtil.java
@@ -6,6 +6,7 @@ import java.util.ArrayList; @@ -6,6 +6,7 @@ import java.util.ArrayList;
6 import java.util.Collections; 6 import java.util.Collections;
7 import java.util.List; 7 import java.util.List;
8 8
  9 +import com.zteits.urbanops.framework.dict.core.DictFrameworkUtils;
9 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; 10 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception;
10 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.INSPECTION_CYCLE_ID_ERROR; 11 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.INSPECTION_CYCLE_ID_ERROR;
11 12
@@ -17,29 +18,16 @@ public class TimeIntervalFrequencyUtil { @@ -17,29 +18,16 @@ public class TimeIntervalFrequencyUtil {
17 18
18 private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 19 private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
19 20
20 - public enum IntervalUnit {  
21 - DAY, WEEK, MONTH, YEAR;  
22 - } 21 +
23 22
24 /** 23 /**
25 - * 转换枚举  
26 - * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次  
27 - * @return 24 + * 根据cycleId获取对应的字典值
  25 + * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年
  26 + * @return 对应的字典值
28 */ 27 */
29 - public static IntervalUnit getIntervalUnit(Integer cycleId) {  
30 - switch (cycleId) {  
31 - case 1:  
32 - return IntervalUnit.DAY;  
33 - case 2:  
34 - return IntervalUnit.WEEK;  
35 - case 3:  
36 - return IntervalUnit.MONTH;  
37 - case 4:  
38 - return IntervalUnit.YEAR;  
39 - default:  
40 - throw exception(INSPECTION_CYCLE_ID_ERROR);  
41 - }  
42 - } 28 + public static String getCycleTypeValue(Integer cycleId) {
  29 + // 使用DictFrameworkUtils从字典表获取对应的周期类型值
  30 + return String.valueOf(cycleId); }
43 31
44 /** 32 /**
45 * 计算时间段划分结果(基于固定天数换算) 33 * 计算时间段划分结果(基于固定天数换算)
@@ -47,7 +35,7 @@ public class TimeIntervalFrequencyUtil { @@ -47,7 +35,7 @@ public class TimeIntervalFrequencyUtil {
47 * @param startStr 开始日期 (yyyy-MM-dd) 35 * @param startStr 开始日期 (yyyy-MM-dd)
48 * @param endStr 结束日期 (yyyy-MM-dd) 36 * @param endStr 结束日期 (yyyy-MM-dd)
49 * @param freq 频次值,格式 "x/y" 37 * @param freq 频次值,格式 "x/y"
50 - * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次 38 + * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年
51 * @return 划分结果列表 39 * @return 划分结果列表
52 */ 40 */
53 public static List<PeriodResult> calculate(String startStr, String endStr, String freq, Integer cycleId) { 41 public static List<PeriodResult> calculate(String startStr, String endStr, String freq, Integer cycleId) {
@@ -65,8 +53,7 @@ public class TimeIntervalFrequencyUtil { @@ -65,8 +53,7 @@ public class TimeIntervalFrequencyUtil {
65 int x = Integer.parseInt(parts[0]); // 每周期次数 53 int x = Integer.parseInt(parts[0]); // 每周期次数
66 int y = Integer.parseInt(parts[1]); // 周期数量 54 int y = Integer.parseInt(parts[1]); // 周期数量
67 55
68 - IntervalUnit unit = getIntervalUnit(cycleId);  
69 - long periodDays = convertToDays(y, unit); // 转为固定天数 56 + long periodDays = convertToDays(y, cycleId); // 转为固定天数
70 57
71 List<PeriodResult> results = new ArrayList<>(); 58 List<PeriodResult> results = new ArrayList<>();
72 LocalDate currentStart = start; 59 LocalDate currentStart = start;
@@ -93,19 +80,26 @@ public class TimeIntervalFrequencyUtil { @@ -93,19 +80,26 @@ public class TimeIntervalFrequencyUtil {
93 80
94 /** 81 /**
95 * 将 y 个单位转换为固定天数 82 * 将 y 个单位转换为固定天数
  83 + * 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年
96 */ 84 */
97 - private static long convertToDays(int y, IntervalUnit unit) {  
98 - switch (unit) {  
99 - case DAY: 85 + private static long convertToDays(int y, Integer cycleId) {
  86 + switch (cycleId) {
  87 + case 1: // DAY
100 return y; 88 return y;
101 - case WEEK: 89 + case 2: // WEEK
102 return (long) y * 7; 90 return (long) y * 7;
103 - case MONTH: 91 + case 3: // MONTH
104 return (long) y * 30; 92 return (long) y * 30;
105 - case YEAR: 93 + case 4: // YEAR
106 return (long) y * 365; 94 return (long) y * 365;
  95 + case 5: // TIME
  96 + return 1; // 按次:将整个时间段视为1个周期
  97 + case 6: // QUARTER
  98 + return (long) y * 90; // 1季度=3个月=90天
  99 + case 7: // SEMIANNUAL
  100 + return (long) y * 180; // 半年=6个月=180天
107 default: 101 default:
108 - throw new UnsupportedOperationException("不支持的单位: " + unit); 102 + throw new IllegalArgumentException("无效的周期ID: " + cycleId);
109 } 103 }
110 } 104 }
111 105
@@ -157,5 +151,18 @@ public class TimeIntervalFrequencyUtil { @@ -157,5 +151,18 @@ public class TimeIntervalFrequencyUtil {
157 System.out.println("\n=== 示例5:每1年4次(即:4/1),按年(测试)=== 2023-09-15 2025-01-31"); 151 System.out.println("\n=== 示例5:每1年4次(即:4/1),按年(测试)=== 2023-09-15 2025-01-31");
158 List<PeriodResult> r5 = calculate("2023-09-15", "2025-01-31", "4/1", 4); 152 List<PeriodResult> r5 = calculate("2023-09-15", "2025-01-31", "4/1", 4);
159 r5.forEach(System.out::println); 153 r5.forEach(System.out::println);
  154 +
  155 + // 新增示例:按次、季度、半年
  156 + System.out.println("\n=== 示例6:按次单位,整个时间段算1个周期 === 2025-01-01 2025-12-31");
  157 + List<PeriodResult> r6 = calculate("2025-01-01", "2025-12-31", "2/1", 5);
  158 + r6.forEach(System.out::println);
  159 +
  160 + System.out.println("\n=== 示例7:每1季度2次(即:2/1),按季度(90天)=== 2025-01-01 2025-12-31");
  161 + List<PeriodResult> r7 = calculate("2025-01-01", "2025-12-31", "2/1", 6);
  162 + r7.forEach(System.out::println);
  163 +
  164 + System.out.println("\n=== 示例8:每1半年3次(即:3/1),按半年(180天)=== 2025-01-01 2025-12-31");
  165 + List<PeriodResult> r8 = calculate("2025-01-01", "2025-12-31", "3/1", 7);
  166 + r8.forEach(System.out::println);
160 } 167 }
161 } 168 }