Commit 11a7c51cd25727abb707546d1b4f3d2d3504baa7
1 parent
32410eb7
养护频次重复校验
Showing
3 changed files
with
30 additions
and
0 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java
| @@ -72,6 +72,7 @@ public interface ErrorCodeConstants { | @@ -72,6 +72,7 @@ public interface ErrorCodeConstants { | ||
| 72 | ErrorCode PLAN_RATE_EXISTS = new ErrorCode(1-200-200-001, "养护频次已存在"); | 72 | ErrorCode PLAN_RATE_EXISTS = new ErrorCode(1-200-200-001, "养护频次已存在"); |
| 73 | ErrorCode PLAN_RATE_LEVEL_ID_DUPLICATE = new ErrorCode(1-200-200-002, "养护等级重复"); | 73 | ErrorCode PLAN_RATE_LEVEL_ID_DUPLICATE = new ErrorCode(1-200-200-002, "养护等级重复"); |
| 74 | ErrorCode PLAN_RATE_NOT_EXISTS = new ErrorCode(1-200-200-002, "未配置计划频次"); | 74 | ErrorCode PLAN_RATE_NOT_EXISTS = new ErrorCode(1-200-200-002, "未配置计划频次"); |
| 75 | + ErrorCode PLAN_RATE_DETAIL_EXISTS = new ErrorCode(1-200-200-003, "计划频次已存在"); | ||
| 75 | 76 | ||
| 76 | ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在"); | 77 | ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在"); |
| 77 | ErrorCode MATERIAL_TYPE_MANAGER_NOT_EXISTS = new ErrorCode(1-100-004-002, "耗材类别管理不存在"); | 78 | ErrorCode MATERIAL_TYPE_MANAGER_NOT_EXISTS = new ErrorCode(1-100-004-002, "耗材类别管理不存在"); |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/PlanConstants.java
| @@ -7,4 +7,8 @@ public class PlanConstants { | @@ -7,4 +7,8 @@ public class PlanConstants { | ||
| 7 | 7 | ||
| 8 | /*周期-cycle_id_type-字典key*/ | 8 | /*周期-cycle_id_type-字典key*/ |
| 9 | public static final String CYCLE_ID_TYPE = "cycle_id_type"; | 9 | public static final String CYCLE_ID_TYPE = "cycle_id_type"; |
| 10 | + | ||
| 11 | + /*养护级别-字典key*/ | ||
| 12 | + public static final String CONSERVE_LEVEL = "conserve_level"; | ||
| 13 | + | ||
| 10 | } | 14 | } |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/planrate/PlanRateServiceImpl.java
| @@ -4,6 +4,9 @@ import cn.hutool.core.date.DateUtil; | @@ -4,6 +4,9 @@ import cn.hutool.core.date.DateUtil; | ||
| 4 | import cn.hutool.core.util.RandomUtil; | 4 | import cn.hutool.core.util.RandomUtil; |
| 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 6 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 6 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| 7 | +import com.zteits.urbanops.framework.common.biz.system.dict.DictDataCommonApi; | ||
| 8 | +import com.zteits.urbanops.framework.common.biz.system.dict.dto.DictDataRespDTO; | ||
| 9 | +import com.zteits.urbanops.framework.common.exception.ServiceException; | ||
| 7 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; | 10 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; |
| 8 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; | 11 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 9 | import com.zteits.urbanops.module.garden.dal.dataobject.planrate.PlanRateDetailDO; | 12 | import com.zteits.urbanops.module.garden.dal.dataobject.planrate.PlanRateDetailDO; |
| @@ -24,6 +27,7 @@ import com.zteits.urbanops.module.garden.dal.mysql.planrate.PlanRateMapper; | @@ -24,6 +27,7 @@ import com.zteits.urbanops.module.garden.dal.mysql.planrate.PlanRateMapper; | ||
| 24 | 27 | ||
| 25 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; | 28 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 26 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; | 29 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; |
| 30 | +import static com.zteits.urbanops.module.garden.enums.PlanConstants.CONSERVE_LEVEL; | ||
| 27 | 31 | ||
| 28 | /** | 32 | /** |
| 29 | * 计划频次 Service 实现类 | 33 | * 计划频次 Service 实现类 |
| @@ -40,6 +44,9 @@ public class PlanRateServiceImpl implements PlanRateService { | @@ -40,6 +44,9 @@ public class PlanRateServiceImpl implements PlanRateService { | ||
| 40 | @Resource | 44 | @Resource |
| 41 | private PlanRateDetailMapper planRateDetailMapper; | 45 | private PlanRateDetailMapper planRateDetailMapper; |
| 42 | 46 | ||
| 47 | + @Resource | ||
| 48 | + private DictDataCommonApi dictDataCommonApi; | ||
| 49 | + | ||
| 43 | @Transactional(rollbackFor = Exception.class) | 50 | @Transactional(rollbackFor = Exception.class) |
| 44 | @Override | 51 | @Override |
| 45 | public Long createPlanRate(PlanRateSaveReqVO createReqVO) { | 52 | public Long createPlanRate(PlanRateSaveReqVO createReqVO) { |
| @@ -75,6 +82,7 @@ public class PlanRateServiceImpl implements PlanRateService { | @@ -75,6 +82,7 @@ public class PlanRateServiceImpl implements PlanRateService { | ||
| 75 | detailDO.setUpdater(userName); | 82 | detailDO.setUpdater(userName); |
| 76 | detailDO.setUpdateTime(now); | 83 | detailDO.setUpdateTime(now); |
| 77 | list.add(detailDO); | 84 | list.add(detailDO); |
| 85 | + validatePlanRateDetailExists(createReqVO.getBusiLine(), createReqVO.getPlanTypeId(), detail.getLevelId()); | ||
| 78 | }); | 86 | }); |
| 79 | /*2.插入频次明细*/ | 87 | /*2.插入频次明细*/ |
| 80 | planRateDetailMapper.insertBatch(list); | 88 | planRateDetailMapper.insertBatch(list); |
| @@ -112,6 +120,7 @@ public class PlanRateServiceImpl implements PlanRateService { | @@ -112,6 +120,7 @@ public class PlanRateServiceImpl implements PlanRateService { | ||
| 112 | detailDO.setUpdater(userName); | 120 | detailDO.setUpdater(userName); |
| 113 | detailDO.setUpdateTime(now); | 121 | detailDO.setUpdateTime(now); |
| 114 | list.add(detailDO); | 122 | list.add(detailDO); |
| 123 | + validatePlanRateDetailExists(updateReqVO.getBusiLine(), updateReqVO.getPlanTypeId(), detail.getLevelId()); | ||
| 115 | }); | 124 | }); |
| 116 | /*3.插入频次明细*/ | 125 | /*3.插入频次明细*/ |
| 117 | planRateDetailMapper.insertBatch(list); | 126 | planRateDetailMapper.insertBatch(list); |
| @@ -146,6 +155,22 @@ public class PlanRateServiceImpl implements PlanRateService { | @@ -146,6 +155,22 @@ public class PlanRateServiceImpl implements PlanRateService { | ||
| 146 | } | 155 | } |
| 147 | } | 156 | } |
| 148 | 157 | ||
| 158 | + /** | ||
| 159 | + * 养护明细是否重复 | ||
| 160 | + * @param planTypeId 养护类型 | ||
| 161 | + * @param busiLine 业务线 | ||
| 162 | + * @param levelId 道路等级 | ||
| 163 | + */ | ||
| 164 | + private void validatePlanRateDetailExists(String busiLine, Integer planTypeId, Integer levelId) { | ||
| 165 | + QueryWrapper<PlanRateDetailDO> sql = new QueryWrapper<>(); | ||
| 166 | + sql.lambda().eq(PlanRateDetailDO::getPlanTypeId, planTypeId).eq(PlanRateDetailDO::getBusiLine, busiLine) | ||
| 167 | + .eq(PlanRateDetailDO::getLevelId, levelId); | ||
| 168 | + if (planRateDetailMapper.selectCount(sql) > 0) { | ||
| 169 | + DictDataRespDTO dictData = dictDataCommonApi.getDictData(CONSERVE_LEVEL, levelId.toString()); | ||
| 170 | + throw new ServiceException(PLAN_RATE_DETAIL_EXISTS.getCode(), "养护等级[" + dictData.getLabel() + "]已存在"); | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + | ||
| 149 | @Override | 174 | @Override |
| 150 | public PlanRateDO getPlanRate(Long id) { | 175 | public PlanRateDO getPlanRate(Long id) { |
| 151 | return planRateMapper.selectById(id); | 176 | return planRateMapper.selectById(id); |