|
@@ -27,6 +27,7 @@ import java.util.Collection;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
|
@@ -81,6 +82,8 @@ public class DictDataTenantServiceImpl implements DictDataTenantService {
|
|
|
validateDictTypeExists(createReqVO.getDictType());
|
|
|
// 校验字典数据的值的唯一性
|
|
|
// validateDictDataValueUnique(null, createReqVO.getDictType(), createReqVO.getValue());
|
|
|
+ // 校验字典数据的label的唯一性
|
|
|
+ validateDictDataLabelUnique(null, createReqVO.getDictType(), createReqVO.getLabel());
|
|
|
|
|
|
// 插入字典类型
|
|
|
DictDataTenantDO dictData = BeanUtils.toBean(createReqVO, DictDataTenantDO.class);
|
|
@@ -104,11 +107,19 @@ public class DictDataTenantServiceImpl implements DictDataTenantService {
|
|
|
@Override
|
|
|
public void updateDictData(DictDataTenantUpdateReqVO updateReqVO) {
|
|
|
// 校验自己存在
|
|
|
- validateDictDataExists(updateReqVO.getId());
|
|
|
+ DictDataTenantDO dictDataTenantDO = validateDictDataExists(updateReqVO.getId());
|
|
|
+ // 内置角色label不能修改
|
|
|
+ if (dictDataTenantDO.getDataType() != null && dictDataTenantDO.getDataType() == 1) {
|
|
|
+ if (!Objects.equals(dictDataTenantDO.getLabel(), updateReqVO.getLabel())) {
|
|
|
+ throw exception(DICT_DATA_CAN_NOT_UPDATE_LABEL_SYSTEM_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 校验字典类型有效
|
|
|
// validateDictTypeExists(updateReqVO.getDictType());
|
|
|
// 校验字典数据的值的唯一性
|
|
|
// validateDictDataValueUnique(updateReqVO.getId(), updateReqVO.getDictType(), updateReqVO.getValue());
|
|
|
+ // 校验字典数据的label的唯一性
|
|
|
+ validateDictDataLabelUnique(updateReqVO.getId(), dictDataTenantDO.getDictType(), updateReqVO.getLabel());
|
|
|
|
|
|
// 更新字典类型
|
|
|
DictDataTenantDO updateObj = BeanUtils.toBean(updateReqVO, DictDataTenantDO.class);
|
|
@@ -148,6 +159,21 @@ public class DictDataTenantServiceImpl implements DictDataTenantService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void validateDictDataLabelUnique(Long id, String dictType, String label) {
|
|
|
+ DictDataTenantDO dictData = dictDataTenantMapper.selectByDictTypeAndLabel(dictType, label);
|
|
|
+ if (dictData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 如果 id 为空,说明不用比较是否为相同 id 的字典数据
|
|
|
+ if (id == null) {
|
|
|
+ throw exception(DICT_DATA_LABEL_DUPLICATE);
|
|
|
+ }
|
|
|
+ if (!dictData.getId().equals(id)) {
|
|
|
+ throw exception(DICT_DATA_LABEL_DUPLICATE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@VisibleForTesting
|
|
|
public DictDataTenantDO validateDictDataExists(Long id) {
|
|
|
DictDataTenantDO dictData = dictDataTenantMapper.selectById(id);
|