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 | 72 | ErrorCode PLAN_RATE_EXISTS = new ErrorCode(1-200-200-001, "养护频次已存在"); |
| 73 | 73 | ErrorCode PLAN_RATE_LEVEL_ID_DUPLICATE = new ErrorCode(1-200-200-002, "养护等级重复"); |
| 74 | 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 | 77 | ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在"); |
| 77 | 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
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 | 4 | import cn.hutool.core.util.RandomUtil; |
| 5 | 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 6 | 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 | 10 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; |
| 8 | 11 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 9 | 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 | 27 | |
| 25 | 28 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 26 | 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 | 33 | * 计划频次 Service 实现类 |
| ... | ... | @@ -40,6 +44,9 @@ public class PlanRateServiceImpl implements PlanRateService { |
| 40 | 44 | @Resource |
| 41 | 45 | private PlanRateDetailMapper planRateDetailMapper; |
| 42 | 46 | |
| 47 | + @Resource | |
| 48 | + private DictDataCommonApi dictDataCommonApi; | |
| 49 | + | |
| 43 | 50 | @Transactional(rollbackFor = Exception.class) |
| 44 | 51 | @Override |
| 45 | 52 | public Long createPlanRate(PlanRateSaveReqVO createReqVO) { |
| ... | ... | @@ -75,6 +82,7 @@ public class PlanRateServiceImpl implements PlanRateService { |
| 75 | 82 | detailDO.setUpdater(userName); |
| 76 | 83 | detailDO.setUpdateTime(now); |
| 77 | 84 | list.add(detailDO); |
| 85 | + validatePlanRateDetailExists(createReqVO.getBusiLine(), createReqVO.getPlanTypeId(), detail.getLevelId()); | |
| 78 | 86 | }); |
| 79 | 87 | /*2.插入频次明细*/ |
| 80 | 88 | planRateDetailMapper.insertBatch(list); |
| ... | ... | @@ -112,6 +120,7 @@ public class PlanRateServiceImpl implements PlanRateService { |
| 112 | 120 | detailDO.setUpdater(userName); |
| 113 | 121 | detailDO.setUpdateTime(now); |
| 114 | 122 | list.add(detailDO); |
| 123 | + validatePlanRateDetailExists(updateReqVO.getBusiLine(), updateReqVO.getPlanTypeId(), detail.getLevelId()); | |
| 115 | 124 | }); |
| 116 | 125 | /*3.插入频次明细*/ |
| 117 | 126 | planRateDetailMapper.insertBatch(list); |
| ... | ... | @@ -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 | 174 | @Override |
| 150 | 175 | public PlanRateDO getPlanRate(Long id) { |
| 151 | 176 | return planRateMapper.selectById(id); | ... | ... |