Commit d58a0f8d3c6994f7d195fb453844fd17c711deb8
1 parent
c3c48b97
feat(garden): 引入养护周期枚举并优化计划创建逻辑
- 新增 MaintenanceCycleEnum 枚举类,定义养护周期类型及其键值映射 - 在 InspectionPlanServiceImpl 和 MaintainPlanServiceImpl 中引入该枚举 - 替换硬编码的周期 ID 判断逻辑,使用枚举提升可读性和维护性 - 统一字典类型常量引用,移除重复定义 - 增强对周期ID的数据校验,确保输入合法性
Showing
3 changed files
with
87 additions
and
6 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/MaintenanceCycleEnum.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.enums; | |
| 2 | + | |
| 3 | +import java.util.HashMap; | |
| 4 | +import java.util.Map; | |
| 5 | + | |
| 6 | +public enum MaintenanceCycleEnum { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 字典标签与字典键值对应关系: | |
| 10 | + * 次 → 0 | |
| 11 | + * 次/日 → 1 | |
| 12 | + * 次/周 → 2 | |
| 13 | + * 次/月 → 3 | |
| 14 | + * 次/季 → 4 | |
| 15 | + * 次/半年 → 5 | |
| 16 | + * 次/年 → 6 | |
| 17 | + */ | |
| 18 | + TIME(0, "次"), | |
| 19 | + DAY(1, "次/日"), | |
| 20 | + WEEK(2, "次/周"), | |
| 21 | + MONTH(3, "次/月"), | |
| 22 | + QUARTER(4, "次/季"), | |
| 23 | + SEMIANNUAL(5, "次/半年"), | |
| 24 | + YEAR(6, "次/年"); | |
| 25 | + | |
| 26 | + private final Integer key; | |
| 27 | + private final String value; | |
| 28 | + | |
| 29 | + // 用于根据key快速查找枚举 | |
| 30 | + private static final Map<Integer, MaintenanceCycleEnum> KEY_MAP = new HashMap<>(); | |
| 31 | + | |
| 32 | + static { | |
| 33 | + // 初始化key映射 | |
| 34 | + for (MaintenanceCycleEnum cycleEnum : values()) { | |
| 35 | + KEY_MAP.put(cycleEnum.key, cycleEnum); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 构造函数 | |
| 41 | + * @param key 字典键值 | |
| 42 | + * @param value 字典标签 | |
| 43 | + */ | |
| 44 | + MaintenanceCycleEnum(Integer key, String value) { | |
| 45 | + this.key = key; | |
| 46 | + this.value = value; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 根据key获取对应的枚举 | |
| 51 | + * @param key 字典键值 | |
| 52 | + * @return 对应的枚举,如果不存在返回null | |
| 53 | + */ | |
| 54 | + public static MaintenanceCycleEnum getByKey(Integer key) { | |
| 55 | + return KEY_MAP.get(key); | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 根据key获取对应的字典标签 | |
| 60 | + * @param key 字典键值 | |
| 61 | + * @return 对应的字典标签,如果不存在返回null | |
| 62 | + */ | |
| 63 | + public static String getValueByKey(Integer key) { | |
| 64 | + MaintenanceCycleEnum cycleEnum = getByKey(key); | |
| 65 | + return cycleEnum != null ? cycleEnum.value : null; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public Integer getKey() { | |
| 69 | + return key; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public String getValue() { | |
| 73 | + return value; | |
| 74 | + } | |
| 75 | +} | |
| 0 | 76 | \ No newline at end of file | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java
| ... | ... | @@ -24,11 +24,13 @@ import com.zteits.urbanops.module.garden.dal.mysql.inspectionplan.InspectionPlan |
| 24 | 24 | import com.zteits.urbanops.module.garden.dal.mysql.inspectionplan.InspectionPlanRoleMapper; |
| 25 | 25 | import com.zteits.urbanops.module.garden.dal.mysql.road.RoadMapper; |
| 26 | 26 | import com.zteits.urbanops.module.garden.enums.FinishStateEnum; |
| 27 | +import com.zteits.urbanops.module.garden.enums.MaintenanceCycleEnum; | |
| 27 | 28 | import com.zteits.urbanops.module.garden.enums.PlanConstants; |
| 28 | 29 | import com.zteits.urbanops.module.garden.util.timeinterval.PeriodResult; |
| 29 | 30 | import com.zteits.urbanops.module.garden.util.timeinterval.TimeIntervalFrequencyUtil; |
| 30 | 31 | import com.zteits.urbanops.module.system.api.dept.DeptApi; |
| 31 | 32 | import com.zteits.urbanops.module.system.api.dept.dto.DeptRespDTO; |
| 33 | +import com.zteits.urbanops.module.system.api.dict.DictDataApi; | |
| 32 | 34 | import com.zteits.urbanops.module.system.api.permission.RoleApi; |
| 33 | 35 | import com.zteits.urbanops.module.system.dal.dataobject.permission.RoleDO; |
| 34 | 36 | import jakarta.annotation.Resource; |
| ... | ... | @@ -48,6 +50,7 @@ import java.util.stream.Collectors; |
| 48 | 50 | |
| 49 | 51 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 50 | 52 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; |
| 53 | +import static com.zteits.urbanops.module.garden.enums.PlanConstants.CYCLE_ID_TYPE; | |
| 51 | 54 | |
| 52 | 55 | /** |
| 53 | 56 | * 巡检计划汇总 Service 实现类 |
| ... | ... | @@ -73,13 +76,13 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { |
| 73 | 76 | |
| 74 | 77 | @Resource |
| 75 | 78 | private RoadMapper roadMapper; |
| 76 | - | |
| 77 | - | |
| 78 | 79 | @Resource |
| 79 | 80 | private DeptApi deptApi; |
| 80 | 81 | |
| 81 | 82 | @Resource |
| 82 | 83 | private RoleApi roleApi; |
| 84 | + @Resource | |
| 85 | + private DictDataApi dictDataApi; | |
| 83 | 86 | |
| 84 | 87 | @Transactional(rollbackFor = Exception.class) |
| 85 | 88 | @Override |
| ... | ... | @@ -100,7 +103,8 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { |
| 100 | 103 | //计算计划次数 |
| 101 | 104 | int planNum; |
| 102 | 105 | //临时计划 |
| 103 | - if (createReqVO.getCycleId().equals(5)) { | |
| 106 | + dictDataApi.validateDictDataList(CYCLE_ID_TYPE, Collections.singleton(createReqVO.getCycleId().toString().trim())); | |
| 107 | + if (createReqVO.getCycleId().equals(MaintenanceCycleEnum.TIME.getKey())) { | |
| 104 | 108 | calculate = new ArrayList<>(); |
| 105 | 109 | PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); |
| 106 | 110 | calculate.add(periodResult); | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java
| ... | ... | @@ -25,6 +25,7 @@ import com.zteits.urbanops.module.garden.dal.mysql.maintainplan.MaintainPlanInte |
| 25 | 25 | import com.zteits.urbanops.module.garden.dal.mysql.maintainplan.MaintainPlanRoleMapper; |
| 26 | 26 | import com.zteits.urbanops.module.garden.dal.mysql.road.RoadMapper; |
| 27 | 27 | import com.zteits.urbanops.module.garden.enums.FinishStateEnum; |
| 28 | +import com.zteits.urbanops.module.garden.enums.MaintenanceCycleEnum; | |
| 28 | 29 | import com.zteits.urbanops.module.garden.enums.PlanConstants; |
| 29 | 30 | import com.zteits.urbanops.module.garden.util.timeinterval.PeriodResult; |
| 30 | 31 | import com.zteits.urbanops.module.garden.util.timeinterval.TimeIntervalFrequencyUtil; |
| ... | ... | @@ -57,6 +58,8 @@ import com.zteits.urbanops.module.garden.dal.mysql.maintainplan.MaintainPlanMapp |
| 57 | 58 | |
| 58 | 59 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 59 | 60 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; |
| 61 | +import static com.zteits.urbanops.module.garden.enums.PlanConstants.CYCLE_ID_TYPE; | |
| 62 | + | |
| 60 | 63 | |
| 61 | 64 | /** |
| 62 | 65 | * 养护计划汇总 Service 实现类 |
| ... | ... | @@ -95,7 +98,6 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { |
| 95 | 98 | /** |
| 96 | 99 | * 字典类型:养护周期类型 |
| 97 | 100 | */ |
| 98 | - private static final String DICT_TYPE_CYCLE_ID = "cycle_id_type"; | |
| 99 | 101 | |
| 100 | 102 | @Override |
| 101 | 103 | public CommonResult<Integer> createMaintainPlan(MaintainPlanSaveReqVO createReqVO) { |
| ... | ... | @@ -115,8 +117,8 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { |
| 115 | 117 | //计算计划次数 |
| 116 | 118 | int planNum; |
| 117 | 119 | //按次计划 |
| 118 | - dictDataApi.validateDictDataList(DICT_TYPE_CYCLE_ID, Collections.singleton(createReqVO.getCycleId().toString().trim())); | |
| 119 | - if (createReqVO.getCycleId().equals(5)) { | |
| 120 | + dictDataApi.validateDictDataList(CYCLE_ID_TYPE, Collections.singleton(createReqVO.getCycleId().toString().trim())); | |
| 121 | + if (createReqVO.getCycleId().equals(MaintenanceCycleEnum.TIME.getKey())) { | |
| 120 | 122 | calculate = new ArrayList<>(); |
| 121 | 123 | PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); |
| 122 | 124 | calculate.add(periodResult); | ... | ... |