字段信息提取

This commit is contained in:
clay 2022-07-17 17:55:34 +08:00
parent e35b70afb6
commit 5ebb68075f
5 changed files with 253 additions and 90 deletions

View File

@ -1,9 +1,8 @@
NODE_ENV = production NODE_ENV = staging
# 测试环境配置 # 测试环境配置
ENV = 'staging' ENV = 'staging'
# EBTS/测试环境 # EBTS/测试环境
#VUE_APP_BASE_API = '/dev-api' #VUE_APP_BASE_API = '/dev-api'
#VUE_APP_BASE_API = 'https://api.ebts.top/dev-api' VUE_APP_BASE_API = 'http://localhost:8085/dev-api'
VUE_APP_BASE_API = 'http://tapi.ebts.top/dev-api'

View File

@ -19,3 +19,4 @@ npm run build:stage
# 构建生产环境 # 构建生产环境
npm run build:prod npm run build:prod
``` ```
workflowe

View File

@ -6,7 +6,8 @@
<el-col :span="18"> <el-col :span="18">
<el-form-item label-width="1px" label=""> <el-form-item label-width="1px" label="">
<textarea ref="textarea" type="textarea" @change="sqlChang" placeholder="请输入sql" <textarea ref="textarea" type="textarea" @change="sqlChang" placeholder="请输入sql"
:autosize="{minRows: 7, maxRows: 7}" :style="{width: '100%'}"></textarea> :autosize="{minRows: 7, maxRows: 7}" :style="{width: '100%'}"
></textarea>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
@ -24,15 +25,24 @@
<el-col :span="6"> <el-col :span="6">
<el-button type="text" icon="el-icon-upload" size="medium" @click="submitForm">提交</el-button> <el-button type="text" icon="el-icon-upload" size="medium" @click="submitForm">提交</el-button>
<el-button type="text" icon="el-icon-view" size="medium" @click="previewQuery">预览</el-button> <el-button type="text" icon="el-icon-view" size="medium" @click="previewQuery">预览</el-button>
<el-button type="text" icon="el-icon-plus" size="medium" @click="handleAdd" >新增</el-button> <el-button type="text" icon="el-icon-plus" size="medium" @click="handleAdd">新增</el-button>
<el-button type="text" icon="el-icon-download" size="medium" @click="handleExport">导出</el-button> <el-button type="text" icon="el-icon-download" size="medium" @click="handleExport">导出</el-button>
<el-button v-if="info.isRelease == 2" type="text" icon="el-icon-success" size="medium" @click="handRelease(1)">发布</el-button> <el-button type="text" icon="el-icon-download" size="medium" @click="fieldExtract">字段提取</el-button>
<el-button v-if="info.isRelease == 1" type="text" icon="el-icon-error" size="medium" @click="handRelease(2)">撤销</el-button> <el-button type="text" icon="el-icon-download" size="medium" @click="fieldEdit">字段修改
</el-button>
<el-button v-if="info.isRelease === 2" type="text" icon="el-icon-success" size="medium"
@click="handRelease(1)"
>发布
</el-button>
<el-button v-if="info.isRelease === 1" type="text" icon="el-icon-error" size="medium"
@click="handRelease(2)"
>撤销
</el-button>
</el-col> </el-col>
</el-form> </el-form>
</el-row> </el-row>
<el-row> <el-row>
<el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight"> <el-table ref="dragTable" :data="columns" row-key="columnId" :max-height="tableHeight">
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag"/> <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag"/>
<el-table-column label="查询名称" min-width="10%"> <el-table-column label="查询名称" min-width="10%">
<template slot-scope="scope"> <template slot-scope="scope">
@ -90,7 +100,8 @@
type="date" type="date"
format="yyyy-MM-dd" format="yyyy-MM-dd"
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
placeholder="选择日期时间"> placeholder="选择日期时间"
>
</el-date-picker> </el-date-picker>
<el-date-picker v-else-if="scope.row.type ==4" <el-date-picker v-else-if="scope.row.type ==4"
v-model="scope.row.ucMock" v-model="scope.row.ucMock"
@ -121,10 +132,11 @@
<div class="el-table"> <div class="el-table">
<el-table v-show="previewDate.open" :data="previewDate.data"> <el-table v-show="previewDate.open" :data="previewDate.data">
<el-table-column v-for="item in previewDate.header" <el-table-column v-for="item in previewDate.header"
:label="item" :label="item.label"
align="center" align="center"
:key="item" :key="item.key"
:prop="item"/> :prop="item.prop"
/>
</el-table> </el-table>
<pagination <pagination
v-show="total>0" v-show="total>0"
@ -134,6 +146,44 @@
@pagination="previewQuery" @pagination="previewQuery"
/> />
</div> </div>
<el-dialog
title="字段信息"
:visible.sync="columnInfo.open"
width="40%"
>
<el-table ref="columnInfoTable" :data="columnInfo.list" row-key="column">
<el-table-column label="字段信息" min-width="10%">
<template slot-scope="scope">
<el-input v-model="scope.row.prop"></el-input>
</template>
</el-table-column>
<el-table-column label="显示名称" min-width="10%">
<template slot-scope="scope">
<el-input v-model="scope.row.label"></el-input>
</template>
</el-table-column>
<el-table-column label="操作" align="center" min-width="5%">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="columnInfoDelete(scope.$index,scope.row)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<div style="text-align:center;">
<el-button
type="danger"
plain
size="medium"
@click="resetFieldExtract"
>重置字段信息
</el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
@ -150,12 +200,11 @@ import 'codemirror/theme/idea.css'
import 'codemirror/mode/sql/sql.js' import 'codemirror/mode/sql/sql.js'
// //
import 'codemirror/addon/hint/show-hint.css'; import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/hint/show-hint.js'; import 'codemirror/addon/hint/show-hint.js'
import 'codemirror/addon/hint/sql-hint.js'; import 'codemirror/addon/hint/sql-hint.js'
import {getQueryInfo, editQueryInfo, previewQueryData, Release, exportMock} from '@/api/tool/query' import { getQueryInfo, editQueryInfo, previewQueryData, Release, exportMock } from '@/api/tool/query'
import {Message} from "element-ui"; import { Message } from 'element-ui'
function JSONString(list) { function JSONString(list) {
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
@ -165,12 +214,12 @@ function JSONString(list) {
} else if (list[i].type == 4) { } else if (list[i].type == 4) {
let time = { let time = {
startTime: list[i].ucMock[0], startTime: list[i].ucMock[0],
endTime: list[i].ucMock[1], endTime: list[i].ucMock[1]
} }
list[i].ucMock = JSON.stringify(time) list[i].ucMock = JSON.stringify(time)
} }
} }
return list; return list
} }
function JSONparse(list) { function JSONparse(list) {
@ -182,7 +231,7 @@ function JSONparse(list) {
list[i].ucMock = [time.startTime, time.endTime] list[i].ucMock = [time.startTime, time.endTime]
} }
} }
return list; return list
} }
export default { export default {
@ -190,10 +239,10 @@ export default {
props: [], props: [],
data() { data() {
return { return {
tableHeight: document.documentElement.scrollHeight - 245 + "px", tableHeight: document.documentElement.scrollHeight - 245 + 'px',
// //
cloumns: [], columns: [],
sqlconfig: { sqlConfig: {
// //
mode: 'sql', mode: 'sql',
// //
@ -209,88 +258,180 @@ export default {
// //
lineNumbers: true, lineNumbers: true,
line: true, line: true,
extraKeys: {"Tab": "autocomplete"}, extraKeys: { 'Tab': 'autocomplete' },
lineWrapping: true,// lineWrapping: true,//
matchBrackets: true,// matchBrackets: true//
}, }
}, },
total: 0, total: 0,
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10
}, },
queryId: null, queryId: null,
info: { info: {
uqSql: '', uqSql: '',
uqName: null, uqName: null,
uqDescribe: null, uqDescribe: null,
columnList: []
},
columnInfo: {
open: false,
list: []
}, },
previewDate: { previewDate: {
open: false, open: false,
data: [], data: [],
header: [], header: []
}, },
rules: { rules: {
uqName: [{required: true, message: '请输入名称', trigger: 'blur'}], uqName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
uqDescribe: [{required: true, message: '请输入描述', trigger: 'blur'}], uqDescribe: [{ required: true, message: '请输入描述', trigger: 'blur' }]
}, }
} }
}, },
computed: {}, computed: {},
watch: {}, watch: {},
created() { created() {
this.queryId = this.$route.params && this.$route.params.queryId; this.queryId = this.$route.params && this.$route.params.queryId
getQueryInfo(this.queryId).then(res => { getQueryInfo(this.queryId).then(res => {
this.cloumns = [] this.columns = []
this.info = res.data.info this.info = res.data.info
this.cloumns = JSONparse(res.data.list) this.columns = JSONparse(res.data.list)
this.sqlconfig.coder.setValue(this.info.uqSql) this.sqlConfig.coder.setValue(this.info.uqSql)
})
this.$nextTick(function() {
this.initialize()
}) })
this.$nextTick(function () {
this.initialize();
});
}, },
mounted() { mounted() {
}, },
methods: { methods: {
columnInfoDelete(index) {
this.columnInfo.list.splice(index, 1)
},
resetFieldExtract() {
this.columnInfo.list = []
this.previewDate.header = []
this.columnInfo.open = false
},
/**
* 字段提取
*/
fieldExtract() {
let that = this
if (that.columnInfo.list.length === 0) {
that.doFieldExtract()
} else {
this.$confirm('已有字段信息,是否覆盖原有数据?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
that.doFieldExtract()
})
}
},
fieldEdit() {
if (this.columnInfo.list.length === 0) {
this.fieldExtract()
} else {
this.columnInfo.open = true
}
},
doFieldExtractToPreviewData() {
if (this.previewDate.header.length === 0) {
Message({
message: '预览数据为空,无法提取,请先点击预览',
type: 'error'
})
return
}
let columnList = []
this.previewDate.header.forEach(item => {
columnList.push({
prop: item.key,
label: item.label
})
})
this.columnInfo.list = columnList
this.columnInfo.open = true
},
/**
* 获取字段
*/
doFieldExtract() {
let sql = this.info.uqSql.toLowerCase()
let selectIndex = sql.indexOf('select')
let fromIndex = sql.indexOf('from')
let columnStr = sql.slice(selectIndex + 6, fromIndex)
let str = columnStr.replace(/\s+/g, '')
if (str.length === 1 && str === '*') {
let that = this
this.$confirm('sql中为*,尝试着从预览数据中获取子弹信息?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'info'
}).then(function() {
that.doFieldExtractToPreviewData()
})
return
}
let columnList = []
let columnStrList = columnStr.split(',')
for (let column of columnStrList) {
let asIndex = column.indexOf('as')
if (asIndex > -1) {
column = column.slice(asIndex + 2)
}
column = column.replace(/\s+/g, '')
let columnItem = {
prop: column,
label: column
}
columnList.push(columnItem)
}
this.columnInfo.list = columnList
this.columnInfo.open = true
console.log(this.columnInfo.list)
},
changUniCon(list) { changUniCon(list) {
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
if (list[i].ucName == "") { if (list[i].ucName == '') {
Message({ Message({
message: "序号" + i + "查询名称不能为空!", message: '序号' + i + '查询名称不能为空!',
type: 'error' type: 'error'
}) })
return false; return false
} }
if (list[i].ucDescribe == "") { if (list[i].ucDescribe == '') {
Message({ Message({
message: "序号" + i + "描述不能为空!", message: '序号' + i + '描述不能为空!',
type: 'error' type: 'error'
}) })
return false; return false
} }
if (list[i].ucKey == "") { if (list[i].ucKey == '') {
Message({ Message({
message: "序号" + i + "key不能为空!", message: '序号' + i + 'key不能为空!',
type: 'error' type: 'error'
}) })
return false; return false
} }
} }
return true return true
}, },
/** 发布与撤销 */ /** 发布与撤销 */
handRelease(release){ handRelease(release) {
let data = { let data = {
id: this.queryId, id: this.queryId,
isRelease: release, isRelease: release
} }
Release(data).then(res=>{ Release(data).then(res => {
this.info.isRelease = (this.info.isRelease==1)?2:1 this.info.isRelease = (this.info.isRelease == 1) ? 2 : 1
Message({ Message({
message:res.msg, message: res.msg,
type:"success" type: 'success'
}) })
}) })
}, },
@ -298,7 +439,7 @@ export default {
previewQuery() { previewQuery() {
this.$refs['elForm'].validate(valid => { this.$refs['elForm'].validate(valid => {
if (valid) { if (valid) {
let list = JSONString(this.cloumns) let list = JSONString(this.columns)
let data = this.info let data = this.info
if (list.length > 0) { if (list.length > 0) {
if (this.changUniCon(list)) { if (this.changUniCon(list)) {
@ -313,25 +454,39 @@ export default {
this.previewDate.data = res.rows this.previewDate.data = res.rows
this.total = res.total this.total = res.total
this.previewDate.header = [] this.previewDate.header = []
for (var key in this.previewDate.data[0]) { if (this.columnInfo.list.length > 0) {
this.previewDate.header.push(key) this.columnInfo.list.forEach(item => {
this.previewDate.header.push({
key: item.prop,
label: item.label,
prop: item.prop
})
})
} else {
for (var key in this.previewDate.data[0]) {
this.previewDate.header.push({
key: key,
label: key,
prop: key
})
}
} }
this.previewDate.open = true this.previewDate.open = true
this.cloumns = JSONparse(list) this.columns = JSONparse(list)
}) })
} }
}) })
}, },
sqlChang() { sqlChang() {
console.log(this.sqlconfig.coder.getValue()) console.log(this.sqlConfig.coder.getValue())
}, },
initialize() { initialize() {
// //
this.sqlconfig.coder = CodeMirror.fromTextArea(this.$refs.textarea, this.sqlconfig.options) this.sqlConfig.coder = CodeMirror.fromTextArea(this.$refs.textarea, this.sqlConfig.options)
// //
this.sqlconfig.coder.setValue(this.info.uqSql) this.sqlConfig.coder.setValue(this.info.uqSql)
// //
this.sqlconfig.coder.on('change', (coder) => { this.sqlConfig.coder.on('change', (coder) => {
this.info.uqSql = coder.getValue() this.info.uqSql = coder.getValue()
if (this.$emit) { if (this.$emit) {
this.$emit('input', this.info.uqSql) this.$emit('input', this.info.uqSql)
@ -341,23 +496,23 @@ export default {
}, },
/** 删除按钮 */ /** 删除按钮 */
handleDelete(index) { handleDelete(index) {
this.cloumns.splice(index, 1); this.columns.splice(index, 1)
}, },
ucTypeChang(index, row) { ucTypeChang(index, row) {
if (row.ucType == 'input' && row.ucCon != 'BETWEEN') { if (row.ucType == 'input' && row.ucCon != 'BETWEEN') {
this.cloumns[index].type = 1 this.columns[index].type = 1
if (typeof (this.cloumns[index].ucMock) != 'string') { if (typeof (this.columns[index].ucMock) != 'string') {
this.cloumns[index].ucMock = '' this.columns[index].ucMock = ''
} }
} else if (row.ucType == 'input' && row.ucCon == 'BETWEEN') { } else if (row.ucType == 'input' && row.ucCon == 'BETWEEN') {
this.cloumns[index].type = 2 this.columns[index].type = 2
this.cloumns[index].ucMock = {begin: '', end: ''} this.columns[index].ucMock = { begin: '', end: '' }
} else if (row.ucType == 'datetime' && row.ucCon != 'BETWEEN') { } else if (row.ucType == 'datetime' && row.ucCon != 'BETWEEN') {
this.cloumns[index].type = 3 this.columns[index].type = 3
this.cloumns[index].ucMock = '' this.columns[index].ucMock = ''
} else if (row.ucType == 'datetime' && row.ucCon == 'BETWEEN') { } else if (row.ucType == 'datetime' && row.ucCon == 'BETWEEN') {
this.cloumns[index].type = 4 this.columns[index].type = 4
this.cloumns[index].ucMock = [] this.columns[index].ucMock = []
} }
}, },
/** 添加 */ /** 添加 */
@ -371,20 +526,27 @@ export default {
ucKey: '', ucKey: '',
ucMock: '', ucMock: '',
ucType: 'input', ucType: 'input',
type: 1, type: 1
} }
this.cloumns.push(row) this.columns.push(row)
}, },
submitForm() { submitForm() {
this.$refs['elForm'].validate(valid => { this.$refs['elForm'].validate(valid => {
if (valid) { if (valid) {
let list = JSONString(this.cloumns) let list = JSONString(this.columns)
let data = this.info let data = this.info
if (list.length > 0) { if (list.length > 0) {
data.uniCons = list data.uniCons = list
} }
if (this.columnInfo.list.length === 0){
Message({
message: '字段信息为空,请提取字段信息',
type: 'error'
})
return
}
editQueryInfo(data).then(res => { editQueryInfo(data).then(res => {
this.cloumns = JSONparse(list) this.columns = JSONparse(list)
Message({ Message({
message: res.msg, message: res.msg,
type: 'success' type: 'success'
@ -401,11 +563,11 @@ export default {
var that = this var that = this
let list = JSONString(that.cloumns) let list = JSONString(that.cloumns)
let data = that.info let data = that.info
this.$confirm('是否确认导出查询数据项?', "警告", { this.$confirm('是否确认导出查询数据项?', '警告', {
confirmButtonText: "确定", confirmButtonText: '确定',
cancelButtonText: "取消", cancelButtonText: '取消',
type: "warning" type: 'warning'
}).then(function () { }).then(function() {
if (list.length > 0) { if (list.length > 0) {
if (that.changUniCon(list)) { if (that.changUniCon(list)) {
data.uniCons = list data.uniCons = list
@ -416,7 +578,7 @@ export default {
return exportMock(data) return exportMock(data)
}).then(response => { }).then(response => {
that.cloumns = JSONparse(list) that.cloumns = JSONparse(list)
this.download(response.msg); this.download(response.msg)
}) })
} }
} }

View File

@ -16,8 +16,8 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
url: jdbc:mysql://13.75.92.40:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://162.14.111.170:3306/ebts?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: gen username: ebts
password: zcsbKxPseM8LhFdT password: zcsbKxPseM8LhFdT
# 从库数据源 # 从库数据源
slave: slave:
@ -28,11 +28,12 @@ spring:
password: password:
redis: redis:
# 地址 # 地址
host: 13.70.28.14 host: 162.14.111.170
# 端口默认为6379 # 端口默认为6379
port: 6379 port: 6379
# 密码 # 密码
password: 926425 password: 926425
database: 5
ftp: ftp:
# ftp服务器ip地址 # ftp服务器ip地址
ftpAddress: 13.75.92.40 ftpAddress: 13.75.92.40

View File

@ -71,6 +71,8 @@ logging:
# Spring配置 # Spring配置
spring: spring:
profiles:
active: dev
# 数据源配置 # 数据源配置
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
@ -119,8 +121,6 @@ spring:
messages: messages:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages
profiles:
active: druid
# 文件上传 # 文件上传
servlet: servlet:
multipart: multipart: