Commit 110e4345 by yuwei

2.0.0项目初始化

parent bde04da0
...@@ -10,7 +10,7 @@ import cn.datax.service.data.market.api.call.service.ApiLogService; ...@@ -10,7 +10,7 @@ import cn.datax.service.data.market.api.call.service.ApiLogService;
import cn.datax.service.data.market.api.call.utils.ThreadUtil; import cn.datax.service.data.market.api.call.utils.ThreadUtil;
import cn.datax.service.data.market.api.dto.ApiLogDto; import cn.datax.service.data.market.api.dto.ApiLogDto;
import cn.datax.service.data.market.api.entity.DataApiEntity; import cn.datax.service.data.market.api.entity.DataApiEntity;
import cn.datax.service.data.market.api.enums.DataType; import cn.datax.service.data.market.api.enums.ParamType;
import cn.datax.service.data.market.api.feign.DataApiServiceFeign; import cn.datax.service.data.market.api.feign.DataApiServiceFeign;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
...@@ -108,9 +108,9 @@ public class ApiInterceptor implements HandlerInterceptor { ...@@ -108,9 +108,9 @@ public class ApiInterceptor implements HandlerInterceptor {
Map<String, Object> finalParams = params; Map<String, Object> finalParams = params;
dataApiEntity.getReqParams().stream().forEach(param -> { dataApiEntity.getReqParams().stream().forEach(param -> {
if (finalParams.containsKey(param.getParamName())) { if (finalParams.containsKey(param.getParamName())) {
String dataType = param.getDataType(); String paramType = param.getParamType();
// 数据类型是否正确 // 参数类型是否正确
DataType.parse(DataType.getDataType(dataType), finalParams.get(param.getParamName())); ParamType.parse(ParamType.getParamType(paramType), finalParams.get(param.getParamName()));
} }
}); });
String apiName = dataApiEntity.getApiName(); String apiName = dataApiEntity.getApiName();
...@@ -125,7 +125,7 @@ public class ApiInterceptor implements HandlerInterceptor { ...@@ -125,7 +125,7 @@ public class ApiInterceptor implements HandlerInterceptor {
// 请求时间范围60秒 // 请求时间范围60秒
seconds = Optional.ofNullable(seconds).orElse(60); seconds = Optional.ofNullable(seconds).orElse(60);
// 根据 USER + API 限流 // 根据 USER + API 限流
String key = "user:" + userId + "_api:" + apiId; String key = "user:" + userId + ":api:" + apiId;
// 根据key获取已请求次数 // 根据key获取已请求次数
Integer maxTimes = (Integer) redisTemplate.opsForValue().get(key); Integer maxTimes = (Integer) redisTemplate.opsForValue().get(key);
if (maxTimes == null) { if (maxTimes == null) {
......
...@@ -32,6 +32,6 @@ public class ExecuteConfig implements Serializable { ...@@ -32,6 +32,6 @@ public class ExecuteConfig implements Serializable {
@Valid @Valid
private List<FieldParam> fieldParams; private List<FieldParam> fieldParams;
@ApiModelProperty(value = "查询SQL") @ApiModelProperty(value = "解析SQL")
private String sqlText; private String sqlText;
} }
...@@ -31,9 +31,9 @@ public class ReqParam implements Serializable { ...@@ -31,9 +31,9 @@ public class ReqParam implements Serializable {
@NotNull(message = "操作符不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotNull(message = "操作符不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
private String whereType; private String whereType;
@ApiModelProperty(value = "数据类型") @ApiModelProperty(value = "参数类型")
@NotNull(message = "数据类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotNull(message = "参数类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
private String dataType; private String paramType;
@ApiModelProperty(value = "示例值") @ApiModelProperty(value = "示例值")
@NotBlank(message = "示例值不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotBlank(message = "示例值不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
......
...@@ -15,9 +15,9 @@ public class ResParam implements Serializable { ...@@ -15,9 +15,9 @@ public class ResParam implements Serializable {
private static final long serialVersionUID=1L; private static final long serialVersionUID=1L;
@ApiModelProperty(value = "参数名称") @ApiModelProperty(value = "字段名称")
@NotBlank(message = "参数名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotBlank(message = "字段名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
private String paramName; private String fieldName;
@ApiModelProperty(value = "描述") @ApiModelProperty(value = "描述")
@NotBlank(message = "描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotBlank(message = "描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
......
...@@ -6,7 +6,7 @@ import cn.hutool.core.util.ObjectUtil; ...@@ -6,7 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import java.math.BigDecimal; import java.math.BigDecimal;
public enum DataType { public enum ParamType {
String("1", "字符串"), String("1", "字符串"),
Integer("2", "整型"), Integer("2", "整型"),
...@@ -18,7 +18,7 @@ public enum DataType { ...@@ -18,7 +18,7 @@ public enum DataType {
private final String val; private final String val;
DataType(String key, String val) { ParamType(String key, String val) {
this.key = key; this.key = key;
this.val = val; this.val = val;
} }
...@@ -31,11 +31,11 @@ public enum DataType { ...@@ -31,11 +31,11 @@ public enum DataType {
return val; return val;
} }
public static Object parse(DataType dataType, Object obj) { public static Object parse(ParamType paramType, Object obj) {
if (ObjectUtil.isEmpty(obj)) { if (ObjectUtil.isEmpty(obj)) {
return null; return null;
} }
switch (dataType) { switch (paramType) {
case String: case String:
try { try {
return (java.lang.String)obj; return (java.lang.String)obj;
...@@ -74,9 +74,9 @@ public enum DataType { ...@@ -74,9 +74,9 @@ public enum DataType {
return null; return null;
} }
public static DataType getDataType(String dataType) { public static ParamType getParamType(String paramType) {
for (DataType type : DataType.values()) { for (ParamType type : ParamType.values()) {
if (type.key.equals(dataType)) { if (type.key.equals(paramType)) {
return type; return type;
} }
} }
......
...@@ -173,13 +173,13 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit ...@@ -173,13 +173,13 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit
List<ReqParam> reqParams = variables.stream().map(s -> { List<ReqParam> reqParams = variables.stream().map(s -> {
ReqParam reqParam = new ReqParam(); ReqParam reqParam = new ReqParam();
reqParam.setParamName(s); reqParam.setParamName(s);
reqParam.setNullable(DataConstant.TrueOrFalse.FALSE.getKey()); reqParam.setNullable(DataConstant.TrueOrFalse.TRUE.getKey());
return reqParam; return reqParam;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
sqlParseVo.setReqParams(reqParams); sqlParseVo.setReqParams(reqParams);
List<ResParam> resParams = cols.stream().map(s -> { List<ResParam> resParams = cols.stream().map(s -> {
ResParam resParam = new ResParam(); ResParam resParam = new ResParam();
resParam.setParamName(s); resParam.setFieldName(s);
return resParam; return resParam;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
sqlParseVo.setResParams(resParams); sqlParseVo.setResParams(resParams);
...@@ -188,7 +188,7 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit ...@@ -188,7 +188,7 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit
private String sqlJdbcNamedParameterBuild(DataApiEntity dataApi) throws JSQLParserException { private String sqlJdbcNamedParameterBuild(DataApiEntity dataApi) throws JSQLParserException {
Table table = new Table(dataApi.getExecuteConfig().getTableName()); Table table = new Table(dataApi.getExecuteConfig().getTableName());
String[] resParams = dataApi.getResParams().stream().map(s -> s.getParamName()).toArray(String[]::new); String[] resParams = dataApi.getResParams().stream().map(s -> s.getFieldName()).toArray(String[]::new);
Select select = SelectUtils.buildSelectFromTableAndExpressions(table, resParams); Select select = SelectUtils.buildSelectFromTableAndExpressions(table, resParams);
return SqlBuilderUtil.getInstance().buildHql(select.toString(), dataApi.getReqParams()); return SqlBuilderUtil.getInstance().buildHql(select.toString(), dataApi.getReqParams());
} }
......
...@@ -52,3 +52,11 @@ export function updateDataApi (data) { ...@@ -52,3 +52,11 @@ export function updateDataApi (data) {
data: data data: data
}) })
} }
export function sqlParse (data) {
return request({
url: '/data/market/dataApis/sql/parse',
method: 'post',
data: data
})
}
<template>
<div>
<el-card class="box-card" shadow="always">
<div slot="header" class="clearfix">
<span>{{ title }}</span>
<el-button-group style="float: right;">
<el-button size="mini" icon="el-icon-plus" round @click="submitForm" :loading="loadingOptions.loading" :disabled="loadingOptions.isDisabled">{{loadingOptions.loadingText}}</el-button>
<el-button size="mini" icon="el-icon-back" round @click="showCard">返回</el-button>
</el-button-group>
</div>
<div :style="classCardbody">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="数据源" prop="sourceId">
<el-select v-model="form.sourceId" placeholder="请选择数据源">
<el-option
v-for="source in sourceOptions"
:key="source.id"
:label="source.sourceName"
:value="source.id"
:disabled="source.status === '0'"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="数据集名称" prop="setName">
<el-input v-model="form.setName" placeholder="请输入数据集名称" />
</el-form-item>
<el-form-item label="数据集sql" prop="setSql">
<sql-editor
ref="sqleditor"
:value="form.setSql"
@changeTextarea="changeTextarea($event)"
style="height: 300px;"
></sql-editor>
</el-form-item>
<el-form-item>
<el-button size="mini" type="primary" @click="formaterSql">Sql格式化</el-button>
<el-button size="mini" type="primary" @click="dataPreview">预览</el-button>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in statusOptions"
:key="dict.id"
:label="dict.itemText"
>{{dict.itemValue}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
</div>
<el-drawer
:visible.sync="drawer"
direction="btt"
:with-header="false">
<el-table :data="previewData.dataList" stripe border
:max-height="200"
style="width: 100%; margin: 15px 0;">
<el-table-column label="序号" width="55" align="center">
<template slot-scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<template v-for="(column, index) in previewData.columnList">
<el-table-column
:prop="column"
:label="column"
:key="index"
align="center"
show-overflow-tooltip
/>
</template>
</el-table>
<el-pagination
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="previewData.pageNum"
:page-size.sync="previewData.pageSize"
:total="previewData.dataTotal"
></el-pagination>
</el-drawer>
</el-card>
</div>
</template>
<script>
import { addDataSet } from '@/api/factory/dataset'
import { listDataSource, queryByPage } from '@/api/factory/datasource'
import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor'
export default {
name: 'ApiMaskAdd',
components: {
SqlEditor
},
props: {
data: {
type: Object,
default: function () {
return {}
}
}
},
data () {
return {
classCardbody: {
overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px'
},
title: '数据API脱敏新增',
// 展示切换
showOptions: {
data: {},
showList: true,
showAdd: false,
showEdit: false,
showDetail: false
},
// 保存按钮
loadingOptions: {
loading: false,
loadingText: '保存',
isDisabled: false
},
// 表单参数
form: {
status: '1',
sourceId: undefined,
setSql: undefined
},
// 表单校验
rules: {
setName: [
{ required: true, message: '数据集名称不能为空', trigger: 'blur' }
]
},
// 状态数据字典
statusOptions: [],
// 数据源数据字典
sourceOptions: [],
drawer: false,
previewData: {
dataList: [],
columnList: [],
pageNum: 1,
pageSize: 20,
dataTotal: 0
}
}
},
created () {
this.getDicts('sys_common_status').then(response => {
if (response.success) {
this.statusOptions = response.data
}
})
this.getDataSourceList()
},
methods: {
showCard () {
this.$emit('showCard', this.showOptions)
},
getDataSourceList () {
listDataSource().then(response => {
if (response.success) {
this.sourceOptions = response.data
}
})
},
// 绑定编辑器value值的变化
changeTextarea (val) {
this.$set(this.form, 'setSql', val)
},
formaterSql () {
if (!this.form.setSql) {
return
}
this.$refs.sqleditor.editor.setValue(sqlFormatter.format(this.$refs.sqleditor.editor.getValue()))
},
dataPreview () {
if (!this.form.sourceId) {
return
}
if (!this.form.setSql) {
return
}
let data = {}
data.dataSourceId = this.form.sourceId
data.sql = this.form.setSql
data.pageNum = this.previewData.pageNum
data.pageSize = this.previewData.pageSize
queryByPage(data).then(response => {
if (response.success) {
const { data } = response
let dataList = data.data || []
let columnList = []
if (dataList.length > 0) {
columnList = Object.keys(dataList[0])
}
this.previewData.dataList = dataList
this.previewData.columnList = columnList
this.previewData.dataTotal = data.total
this.drawer = true
}
})
},
handleSizeChange (val) {
this.previewData.pageNum = 1
this.previewData.pageSize = val
this.dataPreview()
},
handleCurrentChange (val) {
this.previewData.pageNum = val
this.dataPreview()
},
/** 提交按钮 */
submitForm: function () {
this.$refs['form'].validate(valid => {
if (valid) {
this.loadingOptions.loading = true
this.loadingOptions.loadingText = '保存中...'
this.loadingOptions.isDisabled = true
addDataSet(this.form).then(response => {
if (response.success) {
this.$message.success('保存成功')
setTimeout(() => {
// 2秒后跳转列表页
this.$emit('showCard', this.showOptions)
}, 2000)
} else {
this.$message.error('保存失败')
this.loadingOptions.loading = false
this.loadingOptions.loadingText = '保存'
this.loadingOptions.isDisabled = false
}
}).catch(error => {
this.$message.error(error.data.msg || '保存失败')
this.loadingOptions.loading = false
this.loadingOptions.loadingText = '保存'
this.loadingOptions.isDisabled = false
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<div>
<el-card class="box-card" shadow="always">
<div slot="header" class="clearfix">
<span>{{ title }}</span>
<el-button-group style="float: right;">
<el-button size="mini" icon="el-icon-s-data" round @click="dataPreview">数据预览</el-button>
<el-button size="mini" icon="el-icon-back" round @click="showCard">返回</el-button>
</el-button-group>
</div>
<div :style="classCardbody">
<el-form ref="form" :model="form" label-width="80px" disabled>
<el-form-item label="数据源" prop="sourceId">
<el-select v-model="form.sourceId" placeholder="请选择数据源">
<el-option
v-for="source in sourceOptions"
:key="source.id"
:label="source.sourceName"
:value="source.id"
:disabled="source.status === '0'"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="数据集名称" prop="setName">
<el-input v-model="form.setName" placeholder="请输入数据集名称" />
</el-form-item>
<el-form-item label="数据集sql" prop="setSql">
<sql-editor
ref="sqleditor"
:value="form.setSql"
:readOnly="true"
style="height: 300px;"
></sql-editor>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in statusOptions"
:key="dict.id"
:label="dict.itemText"
>{{dict.itemValue}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<el-drawer
:visible.sync="drawer"
direction="btt"
:with-header="false">
<el-table :data="previewData.dataList" stripe border
:max-height="200"
style="width: 100%; margin: 15px 0;">
<el-table-column label="序号" width="55" align="center">
<template slot-scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<template v-for="(column, index) in previewData.columnList">
<el-table-column
:prop="column"
:label="column"
:key="index"
align="center"
show-overflow-tooltip
/>
</template>
</el-table>
<el-pagination
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="previewData.pageNum"
:page-size.sync="previewData.pageSize"
:total="previewData.dataTotal"
></el-pagination>
</el-drawer>
</div>
</el-card>
</div>
</template>
<script>
import { getDataSet } from '@/api/factory/dataset'
import { listDataSource, queryByPage } from '@/api/factory/datasource'
import SqlEditor from '@/components/SqlEditor'
export default {
name: 'ApiMaskDetail',
components: {
SqlEditor
},
props: {
data: {
type: Object,
default: function () {
return {}
}
}
},
data () {
return {
classCardbody: {
overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px'
},
title: '数据API脱敏详情',
// 展示切换
showOptions: {
data: {},
showList: true,
showAdd: false,
showEdit: false,
showDetail: false
},
// 表单参数
form: {},
// 状态数据字典
statusOptions: [],
// 数据源数据字典
sourceOptions: [],
drawer: false,
previewData: {
dataList: [],
columnList: [],
pageNum: 1,
pageSize: 20,
dataTotal: 0
}
}
},
created () {
console.log('id:' + this.data.id)
this.getDicts('sys_common_status').then(response => {
if (response.success) {
this.statusOptions = response.data
}
})
this.getDataSourceList()
this.getDataSet(this.data.id)
},
methods: {
showCard () {
this.$emit('showCard', this.showOptions)
},
getDataSourceList () {
listDataSource().then(response => {
if (response.success) {
this.sourceOptions = response.data
}
})
},
/** 获取详情 */
getDataSet: function (id) {
getDataSet(id).then(response => {
if (response.success) {
this.form = response.data
this.$refs.sqleditor.editor.setValue(this.form.setSql)
}
})
},
dataPreview () {
if (!this.form.sourceId) {
return
}
if (!this.form.setSql) {
return
}
let data = {}
data.dataSourceId = this.form.sourceId
data.sql = this.form.setSql
data.pageNum = this.previewData.pageNum
data.pageSize = this.previewData.pageSize
queryByPage(data).then(response => {
if (response.success) {
const { data } = response
let dataList = data.data || []
let columnList = []
if (dataList.length > 0) {
columnList = Object.keys(dataList[0])
}
this.previewData.dataList = dataList
this.previewData.columnList = columnList
this.previewData.dataTotal = data.total
this.drawer = true
}
})
},
handleSizeChange (val) {
this.previewData.pageNum = 1
this.previewData.pageSize = val
this.dataPreview()
},
handleCurrentChange (val) {
this.previewData.pageNum = val
this.dataPreview()
}
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<div>
<el-card class="box-card" shadow="always">
<div slot="header" class="clearfix">
<span>{{ title }}</span>
<el-button-group style="float: right;">
<el-button size="mini" icon="el-icon-plus" round @click="submitForm" :loading="loadingOptions.loading" :disabled="loadingOptions.isDisabled">{{loadingOptions.loadingText}}</el-button>
<el-button size="mini" icon="el-icon-back" round @click="showCard">返回</el-button>
</el-button-group>
</div>
<div :style="classCardbody">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="数据源" prop="sourceId">
<el-select v-model="form.sourceId" placeholder="请选择数据源">
<el-option
v-for="source in sourceOptions"
:key="source.id"
:label="source.sourceName"
:value="source.id"
:disabled="source.status === '0'"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="数据集名称" prop="setName">
<el-input v-model="form.setName" placeholder="请输入数据集名称" />
</el-form-item>
<el-form-item label="数据集sql" prop="setSql">
<sql-editor
ref="sqleditor"
:value="form.setSql"
@changeTextarea="changeTextarea($event)"
style="height: 300px;"
></sql-editor>
</el-form-item>
<el-form-item>
<el-button size="mini" type="primary" @click="formaterSql">Sql格式化</el-button>
<el-button size="mini" type="primary" @click="dataPreview">预览</el-button>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in statusOptions"
:key="dict.id"
:label="dict.itemText"
>{{dict.itemValue}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<el-drawer
:visible.sync="drawer"
direction="btt"
:with-header="false">
<el-table :data="previewData.dataList" stripe border
:max-height="200"
style="width: 100%; margin: 15px 0;">
<el-table-column label="序号" width="55" align="center">
<template slot-scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<template v-for="(column, index) in previewData.columnList">
<el-table-column
:prop="column"
:label="column"
:key="index"
align="center"
show-overflow-tooltip
/>
</template>
</el-table>
<el-pagination
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="previewData.pageNum"
:page-size.sync="previewData.pageSize"
:total="previewData.dataTotal"
></el-pagination>
</el-drawer>
</div>
</el-card>
</div>
</template>
<script>
import { getDataSet, updateDataSet } from '@/api/factory/dataset'
import { listDataSource, queryByPage } from '@/api/factory/datasource'
import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor'
export default {
name: 'ApiMaskEdit',
components: {
SqlEditor
},
props: {
data: {
type: Object,
default: function () {
return {}
}
}
},
data () {
return {
classCardbody: {
overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px'
},
title: '数据API脱敏编辑',
// 展示切换
showOptions: {
data: {},
showList: true,
showAdd: false,
showEdit: false,
showDetail: false
},
// 保存按钮
loadingOptions: {
loading: false,
loadingText: '保存',
isDisabled: false
},
// 表单参数
form: {},
// 表单校验
rules: {
setName: [
{ required: true, message: '数据集名称不能为空', trigger: 'blur' }
]
},
// 状态数据字典
statusOptions: [],
// 数据源数据字典
sourceOptions: [],
drawer: false,
previewData: {
dataList: [],
columnList: [],
pageNum: 1,
pageSize: 20,
dataTotal: 0
}
}
},
created () {
console.log('id:' + this.data.id)
this.getDicts('sys_common_status').then(response => {
if (response.success) {
this.statusOptions = response.data
}
})
this.getDataSourceList()
this.getDataSet(this.data.id)
},
methods: {
showCard () {
this.$emit('showCard', this.showOptions)
},
getDataSourceList () {
listDataSource().then(response => {
if (response.success) {
this.sourceOptions = response.data
}
})
},
/** 获取详情 */
getDataSet: function (id) {
getDataSet(id).then(response => {
if (response.success) {
this.form = response.data
this.$refs.sqleditor.editor.setValue(this.form.setSql)
}
})
},
// 绑定编辑器value值的变化
changeTextarea (val) {
this.$set(this.form, 'setSql', val)
},
formaterSql (val) {
this.$refs.sqleditor.editor.setValue(sqlFormatter.format(this.$refs.sqleditor.editor.getValue()))
},
dataPreview () {
if (!this.form.sourceId) {
return
}
if (!this.form.setSql) {
return
}
let data = {}
data.dataSourceId = this.form.sourceId
data.sql = this.form.setSql
data.pageNum = this.previewData.pageNum
data.pageSize = this.previewData.pageSize
queryByPage(data).then(response => {
if (response.success) {
const { data } = response
let dataList = data.data || []
let columnList = []
if (dataList.length > 0) {
columnList = Object.keys(dataList[0])
}
this.previewData.dataList = dataList
this.previewData.columnList = columnList
this.previewData.dataTotal = data.total
this.drawer = true
}
})
},
handleSizeChange (val) {
this.previewData.pageNum = 1
this.previewData.pageSize = val
this.dataPreview()
},
handleCurrentChange (val) {
this.previewData.pageNum = val
this.dataPreview()
},
/** 提交按钮 */
submitForm: function () {
this.$refs['form'].validate(valid => {
if (valid) {
this.loadingOptions.loading = true
this.loadingOptions.loadingText = '保存中...'
this.loadingOptions.isDisabled = true
updateDataSet(this.form).then(response => {
if (response.success) {
this.$message.success('保存成功')
setTimeout(() => {
// 2秒后跳转列表页
this.$emit('showCard', this.showOptions)
}, 2000)
} else {
this.$message.error('保存失败')
this.loadingOptions.loading = false
this.loadingOptions.loadingText = '保存'
this.loadingOptions.isDisabled = false
}
}).catch(error => {
this.$message.error(error.data.msg || '保存失败')
this.loadingOptions.loading = false
this.loadingOptions.loadingText = '保存'
this.loadingOptions.isDisabled = false
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
</style>
...@@ -97,6 +97,19 @@ ...@@ -97,6 +97,19 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-row v-if="form2.configType === '2'">
<el-col :span="24">
<sql-editor
ref="sqleditor"
:value="form2.sqlText"
@changeTextarea="changeTextarea($event)"
style="height: 300px;margin: 10px 10px;"
></sql-editor>
</el-col>
</el-row>
<el-form-item v-if="form2.configType === '2'">
<el-button size="mini" type="primary" @click="sqlParse">SQL解析</el-button>
</el-form-item>
</el-form> </el-form>
<el-form ref="form3" :model="form3" :rules="rules3" label-width="80px" v-if="active == 3"> <el-form ref="form3" :model="form3" :rules="rules3" label-width="80px" v-if="active == 3">
</el-form> </el-form>
...@@ -108,9 +121,8 @@ ...@@ -108,9 +121,8 @@
</template> </template>
<script> <script>
import { addDataSet } from '@/api/factory/dataset' import { addDataApi, sqlParse } from '@/api/market/dataapi'
import { listDataSource, queryByPage } from '@/api/factory/datasource' import { listDataSource } from '@/api/factory/datasource'
import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor' import SqlEditor from '@/components/SqlEditor'
export default { export default {
...@@ -132,7 +144,7 @@ export default { ...@@ -132,7 +144,7 @@ export default {
overflow: 'auto', overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px' height: document.body.offsetHeight - 240 + 'px'
}, },
title: '数据新增', title: '数据API新增',
// 展示切换 // 展示切换
showOptions: { showOptions: {
data: {}, data: {},
...@@ -186,9 +198,16 @@ export default { ...@@ -186,9 +198,16 @@ export default {
}, },
form2: { form2: {
sourceId: undefined, sourceId: undefined,
configType: undefined configType: undefined,
tableName: undefined,
fieldParams: [],
sqlText: undefined
},
rules2: {
sourceId: [
{ required: true, message: '数据源不能为空', trigger: 'blur' }
]
}, },
rules2: {},
form3: {}, form3: {},
rules3: {}, rules3: {},
// 请求方式数据字典 // 请求方式数据字典
...@@ -264,6 +283,27 @@ export default { ...@@ -264,6 +283,27 @@ export default {
handleLastStep () { handleLastStep () {
this.active-- this.active--
}, },
changeTextarea (val) {
this.form2.sqlText = val
},
sqlParse () {
if (!this.form2.sourceId) {
this.$message.error('数据源不能为空')
return
}
if (!this.form2.sqlText) {
this.$message.error('解析SQL不能为空')
return
}
let data = {}
data.sqlText = this.form2.sqlText
sqlParse(data).then(response => {
if (response.success) {
const { data } = response
console.log(data)
}
})
},
/** 提交按钮 */ /** 提交按钮 */
submitForm: function () { submitForm: function () {
this.$refs['form3'].validate(valid => { this.$refs['form3'].validate(valid => {
...@@ -271,7 +311,7 @@ export default { ...@@ -271,7 +311,7 @@ export default {
this.loadingOptions.loading = true this.loadingOptions.loading = true
this.loadingOptions.loadingText = '保存中...' this.loadingOptions.loadingText = '保存中...'
this.loadingOptions.isDisabled = true this.loadingOptions.isDisabled = true
addDataSet(this.form).then(response => { addDataApi(this.form).then(response => {
if (response.success) { if (response.success) {
this.$message.success('保存成功') this.$message.success('保存成功')
setTimeout(() => { setTimeout(() => {
......
...@@ -106,7 +106,7 @@ export default { ...@@ -106,7 +106,7 @@ export default {
overflow: 'auto', overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px' height: document.body.offsetHeight - 240 + 'px'
}, },
title: '数据详情', title: '数据API详情',
// 展示切换 // 展示切换
showOptions: { showOptions: {
data: {}, data: {},
...@@ -133,7 +133,7 @@ export default { ...@@ -133,7 +133,7 @@ export default {
}, },
created () { created () {
console.log('id:' + this.data.id) console.log('id:' + this.data.id)
this.getDicts('sys_common_status').then(response => { this.getDicts('sys_job_status').then(response => {
if (response.success) { if (response.success) {
this.statusOptions = response.data this.statusOptions = response.data
} }
......
...@@ -111,7 +111,7 @@ export default { ...@@ -111,7 +111,7 @@ export default {
overflow: 'auto', overflow: 'auto',
height: document.body.offsetHeight - 240 + 'px' height: document.body.offsetHeight - 240 + 'px'
}, },
title: '数据编辑', title: '数据API编辑',
// 展示切换 // 展示切换
showOptions: { showOptions: {
data: {}, data: {},
...@@ -150,7 +150,7 @@ export default { ...@@ -150,7 +150,7 @@ export default {
}, },
created () { created () {
console.log('id:' + this.data.id) console.log('id:' + this.data.id)
this.getDicts('sys_common_status').then(response => { this.getDicts('sys_job_status').then(response => {
if (response.success) { if (response.success) {
this.statusOptions = response.data this.statusOptions = response.data
} }
......
...@@ -101,7 +101,7 @@ export default { ...@@ -101,7 +101,7 @@ export default {
} }
}, },
created () { created () {
this.getDicts('sys_common_status').then(response => { this.getDicts('sys_job_status').then(response => {
if (response.success) { if (response.success) {
this.statusOptions = response.data this.statusOptions = response.data
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment