feat(数据源): 数据源详情

This commit is contained in:
junjun 2022-09-21 10:47:46 +08:00
parent 4d7578bfc2
commit ca92699340
2 changed files with 63 additions and 55 deletions

View File

@ -3,22 +3,23 @@ package io.dataease.controller.datasource;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.annotation.DeLog;
import io.dataease.auth.annotation.DePermission;
import io.dataease.commons.constants.SysLogConstants;
import io.dataease.commons.utils.DeLogUtils;
import io.dataease.dto.SysLogDTO;
import io.dataease.plugins.common.base.domain.Datasource;
import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.ResourceAuthLevel;
import io.dataease.commons.constants.SysLogConstants;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.DeLogUtils;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.datasource.request.UpdataDsRequest;
import io.dataease.controller.request.DatasourceUnionRequest;
import io.dataease.controller.request.datasource.ApiDefinition;
import io.dataease.dto.datasource.DBTableDTO;
import io.dataease.service.datasource.DatasourceService;
import io.dataease.dto.DatasourceDTO;
import io.dataease.dto.SysLogDTO;
import io.dataease.dto.datasource.DBTableDTO;
import io.dataease.plugins.common.base.domain.Datasource;
import io.dataease.service.datasource.DatasourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
@ -43,19 +44,19 @@ public class DatasourceController {
@ApiOperation("新增数据源")
@PostMapping("/add")
@DeLog(
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
positionIndex = 0,positionKey = "type",
value = "id"
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
positionIndex = 0, positionKey = "type",
value = "id"
)
public Datasource addDatasource(@RequestBody Datasource datasource) throws Exception{
public Datasource addDatasource(@RequestBody Datasource datasource) throws Exception {
return datasourceService.addDatasource(datasource);
}
@RequiresPermissions("datasource:read")
@ApiOperation("数据源类型")
@GetMapping("/types")
public Collection types() throws Exception{
public Collection types() throws Exception {
return datasourceService.types();
}
@ -81,6 +82,16 @@ public class DatasourceController {
return datasourceService.getDatasourceList(request);
}
@ApiOperation("查询数据源详情")
@PostMapping("/get/{id}")
public DatasourceDTO getDatasource(@PathVariable String id) throws Exception {
DatasourceUnionRequest request = new DatasourceUnionRequest();
request.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
request.setId(id);
List<DatasourceDTO> datasourceList = datasourceService.getDatasourceList(request);
return CollectionUtils.isNotEmpty(datasourceList) ? datasourceList.get(0) : null;
}
@ApiOperation("查询当前用户数据源")
@GetMapping("/list/{type}")
public List<DatasourceDTO> getDatasourceListByType(@PathVariable String type) throws Exception {
@ -105,12 +116,12 @@ public class DatasourceController {
@ApiOperation("更新数据源")
@PostMapping("/update")
@DeLog(
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
positionIndex = 0,positionKey = "type",
value = "id"
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
positionIndex = 0, positionKey = "type",
value = "id"
)
public void updateDatasource(@RequestBody UpdataDsRequest dsRequest) throws Exception{
public void updateDatasource(@RequestBody UpdataDsRequest dsRequest) throws Exception {
datasourceService.updateDatasource(dsRequest);
}
@ -124,7 +135,7 @@ public class DatasourceController {
@ApiIgnore
@PostMapping("/getSchema")
public List<String> getSchema(@RequestBody Datasource datasource) throws Exception {
return datasourceService.getSchema(datasource);
return datasourceService.getSchema(datasource);
}
@ApiIgnore

View File

@ -10,7 +10,7 @@
<select id="query" parameterType="io.dataease.ext.query.GridExample" resultMap="BaseResultMapDTO">
select datasource.*,
authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{extendCondition}, 'link') cids) t,datasource
from (select GET_V_AUTH_MODEL_ID_P_USE (#{extendCondition}, 'link') cids) t,datasource
left join (
SELECT
auth_source,
@ -43,7 +43,7 @@
) authInfo
on datasource.id = authInfo.auth_source
<if test="_parameter != null">
<include refid="io.dataease.ext.query.GridSql.gridCondition" />
<include refid="io.dataease.ext.query.GridSql.gridCondition"/>
</if>
and FIND_IN_SET(datasource.id,cids)
<if test="orderByClause != null">
@ -54,7 +54,7 @@
</if>
</select>
<select id="queryUnion" resultMap="BaseResultMapDTO">
<select id="queryUnion" resultMap="BaseResultMapDTO">
select datasource.*,
authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'link') cids) t,datasource
@ -91,46 +91,43 @@
on datasource.id = authInfo.auth_source
<where>
FIND_IN_SET(datasource.id,cids)
<if test="id != null">
id = #{id,jdbcType=VARCHAR}
</if>
<if test="name != null">
`name` like concat('%',#{name,jdbcType=VARCHAR},'%')
</if>
<if test="desc != null">
`desc` = #{desc,jdbcType=VARCHAR}
</if>
<if test="type != null">
`type` = #{type,jdbcType=VARCHAR}
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT}
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT}
</if>
<if test="configuration != null">
configuration = #{configuration,jdbcType=LONGVARCHAR}
</if>
<if test="id != null">
and id = #{id,jdbcType=VARCHAR}
</if>
<if test="name != null">
and `name` like concat('%',#{name,jdbcType=VARCHAR},'%')
</if>
<if test="desc != null">
and `desc` = #{desc,jdbcType=VARCHAR}
</if>
<if test="type != null">
and `type` = #{type,jdbcType=VARCHAR}
</if>
<if test="createTime != null">
and create_time = #{createTime,jdbcType=BIGINT}
</if>
<if test="updateTime != null">
and update_time = #{updateTime,jdbcType=BIGINT}
</if>
<if test="configuration != null">
and configuration = #{configuration,jdbcType=LONGVARCHAR}
</if>
</where>
<if test="sort == null">
order by ${sort}
</if>
</select>
<select id="findByPanelId" resultMap="BaseResultMapDTO">
SELECT DISTINCT
datasource.id,
datasource.`name`,
datasource.DESC,
datasource.type
FROM
chart_view
INNER JOIN panel_view ON chart_view.id = panel_view.chart_view_id
INNER JOIN dataset_table ON chart_view.table_id = dataset_table.id
INNER JOIN datasource ON dataset_table.data_source_id = datasource.id
WHERE
panel_view.panel_id = #{panelId}
<select id="findByPanelId" resultMap="BaseResultMapDTO">
SELECT DISTINCT datasource.id,
datasource.`name`,
datasource.DESC,
datasource.type
FROM chart_view
INNER JOIN panel_view ON chart_view.id = panel_view.chart_view_id
INNER JOIN dataset_table ON chart_view.table_id = dataset_table.id
INNER JOIN datasource ON dataset_table.data_source_id = datasource.id
WHERE panel_view.panel_id = #{panelId}
</select>