feat: 校验数据源状态时,同时刷新左侧菜单中数据源的状态

This commit is contained in:
taojinlong 2021-08-23 16:27:05 +08:00
parent 378a034f85
commit 4eaaf2273e
4 changed files with 56 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import io.dataease.base.domain.Datasource;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.request.DatasourceUnionRequest;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.datasource.dto.DBTableDTO;
@ -41,6 +42,13 @@ public class DatasourceController {
datasourceService.validate(datasource);
}
@ApiOperation("验证数据源")
@GetMapping("/validate/{datasourceId}")
public ResultHolder validate(@PathVariable String datasourceId) {
return datasourceService.validate(datasourceId);
}
@ApiOperation("查询当前用户数据源")
@GetMapping("/list")
public List<DatasourceDTO> getDatasourceList() throws Exception {

View File

@ -9,6 +9,7 @@ import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.CommonThreadPool;
import io.dataease.commons.utils.LogUtil;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.request.DatasourceUnionRequest;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.base.ConditionEntity;
@ -126,13 +127,23 @@ public class DatasourceService {
datasourceProvider.checkStatus(datasourceRequest);
}
public void validate(String datasourceId) throws Exception {
if(StringUtils.isEmpty(datasourceId)){
return;
}
public ResultHolder validate(String datasourceId) {
Datasource datasource = datasourceMapper.selectByPrimaryKey(datasourceId);
validate(datasource);
if(datasource == null){
return ResultHolder.error("Can not find datasource: "+ datasourceId);
}
try {
validate(datasource);
datasource.setStatus("Success");
return ResultHolder.success("Success");
}catch (Exception e){
datasource.setStatus("Error");
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
}finally {
datasourceMapper.updateByPrimaryKey(datasource);
}
}
public List<String> getSchema(Datasource datasource) throws Exception {
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();

View File

@ -50,6 +50,14 @@ export function validateDs(data) {
})
}
export function validateDsById(datasourceId) {
return request({
url: 'datasource/validate/' + datasourceId,
method: 'get',
loading: true
})
}
export function getSchema(data) {
return request({
url: 'datasource/getSchema/',

View File

@ -100,7 +100,7 @@
<script>
import LayoutContent from '@/components/business/LayoutContent'
import { addDs, editDs, getSchema, validateDs } from '@/api/system/datasource'
import { addDs, editDs, getSchema, validateDs, validateDsById } from '@/api/system/datasource'
import { $confirm } from '@/utils/message'
export default {
@ -276,9 +276,29 @@ export default {
if (valid) {
const data = JSON.parse(JSON.stringify(this.form))
data.configuration = JSON.stringify(data.configuration)
validateDs(data).then(res => {
this.$success(this.$t('datasource.validate_success'))
})
if(data.showModel === 'show' && !this.canEdit){
validateDsById(data.id).then(res => {
if(res.success === 'true'){
this.$success(this.$t('datasource.validate_success'))
}else {
this.$error(this.$t(res.message))
}
this.refreshTree()
}).catch(res => {
this.$error(res.message)
})
}else {
validateDs(data).then(res => {
if(res.success === 'true'){
this.$success(this.$t('datasource.validate_success'))
}else {
this.$error(this.$t(res.message))
}
}).catch(res => {
this.$error(res.message)
})
}
} else {
return false
}