diff --git a/src/main/java/com/spring/modules/sys/controller/DictDataController.java b/src/main/java/com/spring/modules/sys/controller/DictDataController.java index 8ccdcbad..504d288f 100644 --- a/src/main/java/com/spring/modules/sys/controller/DictDataController.java +++ b/src/main/java/com/spring/modules/sys/controller/DictDataController.java @@ -39,6 +39,19 @@ public class DictDataController { throw new RuntimeException("当前字典已存在默认值"); } } + if (!StringUtils.hasText(dictData.getDictType())){ + throw new RuntimeException("字典类型为空"); + } + if (!StringUtils.hasText(dictData.getDictValue())){ + throw new RuntimeException("字典键值为空"); + } + if (!StringUtils.hasText(dictData.getSite())){ + throw new RuntimeException("工厂编码为空"); + } + List list = dictDataService.list(new LambdaQueryWrapper().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite())); + if (null != list && !list.isEmpty()){ + throw new RuntimeException("字典键值重复"); + } if (dictDataService.save(dictData)) { return R.ok("保存成功!"); } @@ -118,7 +131,30 @@ public class DictDataController { if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){ List list = dictDataService.list(new LambdaQueryWrapper().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y")); if (null != list && !list.isEmpty()){ - throw new RuntimeException("当前字典已存在默认值"); + if (list.size() > 1){ + throw new RuntimeException("当前字典已存在默认值"); + } + if (!list.get(0).getDictCode().equals(dictData.getDictCode())){ + throw new RuntimeException("当前字典已存在默认值"); + } + } + } + if (!StringUtils.hasText(dictData.getDictType())){ + throw new RuntimeException("字典类型为空"); + } + if (!StringUtils.hasText(dictData.getDictValue())){ + throw new RuntimeException("字典键值为空"); + } + if (!StringUtils.hasText(dictData.getSite())){ + throw new RuntimeException("工厂编码为空"); + } + List list = dictDataService.list(new LambdaQueryWrapper().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite())); + if (null != list && !list.isEmpty()){ + if (list.size() > 1){ + throw new RuntimeException("字典键值重复"); + } + if (!list.get(0).getDictCode().equals(dictData.getDictCode())){ + throw new RuntimeException("字典键值重复"); } } if (dictDataService.updateById(dictData)) { diff --git a/src/main/java/com/spring/modules/sys/controller/DictTypeController.java b/src/main/java/com/spring/modules/sys/controller/DictTypeController.java index 00056c61..56940ce7 100644 --- a/src/main/java/com/spring/modules/sys/controller/DictTypeController.java +++ b/src/main/java/com/spring/modules/sys/controller/DictTypeController.java @@ -118,6 +118,21 @@ public class DictTypeController { if (Objects.isNull(dictType)||Objects.isNull(dictType.getDictId())){ throw new RuntimeException("字典编码为空"); } + if (!StringUtils.hasText(dictType.getDictType())){ + throw new RuntimeException("字典类型为空"); + } + if (!StringUtils.hasText(dictType.getSite())){ + throw new RuntimeException("工厂编码为空"); + } + List list = dictTypeService.list(new LambdaQueryWrapper().eq(DictType::getDictType, dictType.getDictType()).eq(DictType::getSite, dictType.getSite())); + if (null != list && !list.isEmpty()){ + if (list.size() > 1){ + throw new RuntimeException("该字典类型已存在!"); + } + if (!list.get(0).getDictId().equals(dictType.getDictId())){ + throw new RuntimeException("该字典类型已存在!"); + } + } if (dictTypeService.updateById(dictType)) { return R.ok("保存成功!"); }