Browse Source

2024-1-5 字典校验

master
zelian_wu 2 years ago
parent
commit
93efd00977
  1. 38
      src/main/java/com/spring/modules/sys/controller/DictDataController.java
  2. 15
      src/main/java/com/spring/modules/sys/controller/DictTypeController.java

38
src/main/java/com/spring/modules/sys/controller/DictDataController.java

@ -39,6 +39,19 @@ public class DictDataController {
throw new RuntimeException("当前字典已存在默认值"); 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<DictData> list = dictDataService.list(new LambdaQueryWrapper<DictData>().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)) { if (dictDataService.save(dictData)) {
return R.ok("保存成功!"); return R.ok("保存成功!");
} }
@ -118,7 +131,30 @@ public class DictDataController {
if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){ if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){
List<DictData> list = dictDataService.list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y")); List<DictData> list = dictDataService.list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y"));
if (null != list && !list.isEmpty()){ 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<DictData> list = dictDataService.list(new LambdaQueryWrapper<DictData>().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)) { if (dictDataService.updateById(dictData)) {

15
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())){ if (Objects.isNull(dictType)||Objects.isNull(dictType.getDictId())){
throw new RuntimeException("字典编码为空"); throw new RuntimeException("字典编码为空");
} }
if (!StringUtils.hasText(dictType.getDictType())){
throw new RuntimeException("字典类型为空");
}
if (!StringUtils.hasText(dictType.getSite())){
throw new RuntimeException("工厂编码为空");
}
List<DictType> list = dictTypeService.list(new LambdaQueryWrapper<DictType>().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)) { if (dictTypeService.updateById(dictType)) {
return R.ok("保存成功!"); return R.ok("保存成功!");
} }

Loading…
Cancel
Save