Merge pull request #9503 from dataease/pr@dev-v2@sysvariable

fix(数据源): 社区版同名校验缺失
This commit is contained in:
taojinlong 2024-05-07 12:23:34 +08:00 committed by GitHub
commit 0d2bdda853
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,7 @@ import io.dataease.datasource.dao.ext.mapper.DataSourceExtMapper;
import io.dataease.datasource.dao.ext.po.DataSourceNodePO;
import io.dataease.datasource.dto.DatasourceNodeBO;
import io.dataease.exception.DEException;
import io.dataease.i18n.Translator;
import io.dataease.license.config.XpackInteract;
import io.dataease.model.BusiNodeRequest;
import io.dataease.model.BusiNodeVO;
@ -73,10 +74,31 @@ public class DataSourceManage {
@XpackInteract(value = "datasourceResourceTree", before = false)
public void innerSave(CoreDatasource coreDatasource) {
checkName(coreDatasource);
coreDatasourceMapper.insert(coreDatasource);
coreOptRecentManage.saveOpt(coreDatasource.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.NEW);
}
public void checkName(CoreDatasource dto) {
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
if (ObjectUtils.isNotEmpty(dto.getPid())) {
wrapper.eq("pid", dto.getPid());
}
if (StringUtils.isNotEmpty(dto.getName())) {
wrapper.eq("name", dto.getName());
}
if (ObjectUtils.isNotEmpty(dto.getId())) {
wrapper.ne("id", dto.getId());
}
if (ObjectUtils.isNotEmpty(dto.getType()) && dto.getType().equalsIgnoreCase("folder")) {
wrapper.ne("type", dto.getType());
}
List<CoreDatasource> list = coreDatasourceMapper.selectList(wrapper);
if (list.size() > 0) {
DEException.throwException(Translator.get("i18n_ds_name_exists"));
}
}
@XpackInteract(value = "datasourceResourceTree", before = false)
public void innerEdit(CoreDatasource coreDatasource) {
@ -108,6 +130,7 @@ public class DataSourceManage {
sourceData.setUpdateBy(AuthUtils.getUser().getUserId());
sourceData.setPid(dataSourceDTO.getPid());
sourceData.setName(dataSourceDTO.getName());
checkName(sourceData);
coreDatasourceMapper.updateById(sourceData);
coreOptRecentManage.saveOpt(sourceData.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.UPDATE);
}