Commit 8574ecef7b2c39dfa53a36d95411b0b32c8542c4
1 parent
d16cb13d
feat(garden): 扩展养护计划周期类型支持
- 新增周期ID选项:5(按次)、6(季度)、7(半年) - 更新维护计划服务以支持新周期类型校验 - 修改时间间隔工具类以适配新增周期计算逻辑 - 引入字典数据API用于周期类型验证 - 调整按次计划的特殊处理逻辑 - 更新相关文档描述和示例代码
Showing
3 changed files
with
53 additions
and
36 deletions
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 | 48 | @NotEmpty(message = "频次值不能为空") |
| 49 | 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 | 53 | private Integer cycleId; |
| 54 | 54 | |
| 55 | 55 | @Schema(description = "开始时间") |
| ... | ... | @@ -69,4 +69,4 @@ public class MaintainPlanSaveReqVO { |
| 69 | 69 | public boolean verify(){ |
| 70 | 70 | return StringValidateUtil.validate(rateValue); |
| 71 | 71 | } |
| 72 | -} | |
| 73 | 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 | 30 | import com.zteits.urbanops.module.garden.util.timeinterval.TimeIntervalFrequencyUtil; |
| 31 | 31 | import com.zteits.urbanops.module.system.api.dept.DeptApi; |
| 32 | 32 | import com.zteits.urbanops.module.system.api.dept.dto.DeptRespDTO; |
| 33 | +import com.zteits.urbanops.module.system.api.dict.DictDataApi; | |
| 33 | 34 | import com.zteits.urbanops.module.system.api.permission.RoleApi; |
| 34 | 35 | import com.zteits.urbanops.module.system.dal.dataobject.permission.RoleDO; |
| 35 | 36 | import jodd.util.StringUtil; |
| ... | ... | @@ -88,6 +89,14 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { |
| 88 | 89 | @Resource |
| 89 | 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 | 100 | @Override |
| 92 | 101 | public CommonResult<Integer> createMaintainPlan(MaintainPlanSaveReqVO createReqVO) { |
| 93 | 102 | //存在性校验 |
| ... | ... | @@ -105,8 +114,9 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { |
| 105 | 114 | List<PeriodResult> calculate; |
| 106 | 115 | //计算计划次数 |
| 107 | 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 | 120 | calculate = new ArrayList<>(); |
| 111 | 121 | PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); |
| 112 | 122 | calculate.add(periodResult); |
| ... | ... | @@ -422,4 +432,4 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { |
| 422 | 432 | }); |
| 423 | 433 | } |
| 424 | 434 | |
| 425 | -} | |
| 426 | 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 | import java.util.Collections; |
| 7 | 7 | import java.util.List; |
| 8 | 8 | |
| 9 | +import com.zteits.urbanops.framework.dict.core.DictFrameworkUtils; | |
| 9 | 10 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 10 | 11 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.INSPECTION_CYCLE_ID_ERROR; |
| 11 | 12 | |
| ... | ... | @@ -17,29 +18,16 @@ public class TimeIntervalFrequencyUtil { |
| 17 | 18 | |
| 18 | 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 | 35 | * @param startStr 开始日期 (yyyy-MM-dd) |
| 48 | 36 | * @param endStr 结束日期 (yyyy-MM-dd) |
| 49 | 37 | * @param freq 频次值,格式 "x/y" |
| 50 | - * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次 | |
| 38 | + * @param cycleId 1:日/次;2:周/次;3:月/次;4:年/次;5:按次;6:季度;7:半年 | |
| 51 | 39 | * @return 划分结果列表 |
| 52 | 40 | */ |
| 53 | 41 | public static List<PeriodResult> calculate(String startStr, String endStr, String freq, Integer cycleId) { |
| ... | ... | @@ -65,8 +53,7 @@ public class TimeIntervalFrequencyUtil { |
| 65 | 53 | int x = Integer.parseInt(parts[0]); // 每周期次数 |
| 66 | 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 | 58 | List<PeriodResult> results = new ArrayList<>(); |
| 72 | 59 | LocalDate currentStart = start; |
| ... | ... | @@ -93,19 +80,26 @@ public class TimeIntervalFrequencyUtil { |
| 93 | 80 | |
| 94 | 81 | /** |
| 95 | 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 | 88 | return y; |
| 101 | - case WEEK: | |
| 89 | + case 2: // WEEK | |
| 102 | 90 | return (long) y * 7; |
| 103 | - case MONTH: | |
| 91 | + case 3: // MONTH | |
| 104 | 92 | return (long) y * 30; |
| 105 | - case YEAR: | |
| 93 | + case 4: // YEAR | |
| 106 | 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 | 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 | 151 | System.out.println("\n=== 示例5:每1年4次(即:4/1),按年(测试)=== 2023-09-15 2025-01-31"); |
| 158 | 152 | List<PeriodResult> r5 = calculate("2023-09-15", "2025-01-31", "4/1", 4); |
| 159 | 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 | } | ... | ... |