forked from github/dataease
commit
aa0199a934
@ -144,7 +144,7 @@ public class CalciteProvider {
|
||||
String querySql = getTablesSql(datasourceRequest).get(0);
|
||||
try (Connection con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con, 30); ResultSet resultSet = statement.executeQuery(querySql)) {
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return "Success";
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.RI
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/datasource")
|
||||
@Transactional
|
||||
public class DatasourceServer implements DatasourceApi {
|
||||
@Resource
|
||||
private CoreDatasourceMapper datasourceMapper;
|
||||
@ -120,48 +119,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
}
|
||||
|
||||
public void move(DatasourceDTO dataSourceDTO) throws DEException {
|
||||
switch (dataSourceDTO.getAction()) {
|
||||
case "move" -> {
|
||||
if (dataSourceDTO.getPid() == null) {
|
||||
DEException.throwException("目录必选!");
|
||||
}
|
||||
if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
if (dataSourceDTO.getPid() != 0) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
getParents(dataSourceDTO.getPid(), ids);
|
||||
if (ids.contains(dataSourceDTO.getId())) {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
}
|
||||
dataSourceManage.move(dataSourceDTO);
|
||||
}
|
||||
case "rename" -> {
|
||||
if (StringUtils.isEmpty(dataSourceDTO.getName())) {
|
||||
DEException.throwException("名称不能为空!");
|
||||
}
|
||||
CoreDatasource datasource = datasourceMapper.selectById(dataSourceDTO.getId());
|
||||
datasource.setName(dataSourceDTO.getName());
|
||||
dataSourceManage.innerEdit(datasource);
|
||||
}
|
||||
case "create" -> {
|
||||
CoreDatasource coreDatasource = new CoreDatasource();
|
||||
BeanUtils.copyBean(coreDatasource, dataSourceDTO);
|
||||
coreDatasource.setCreateTime(System.currentTimeMillis());
|
||||
coreDatasource.setUpdateTime(System.currentTimeMillis());
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
coreDatasource.setType(dataSourceDTO.getNodeType());
|
||||
coreDatasource.setId(IDUtils.snowID());
|
||||
coreDatasource.setConfiguration("");
|
||||
dataSourceManage.innerSave(coreDatasource);
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void filterDs(List<BusiNodeVO> busiNodeVOS, List<Long> ids, String type, Long id) {
|
||||
for (BusiNodeVO busiNodeVO : busiNodeVOS) {
|
||||
if (busiNodeVO.getType() != null && busiNodeVO.getType().equalsIgnoreCase(type)) {
|
||||
@ -231,16 +188,53 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return hasRepeat;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public DatasourceDTO move(DatasourceDTO dataSourceDTO) {
|
||||
if (dataSourceDTO.getPid() == null) {
|
||||
DEException.throwException("目录必选!");
|
||||
}
|
||||
if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
if (dataSourceDTO.getPid() != 0) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
getParents(dataSourceDTO.getPid(), ids);
|
||||
if (ids.contains(dataSourceDTO.getId())) {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
}
|
||||
dataSourceManage.move(dataSourceDTO);
|
||||
return dataSourceDTO;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public DatasourceDTO reName(DatasourceDTO dataSourceDTO) {
|
||||
if (StringUtils.isEmpty(dataSourceDTO.getName())) {
|
||||
DEException.throwException("名称不能为空!");
|
||||
}
|
||||
CoreDatasource datasource = datasourceMapper.selectById(dataSourceDTO.getId());
|
||||
datasource.setName(dataSourceDTO.getName());
|
||||
dataSourceManage.innerEdit(datasource);
|
||||
return dataSourceDTO;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public DatasourceDTO createFolder(DatasourceDTO dataSourceDTO) {
|
||||
dataSourceDTO.setCreateTime(System.currentTimeMillis());
|
||||
dataSourceDTO.setUpdateTime(System.currentTimeMillis());
|
||||
dataSourceDTO.setType(dataSourceDTO.getNodeType());
|
||||
dataSourceDTO.setId(IDUtils.snowID());
|
||||
dataSourceDTO.setConfiguration("");
|
||||
CoreDatasource coreDatasource = new CoreDatasource();
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
BeanUtils.copyBean(coreDatasource, dataSourceDTO);
|
||||
dataSourceManage.innerSave(coreDatasource);
|
||||
return dataSourceDTO;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public DatasourceDTO save(DatasourceDTO dataSourceDTO) throws DEException {
|
||||
if (StringUtils.isNotEmpty(dataSourceDTO.getAction())) {
|
||||
move(dataSourceDTO);
|
||||
return dataSourceDTO;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSourceDTO.getNodeType()) && dataSourceDTO.getNodeType().equalsIgnoreCase("folder")) {
|
||||
dataSourceDTO.setType("folder");
|
||||
dataSourceDTO.setConfiguration("");
|
||||
}
|
||||
if (dataSourceDTO.getId() != null && dataSourceDTO.getId() > 0) {
|
||||
return update(dataSourceDTO);
|
||||
}
|
||||
@ -256,6 +250,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
try {
|
||||
checkDatasourceStatus(coreDatasource);
|
||||
} catch (Exception ignore) {
|
||||
coreDatasource.setStatus("Error");
|
||||
}
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
coreDatasource.setCreateBy(AuthUtils.getUser().getUserId().toString());
|
||||
@ -316,32 +311,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return dataSourceDTO;
|
||||
}
|
||||
|
||||
private static void checkParams(String configurationStr) {
|
||||
DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class);
|
||||
if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) {
|
||||
DEException.throwException("初始连接数不能小于最小连接数!");
|
||||
}
|
||||
if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) {
|
||||
DEException.throwException("初始连接数不能大于最大连接数!");
|
||||
}
|
||||
if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) {
|
||||
DEException.throwException("最大连接数不能小于最小连接数!");
|
||||
}
|
||||
if (configuration.getQueryTimeout() < 0) {
|
||||
DEException.throwException("查询超时不能小于0!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkName(List<String> tables) {
|
||||
for (int i = 0; i < tables.size() - 1; i++) {
|
||||
for (int j = i + 1; j < tables.size(); j++) {
|
||||
if (tables.get(i).equalsIgnoreCase(tables.get(j))) {
|
||||
DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DatasourceDTO update(DatasourceDTO dataSourceDTO) throws DEException {
|
||||
Long pk = null;
|
||||
if (ObjectUtils.isEmpty(pk = dataSourceDTO.getId())) {
|
||||
@ -358,7 +327,8 @@ public class DatasourceServer implements DatasourceApi {
|
||||
requestDatasource.setUpdateBy(AuthUtils.getUser().getUserId());
|
||||
try {
|
||||
checkDatasourceStatus(requestDatasource);
|
||||
} catch (Exception ignore) {
|
||||
} catch (Exception e) {
|
||||
requestDatasource.setStatus("Error");
|
||||
}
|
||||
|
||||
DatasourceRequest sourceTableRequest = new DatasourceRequest();
|
||||
@ -455,6 +425,32 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return dataSourceDTO;
|
||||
}
|
||||
|
||||
private static void checkParams(String configurationStr) {
|
||||
DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class);
|
||||
if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) {
|
||||
DEException.throwException("初始连接数不能小于最小连接数!");
|
||||
}
|
||||
if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) {
|
||||
DEException.throwException("初始连接数不能大于最大连接数!");
|
||||
}
|
||||
if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) {
|
||||
DEException.throwException("最大连接数不能小于最小连接数!");
|
||||
}
|
||||
if (configuration.getQueryTimeout() < 0) {
|
||||
DEException.throwException("查询超时不能小于0!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkName(List<String> tables) {
|
||||
for (int i = 0; i < tables.size() - 1; i++) {
|
||||
for (int j = i + 1; j < tables.size(); j++) {
|
||||
if (tables.get(i).equalsIgnoreCase(tables.get(j))) {
|
||||
DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String excelDataTableName(String name) {
|
||||
return StringUtils.substring(name, 6, name.length() - 11);
|
||||
}
|
||||
@ -553,6 +549,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return datasourceDTO;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@DeLog(id = "#p0", ot = LogOT.DELETE, st = LogST.DATASOURCE)
|
||||
@Override
|
||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||
@ -615,7 +612,8 @@ public class DatasourceServer implements DatasourceApi {
|
||||
|
||||
@Override
|
||||
public DatasourceDTO validate(Long datasourceId) throws DEException {
|
||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
||||
CoreDatasource coreDatasource = new CoreDatasource();
|
||||
BeanUtils.copyBean(coreDatasource, datasourceMapper.selectById(datasourceId));
|
||||
return validate(coreDatasource);
|
||||
}
|
||||
|
||||
@ -645,19 +643,24 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
|
||||
private DatasourceDTO validate(CoreDatasource coreDatasource) {
|
||||
checkDatasourceStatus(coreDatasource);
|
||||
DatasourceDTO datasourceDTO = new DatasourceDTO();
|
||||
BeanUtils.copyBean(datasourceDTO, coreDatasource);
|
||||
CoreDatasource record = new CoreDatasource();
|
||||
record.setStatus(coreDatasource.getStatus());
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("id", coreDatasource.getId());
|
||||
CoreDatasource originData = datasourceMapper.selectById(coreDatasource.getId());
|
||||
String originStatus = originData.getStatus();
|
||||
if (StringUtils.equals(coreDatasource.getStatus(), originStatus)) {
|
||||
return datasourceDTO;
|
||||
try {
|
||||
checkDatasourceStatus(coreDatasource);
|
||||
} catch (Exception e) {
|
||||
coreDatasource.setStatus("Error");
|
||||
DEException.throwException(e.getMessage());
|
||||
} finally {
|
||||
datasourceDTO.setStatus(coreDatasource.getStatus());
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("id", coreDatasource.getId());
|
||||
CoreDatasource originData = datasourceMapper.selectById(coreDatasource.getId());
|
||||
String originStatus = originData.getStatus();
|
||||
if (!StringUtils.equals(coreDatasource.getStatus(), originStatus)) {
|
||||
dataSourceManage.innerEditStatus(coreDatasource);
|
||||
}
|
||||
}
|
||||
dataSourceManage.innerEditStatus(coreDatasource);
|
||||
datasourceDTO.setConfiguration("");
|
||||
return datasourceDTO;
|
||||
}
|
||||
|
||||
@ -838,7 +841,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDatasourceStatus(CoreDatasource coreDatasource) throws DEException {
|
||||
public void checkDatasourceStatus(CoreDatasource coreDatasource) {
|
||||
if (coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.Excel.name()) || coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.folder.name())) {
|
||||
return;
|
||||
}
|
||||
@ -853,8 +856,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
coreDatasource.setStatus(status);
|
||||
} catch (Exception e) {
|
||||
coreDatasource.setStatus("Error");
|
||||
DEException.throwException("校验失败: " + e.getMessage());
|
||||
DEException.throwException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,24 @@ export const save = async (data = {}): Promise<Dataset> => {
|
||||
})
|
||||
}
|
||||
|
||||
export const move = async (data = {}): Promise<Dataset> => {
|
||||
return request.post({ url: '/datasource/move', data }).then(res => {
|
||||
return res?.data
|
||||
})
|
||||
}
|
||||
|
||||
export const reName = async (data = {}): Promise<Dataset> => {
|
||||
return request.post({ url: '/datasource/reName', data }).then(res => {
|
||||
return res?.data
|
||||
})
|
||||
}
|
||||
|
||||
export const createFolder = async (data = {}): Promise<Dataset> => {
|
||||
return request.post({ url: '/datasource/createFolder', data }).then(res => {
|
||||
return res?.data
|
||||
})
|
||||
}
|
||||
|
||||
export const checkRepeat = async (data = {}): Promise<Dataset> => {
|
||||
return request.post({ url: '/datasource/checkRepeat', data }).then(res => {
|
||||
return res?.data
|
||||
|
@ -22,7 +22,9 @@ import {
|
||||
getTableField,
|
||||
listDatasourceTables,
|
||||
deleteById,
|
||||
save,
|
||||
move,
|
||||
reName,
|
||||
createFolder,
|
||||
validateById,
|
||||
syncApiDs,
|
||||
syncApiTable
|
||||
@ -234,28 +236,24 @@ const handleLoadExcel = data => {
|
||||
}
|
||||
|
||||
const validateDS = () => {
|
||||
validateById(nodeInfo.id as number)
|
||||
.then(res => {
|
||||
if (res.data.type === 'API') {
|
||||
let error = 0
|
||||
const status = JSON.parse(res.data.status)
|
||||
for (let i = 0; i < status.length; i++) {
|
||||
if (status[i].status === 'Error') {
|
||||
error++
|
||||
}
|
||||
validateById(nodeInfo.id as number).then(res => {
|
||||
if (res.data.type === 'API') {
|
||||
let error = 0
|
||||
const status = JSON.parse(res.data.status)
|
||||
for (let i = 0; i < status.length; i++) {
|
||||
if (status[i].status === 'Error') {
|
||||
error++
|
||||
}
|
||||
if (error === 0) {
|
||||
ElMessage.success('校验成功')
|
||||
} else {
|
||||
ElMessage.error('校验失败')
|
||||
}
|
||||
} else {
|
||||
ElMessage.success('校验成功')
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error('校验失败')
|
||||
})
|
||||
if (error === 0) {
|
||||
ElMessage.success('校验成功')
|
||||
} else {
|
||||
ElMessage.error('校验失败')
|
||||
}
|
||||
} else {
|
||||
ElMessage.success('校验成功')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const dialogErrorInfo = ref(false)
|
||||
@ -351,21 +349,29 @@ const infoList = computed(() => {
|
||||
}
|
||||
})
|
||||
const saveDsFolder = (params, successCb, finallyCb, cmd) => {
|
||||
save(params)
|
||||
let method = move
|
||||
let message = '移动成功'
|
||||
|
||||
switch (cmd) {
|
||||
case 'move':
|
||||
method = move
|
||||
message = '移动成功'
|
||||
|
||||
break
|
||||
case 'rename':
|
||||
method = reName
|
||||
message = '重命名成功'
|
||||
break
|
||||
default:
|
||||
method = createFolder
|
||||
message = '新建成功'
|
||||
break
|
||||
}
|
||||
method(params)
|
||||
.then(res => {
|
||||
if (res !== undefined) {
|
||||
successCb()
|
||||
switch (cmd) {
|
||||
case 'move':
|
||||
ElMessage.success('移动成功')
|
||||
break
|
||||
case 'rename':
|
||||
ElMessage.success('重命名成功')
|
||||
break
|
||||
default:
|
||||
ElMessage.success('新建成功')
|
||||
break
|
||||
}
|
||||
ElMessage.success(message)
|
||||
listDs()
|
||||
}
|
||||
})
|
||||
|
@ -35,6 +35,15 @@ public interface DatasourceApi {
|
||||
DatasourceDTO save(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
|
||||
|
||||
|
||||
@PostMapping("/move")
|
||||
DatasourceDTO move(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
|
||||
|
||||
@PostMapping("/reName")
|
||||
DatasourceDTO reName(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
|
||||
|
||||
@PostMapping("/createFolder")
|
||||
DatasourceDTO createFolder(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
|
||||
|
||||
@PostMapping("/checkRepeat")
|
||||
boolean checkRepeat(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user