feat: 自助数据集新增mybatis语法支持

main
hong.yang 1 year ago
parent 3ddfdba2c3
commit bd8173b9fa

@ -184,6 +184,37 @@
</el-tooltip>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item
label="语法类型"
prop="syntaxType"
>
<el-radio-group
v-model="dataForm.syntaxType"
class="bs-el-radio-group"
>
<el-radio label="normal">
普通
</el-radio>
<el-radio label="mybatis">
Mybatis
</el-radio>
</el-radio-group>
<el-tooltip
class="item"
effect="light"
content="Mybatis类型可使用动态标签来处理sql如if、choose、where具体用法可参考示例"
placement="top"
>
<i
class="el-icon-warning-outline"
style="color: #E3C98C;margin-left: 16px;font-size:14px"
/>
</el-tooltip>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item
label="标签"
@ -209,10 +240,35 @@
:options="cOptions"
style="margin-top: 2px"
/>
<div class="bs-codemirror-bottom-text">
<div class="bs-codemirror-bottom-text" v-if="dataForm.syntaxType === 'mybatis'">
示例
<strong><br>
1常规使用
<el-tooltip
class="item"
effect="dark"
content="${参数名称}会将参数值直接填充到sql中#{参数名称}会将参数值进行转义(比如字符串类型会添加''后填充到sql中"
placement="top-start"
><i class="el-icon-question" />
</el-tooltip>
select * from table where table_field = <span style="color: #CC7832;">${参数名称}</span> ( <span style="color: #CC7832;">#{参数名称}</span> )<br>
2条件判断
<el-tooltip
class="item"
effect="dark"
content="支持Mybatis的所有动态标签如if、choose、where等具体用法请参考Mybatis官方文档"
placement="top-start"
><i class="el-icon-question" />
</el-tooltip>
select * from table where 1=1 <span style="color: #2F67A7;">&lt;if test="参数名称 != null and 参数名称 !=''"&gt;</span> and table_field = <span
style="color: #CC7832;"
>${参数名称}</span> <span style="color: #2F67A7;">&lt;/if&gt;</span>
</strong>
</div>
<div class="bs-codemirror-bottom-text" v-else>
示例
<strong><br>
1常规使用 select * from table where table_field = <span style="color: red;">${参数名称}</span><br>
1常规使用 select * from table where table_field = <span style="color: #CC7832;">${参数名称}</span><br>
2标签使用
<el-tooltip
class="item"
@ -221,9 +277,9 @@
placement="top-start"
><i class="el-icon-question" />
</el-tooltip>
select * from table where 1=1 <span style="color: blue;">&lt;参数名称&gt;</span> and table_field = <span
style="color: red;"
>${参数名称}</span> <span style="color: blue;">&lt;/&gt;</span>
select * from table where 1=1 <span style="color: #2F67A7;">&lt;参数名称&gt;</span> and table_field = <span
style="color: #CC7832;"
>${参数名称}</span> <span style="color: #2F67A7;">&lt;/&gt;</span>
</strong>
</div>
</div>
@ -857,7 +913,8 @@ export default {
fieldDesc: {},
fieldList: [],
script: '',
cacheCoherence: null
cacheCoherence: null,
syntaxType: 'normal'
},
rules: {
name: [
@ -980,6 +1037,7 @@ export default {
this.dataForm.fieldDesc = res.config.fieldDesc
this.dataForm.fieldList = res.config.fieldList
this.dataForm.cacheCoherence = res.config.cacheCoherence
this.dataForm.syntaxType = res.config.syntaxType ? res.config.syntaxType : 'normal'
// 使
this.dataForm.name = this.datasetName
this.paramsListCopy = cloneDeep(this.dataForm.paramsList)
@ -1161,7 +1219,8 @@ export default {
sqlProcess: this.dataForm.sqlProcess,
paramsList: this.dataForm.paramsList,
fieldList: this.dataForm.fieldList,
fieldDesc: this.dataForm.fieldDesc
fieldDesc: this.dataForm.fieldDesc,
syntaxType: this.dataForm.syntaxType,
}
}
datasetSave(datasetParams).then(res => {
@ -1184,8 +1243,13 @@ export default {
*/
buildParamsAndRun () {
this.isTest = true
// ${}
const reg = /\${(.*?)}/g
const paramNames = [...new Set([...this.dataForm.sqlProcess.matchAll(reg)].map(item => item[1]))]
let paramNames = [...new Set([...this.dataForm.sqlProcess.matchAll(reg)].map(item => item[1]))]
// #{}
const reg2 = /#{(.*?)}/g
const paramNames2 = [...new Set([...this.dataForm.sqlProcess.matchAll(reg2)].map(item => item[1]))]
paramNames.push(...paramNames2)
const names = this.dataForm.paramsList.map(item => item.name)
const params = []
paramNames.forEach(name => {
@ -1243,6 +1307,7 @@ export default {
script: this.dataForm.sqlProcess,
params: this.dataForm.paramsList,
dataSetType: 'custom',
syntaxType: this.dataForm.syntaxType,
size: this.size,
current: this.current
}
@ -1285,7 +1350,7 @@ export default {
const checkList = this.structurePreviewList.filter(item => item.fieldName === param.name)
if (checkList.length) {
paramsNameCheck = true
param.name = ''
// param.name = ''
}
})
if (paramsNameCheck) {

@ -929,10 +929,15 @@ export default {
this.structurePreviewList = []
this.structurePreviewListCopy = []
if (!this.dataForm.sourceId || !this.dataForm.tableName) return
let allField = []
if (this.dataForm.fieldInfo.length === 0) {
//
allField = this.fieldList.map(field => field.columnName)
}
const executeParams = {
dataSourceId: this.dataForm.sourceId,
script: JSON.stringify({
fieldInfo: this.dataForm.fieldInfo, //
fieldInfo: this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo : allField,
tableName: this.dataForm.tableName,
repeatStatus: this.dataForm.repeatStatus
}),

@ -212,7 +212,7 @@
/>
<div class="bs-codemirror-bottom-text">
示例
<strong>call 存储过程名称(<span style="color: red;">${参数名称}</span>,?)SqlServer数据源使用exec 存储过程名称 <span style="color: red;">@参数名称</span>=?</strong>
<strong>call 存储过程名称(<span style="color: #CC7832;">${参数名称}</span>,?)SqlServer数据源使用exec 存储过程名称 <span style="color: #CC7832;">@参数名称</span>=?</strong>
</div>
</div>
<div style="text-align: center; padding: 16px 0;">

Loading…
Cancel
Save