forked from github/dataease
feat: 支持复制数据源
This commit is contained in:
parent
f6b5be96c4
commit
572a42c86e
@ -52,6 +52,20 @@ public class DatasourceController {
|
||||
return datasourceService.addDatasource(datasource);
|
||||
}
|
||||
|
||||
@RequiresPermissions("datasource:read")
|
||||
@DePermission(type = DePermissionType.DATASOURCE, value = "id", level = ResourceAuthLevel.DATASOURCE_LEVEL_MANAGE)
|
||||
@ApiOperation("更新数据源")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
|
||||
positionIndex = 0, positionKey = "type",
|
||||
value = "id"
|
||||
)
|
||||
public void updateDatasource(@RequestBody UpdataDsRequest dsRequest) throws Exception {
|
||||
datasourceService.updateDatasource(dsRequest);
|
||||
}
|
||||
|
||||
@RequiresPermissions("datasource:read")
|
||||
@ApiOperation("数据源类型")
|
||||
@GetMapping("/types")
|
||||
@ -106,20 +120,6 @@ public class DatasourceController {
|
||||
return resultHolder;
|
||||
}
|
||||
|
||||
@RequiresPermissions("datasource:read")
|
||||
@DePermission(type = DePermissionType.DATASOURCE, value = "id", level = ResourceAuthLevel.DATASOURCE_LEVEL_MANAGE)
|
||||
@ApiOperation("更新数据源")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
|
||||
positionIndex = 0, positionKey = "type",
|
||||
value = "id"
|
||||
)
|
||||
public void updateDatasource(@RequestBody UpdataDsRequest dsRequest) throws Exception {
|
||||
datasourceService.updateDatasource(dsRequest);
|
||||
}
|
||||
|
||||
@DePermission(type = DePermissionType.DATASOURCE)
|
||||
@ApiOperation("查询数据源下属所有表")
|
||||
@PostMapping("/getTables/{id}")
|
||||
|
@ -263,12 +263,9 @@ public class DatasourceService {
|
||||
if (!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(updataDsRequest.getType())) {
|
||||
throw new Exception("Datasource type not supported.");
|
||||
}
|
||||
System.out.println(updataDsRequest.getConfiguration());
|
||||
System.out.println(updataDsRequest.isConfigurationEncryption());
|
||||
if(updataDsRequest.isConfigurationEncryption()){
|
||||
updataDsRequest.setConfiguration(new String(java.util.Base64.getDecoder().decode(updataDsRequest.getConfiguration())));
|
||||
}
|
||||
System.out.println(updataDsRequest.getConfiguration());
|
||||
checkName(updataDsRequest.getName(), updataDsRequest.getType(), updataDsRequest.getId());
|
||||
Datasource datasource = new Datasource();
|
||||
datasource.setName(updataDsRequest.getName());
|
||||
@ -277,15 +274,22 @@ public class DatasourceService {
|
||||
datasource.setCreateTime(null);
|
||||
datasource.setType(updataDsRequest.getType());
|
||||
datasource.setUpdateTime(System.currentTimeMillis());
|
||||
|
||||
Provider datasourceProvider = ProviderFactory.getProvider(updataDsRequest.getType());
|
||||
datasourceProvider.checkConfiguration(datasource);
|
||||
|
||||
checkAndUpdateDatasourceStatus(datasource);
|
||||
DatasourceExample example = new DatasourceExample();
|
||||
example.createCriteria().andIdEqualTo(updataDsRequest.getId());
|
||||
datasourceMapper.updateByExampleSelective(datasource, example);
|
||||
handleConnectionPool(updataDsRequest.getId());
|
||||
if(StringUtils.isNotEmpty(updataDsRequest.getId())){
|
||||
DatasourceExample example = new DatasourceExample();
|
||||
example.createCriteria().andIdEqualTo(updataDsRequest.getId());
|
||||
datasourceMapper.updateByExampleSelective(datasource, example);
|
||||
handleConnectionPool(updataDsRequest.getId());
|
||||
}else {
|
||||
datasource.setId(UUID.randomUUID().toString());
|
||||
datasource.setCreateTime(System.currentTimeMillis());
|
||||
datasourceMapper.insert(datasource);
|
||||
handleConnectionPool(datasource, "add");
|
||||
sysAuthService.copyAuth(datasource.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASOURCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleConnectionPool(String datasourceId) {
|
||||
|
@ -1817,6 +1817,7 @@ export default {
|
||||
please_input_url: 'Please enter url address',
|
||||
please_input_port: 'Please enter port',
|
||||
modify: 'Edit data Source',
|
||||
copy: 'Copy datasource',
|
||||
validate_success: 'Verification successful',
|
||||
validate: 'Validate',
|
||||
search_by_name: 'Search by name',
|
||||
|
@ -1811,6 +1811,7 @@ export default {
|
||||
please_input_url: '請輸入URL地址',
|
||||
please_input_port: '請輸入端口',
|
||||
modify: '編輯數據源',
|
||||
copy: '複製數據源',
|
||||
validate_success: '校驗成功',
|
||||
validate: '校驗',
|
||||
search_by_name: '根據名稱搜索',
|
||||
|
@ -1810,6 +1810,7 @@ export default {
|
||||
please_input_url: '请输入URL地址',
|
||||
please_input_port: '请输入端口',
|
||||
modify: '编辑数据源',
|
||||
copy: '复制数据源',
|
||||
validate_success: '校验成功',
|
||||
validate: '校验',
|
||||
search_by_name: '根据名称搜索',
|
||||
|
@ -95,6 +95,9 @@ export default {
|
||||
},
|
||||
tips() {
|
||||
const { id, showModel } = this.params
|
||||
if(showModel === 'copy'){
|
||||
return this.$t('datasource.copy')
|
||||
}
|
||||
return id && showModel === 'show' && !this.canEdit
|
||||
? this.$t('datasource.show_info')
|
||||
: this.formType === 'add'
|
||||
|
@ -716,6 +716,9 @@ export default {
|
||||
res.data.apiConfiguration = JSON.parse(Base64.decode(res.data.apiConfigurationStr))
|
||||
}
|
||||
this.params = { ...res.data, showModel }
|
||||
if(showModel === 'copy'){
|
||||
this.params.id = ''
|
||||
}
|
||||
this.$emit('setParams', { ...this.params })
|
||||
}).finally(() => {
|
||||
this.$emit('update:formLoading', false)
|
||||
|
@ -173,6 +173,10 @@
|
||||
<i class="el-icon-edit" />
|
||||
{{ $t('chart.edit') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="copy" v-show="showView === 'Datasource'">
|
||||
<i class="el-icon-edit" />
|
||||
{{ $t('commons.copy') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="delete">
|
||||
<i class="el-icon-delete" />
|
||||
{{ $t('chart.delete') }}
|
||||
@ -646,6 +650,9 @@ export default {
|
||||
case 'edit':
|
||||
this._handleEditer(data)
|
||||
break
|
||||
case 'copy':
|
||||
this._handleCopy(data)
|
||||
break
|
||||
case 'delete':
|
||||
this._handleDelete(data)
|
||||
break
|
||||
@ -664,6 +671,17 @@ export default {
|
||||
this.dialogTitle = this.$t('datasource.edit_driver')
|
||||
this.driverForm = { ...row }
|
||||
},
|
||||
_handleCopy(row){
|
||||
if (this.showView === 'Datasource') {
|
||||
const param = { ...row, ...{ showModel: 'copy' }}
|
||||
this.switchMain('DsForm', param, this.tData, this.dsTypes)
|
||||
this.currentNodeId && sessionStorage.setItem('datasource-current-node', this.currentNodeId)
|
||||
return
|
||||
}
|
||||
this.editDriver = true
|
||||
this.dialogTitle = this.$t('commons.copy')
|
||||
this.driverForm = { ...row }
|
||||
},
|
||||
_handleDelete(datasource) {
|
||||
const params = {
|
||||
title:
|
||||
|
Loading…
Reference in New Issue
Block a user