UNPKG

w-vue-middle

Version:

统一公共服务组件

660 lines (631 loc) 19.9 kB
/* * @Author: Jason Liu * @Date: 2023-03-08 13:31:51 * @Desc: */ const glSqlEditor = require('w-vue-middle/components/glSqlEditor').default; const $dataIntegration = require('w-vue-middle/api/dataIntegration'); /** * @Author: Jason Liu * @description: 设置输出字段 */ const setSourceColumn = require('../setSourceColumn').default; const { jobVariable } = require('w-vue-middle/jobProcessService'); export default { components: { glSqlEditor, setSourceColumn, jobVariable }, props: { value: { type: Object, default: { sourceType: 1, dbId: undefined, //链接数据库ID dbName: undefined, //链接数据库名称 dbType: undefined, //链接数据库类型 ip: undefined, port: undefined, tableId: undefined, tableName: undefined, tableCode: undefined, script: undefined, whereString: undefined, description: undefined, mapping: [], }, }, referData: { type: Object, default: () => { return { mapping: [], }; }, }, set: { type: Boolean, default: false, }, sourceColumns: { //数据元组 type: Array, default: () => { return []; }, }, job: { type: Object, default: () => { return { data: { id: undefined, jobType: undefined, jsonDetail: undefined, }, }; }, }, }, data() { return { loading: false, nodeData: JSON.DeepCopy(this.value), show: this.set, columns: [], referColumns: [], newColums: [], setOutTables: { //输出参数设置 setMap: false, //设置映射 str: undefined, outstr: undefined, overlay: false, isNull: false, }, tablesColumns: {}, showFunctionHelp: false, functionList: [], showFunctionts: [], //显示的函数列表 listkey: 0, mapKey: 0, setColumn: { show: false, data: {}, }, queryData: { //输出参数设置 setMap: false, //设置映射 str: undefined, outstr: undefined, overlay: false, }, queue: {}, textData: { id: undefined, jobType: undefined, jsonDetail: undefined, }, variableList: [], verifyMapping: {}, //验证信息 }; }, created() { this.parseTable(); this.getFunctionList(); }, methods: { /** * @Author: Jason Liu * @description: 转换列的大小写 * @return {*} */ parseColumnCode(type = 'lower') { this.nodeData.mapping = this.nodeData.mapping.map((mapping) => { if (type == 'lower') { if (mapping.source.select) mapping.source.select = mapping.source.select.toLocaleLowerCase(); if (mapping.source.columnName) mapping.source.columnName = mapping.source.columnName.toLocaleLowerCase(); } else { if (mapping.source.select) mapping.source.select = mapping.source.select.toLocaleUpperCase(); if (mapping.source.columnName) mapping.source.columnName = mapping.source.columnName.toLocaleUpperCase(); } return mapping; }); this.searchOutPutList(); }, /** * @Author: Jason Liu * @description: 读取变量 */ loadedVariable(e = []) { this.variableList = e; this.parseTable(); }, /** * @Author: Jason Liu * @description: 获取函数列表 */ getFunctionList() { $dataIntegration.getSQlFunctonList().then((req) => { this.functionList = req.data.map((item, i) => { item.id = i; item.children = item.sub; return item; }); }); }, /** * @Author: Jason Liu * @description: 标准化提示表格 */ parseTable() { let tablesColumns = {}; this.verifyMapping = {}; this.sourceColumns.forEach((column) => { if (!tablesColumns[column.tableAsName]) { tablesColumns[column.tableAsName] = []; } let keyName = column.tableAsName || column.tableCode; tablesColumns[keyName].push(column.columnName); if (column.asName != column.columnName) { tablesColumns[keyName].push(column.asName); } }); this.variableList.forEach((item) => { tablesColumns[item.code] = []; }); this.nodeData.mapping.forEach((mapping) => { this.analysisColumn(false, mapping); //页面数据自动规整 if (mapping.source.type == 'field' || mapping.source.select) { let has = this.sourceColumns.find((column) => { let keyName = column.tableAsName || column.tableCode; mapping.source.columnName = mapping.source.select; return `${keyName}.${column.columnName}` == mapping.source.select; }); if (has) { mapping.source.has = ''; } else { mapping.source.has = 'no_source'; } } }); this.tablesColumns = tablesColumns; this.searchOutPutList(); }, /** * @Author: Jason Liu * @description: 搜索输出字段信息 */ searchOutPutList() { this.queryData = JSON.DeepCopy(this.setOutTables); this.columns = this.nodeData.mapping.filter((item) => { return this.filterOutTableName(item); }); if (this.referData.mapping && this.referData.mapping.length > 0) { this.referColumns = this.referData.mapping; } this.newColums = this.compMapping(this.columns, this.referColumns); }, compMapping(column, referColumn) { let newList = []; let commonList = []; column.forEach((itemA) => { let commonItem = referColumn.find((itemB) => { return ( itemA.target.columnName.toLocaleLowerCase() == itemB.target.columnName.toLocaleLowerCase() ); }); let diffFlag = false; if (commonItem) { diffFlag = this.testColumnData(itemA, commonItem); } if (commonItem) { newList.push({ ...itemA, referColumn: { ...commonItem, }, isDiff: !diffFlag, }); commonList.push(itemA.target.columnName); } else { newList.push({ ...itemA, referColumn: { source: {}, target: {}, }, isDiff: true, }); } }); if ( this.queryData.str || this.queryData.outstr || this.setOutTables.overlay || this.setOutTables.isNull ) { return newList; } referColumn.forEach((itemB) => { let index = commonList.findIndex((v) => { return v.toLocaleLowerCase() == itemB.target.columnName.toLocaleLowerCase(); }); if (index == -1) { newList.push({ source: {}, target: {}, referColumn: { ...itemB, }, // isDiff: true, }); } }); return newList; }, changeColumn(row) { if (row.referColumn && row.referColumn.target) { row.isDiff = !this.testColumnData(row, row.referColumn); } }, testColumnData(data1, data2) { let val = data1.target.columnName.toLocaleLowerCase() == data2.target.columnName.toLocaleLowerCase() && data1.target.pk == data2.target.pk && data1.target.columnType == data2.target.columnType && data1.target.columnSize == data2.target.columnSize && data1.source.columnName == data2.source.columnName && data1.source.columnType == data2.source.columnType && data1.source.columnSize == data2.source.columnSize; return val; }, /** * @Author: Jason Liu * @description: 查询设置 */ filterOutTableName(row) { let targethas = true; if (this.queryData.str) { let columnName = row.target.columnName.toLocaleLowerCase(); let str = this.queryData.str.toLocaleLowerCase(); targethas = columnName.indexOf(str) > -1; } let sourcehas = true; if (this.queryData.outstr) { if (row.source.columnName) { let columnName = row.source.columnName.toLocaleLowerCase(); let str = this.queryData.outstr.toLocaleLowerCase(); sourcehas = columnName.indexOf(str) > -1; } else { sourcehas = false; } } let nullhas = true; if (this.queryData.overlay) { nullhas = !row.source.columnName; } let viewNotNull = true; if (this.queryData.isNull) { viewNotNull = row.target.notNull; } return targethas && sourcehas && nullhas && viewNotNull; }, filterOutTableSource({ option, row }) { if (option.data) { if (option.data.str) { if (row.source.columnName) { return ( row.source.columnName .toLocaleLowerCase() .indexOf(option.data.str.toLocaleLowerCase()) > -1 ); } else { return false; } } else if (option.data.isNoll) { return !row.source.columnName; } else { return true; } } else { return true; } }, setRowDataClass({ row, rowIndex }) { row.warning = false; let result = ''; if (row.source.columnName) { //设置了映射列的情况下 if (row.source.columnType != row.target.columnType) { //如果类型不一样,给出警告 //result = "row_warning"; } else if (row.source.type != 'fun' && row.source.columnSize > row.target.columnSize) { //result = "row--error"; //配置字段了,长度小于来源,会报错 } } if (row.isDiff) { result = 'row-diff'; } return result; }, setCellClass({ row, column }) { if (column.field && column.field.indexOf('referColumn') > -1) { return 'col-gray'; } }, /** * @Author: Jason Liu * @description: 显示数据源设置 */ viewSetColumn(row) { this.setColumn.show = true; this.setColumn.data = row; this.searchOutPutList(); }, /** * @Author: Jason Liu * @description: 清空设置内容 */ clearColumn(row) { row.source.select = undefined; row.source.columnName = undefined; row.source.lockType = false; row.source.columnType = undefined; row.source.columnSize = undefined; }, /** * @Author: Jason Liu * @description: 分析字段内容 */ analysisColumn(e, row) { if (!e) { let verifyInfo = { verify: 'pass', messages: [], }; /** * @Author: Jason Liu * @description: 修改警告状态 */ const changeState = () => { if (verifyInfo.verify == 'pass') { verifyInfo.verify = 'warning'; } }; const verifyData = () => { if (row.source.columnType != row.target.columnType) { changeState(); verifyInfo.messages.push({ type: 'warning', message: $t('输入类型与输出类型不一样,可能会导致调度异常!'), }); } if (row.source.columnSize > row.target.columnSize) { changeState(); verifyInfo.messages.push({ type: 'warning', message: $t( '输入字段长度大于输出字段长度,输入类型与输出类型不一样,可能会导致调度异常!', ), }); } let data = row.source.columnName; const stringRegex = /^'.*'$/; if (!stringRegex.test(data)) { //收尾没有' if (row.source.columnType == 'TIMESTAMP') { //日期格式,需要添加‘ verifyInfo.messages.push({ type: 'warning', message: $t('日期数据,请前后添加,可能会导致调度异常!'), }); } const placeRegex = /^\${.*}$/; //占位符正则 var funRegex = /\?|[.]|[(]|[)]|[+]|[-]|[_]|[`]/g; //非字符内容的正则 if (placeRegex.test(data)) { verifyInfo.verify = 'error'; verifyInfo.messages.push({ type: 'error', message: $t('占位符需要添加首位添加 _#_单引号,否则会导致调度异常!'), }); } else if (!funRegex.test(data)) { verifyInfo.messages.push({ type: 'warning', message: $t('内容需要首位添加 _#_单引号,否则会导致调度异常!'), }); } } }; if (row.source.columnName) { let sourceColumn = this.sourceColumns.find((column) => { return ( [ `${column.tableAsName}.${column.columnName}`, `${column.tableAsName}.${column.asName}`, ].indexOf(row.source.columnName.trim()) > -1 ); }); if (sourceColumn) { if (row.source.lockType) { row.source = { ...row.source, select: row.source.columnName, description: sourceColumn.description, columnTypeFlink: sourceColumn.columnTypeFlink, pk: sourceColumn.pk, has: '', type: 'field', }; } else { row.source = { ...row.source, select: row.source.columnName, columnType: sourceColumn.columnType, description: sourceColumn.description, columnTypeFlink: sourceColumn.columnTypeFlink, columnSize: sourceColumn.columnSize, pk: sourceColumn.pk, has: '', type: 'field', }; } verifyData(); } else { let has = ''; if (row.source.select == row.source.columnName) { has = 'no_source'; changeState(); verifyInfo.messages.push({ type: 'warning', message: $t('未找到输入列,已自动换行成函数字段,修改后警告去除!'), }); } row.source = { ...row.source, pk: false, select: undefined, has: has, type: 'fun', }; if (!row.source.lockType) { let columnType = 'VARCHAR'; const time = row.source.columnName.replaceAll("'", ''); if (!isNaN(row.source.columnName)) { //fun 数字类型和来源不匹配 1需要是数字 给出警告 let num = row.source.columnName; if (parseInt(num) == parseFloat(num)) { columnType = 'INT'; } else { columnType = 'DECIMAL'; } } else if (this.moment(time).isValid() && time.length >= 10) { columnType = 'TIMESTAMP'; } //fun 占位符类型和来源不匹配 字符需要给单引号 给出报错 NA //fun . ( ) 空格 不需要单引号警告,其他给出警告 row.source = { ...row.source, description: undefined, columnTypeFlink: undefined, columnSize: 32, columnType: columnType, }; } verifyData(); } } else { if (row.target.notNull) { verifyInfo.verify = 'error'; verifyInfo.messages.push({ type: 'error', message: $t('非空列,必须设置输入列名信息'), }); } row.source = { pk: false, lockType: false, select: undefined, description: undefined, columnTypeFlink: undefined, columnSize: undefined, type: undefined, columnType: undefined, }; } this.verifyMapping[row.target.columnName] = verifyInfo; this.changeColumn(row); } else { } }, /** * @Author: Jason Liu * @description: 输出映射空值填充 */ outTablesNullFill() { this.nodeData.mapping = this.nodeData.mapping.map((item) => { if (item.target.notNull) { //必输字段 item.target.isComplete = true; } return item; }); }, /** * @Author: Jason Liu * @description: 输出映射自动填充 */ outTablesSmartFill() { this.nodeData.mapping = this.nodeData.mapping.map((item) => { let sourceColumn = this.sourceColumns.find((column) => { return ( [`${column.columnName.toLocaleLowerCase()}`, `${column.asName}`].indexOf( item.target.columnName.toLocaleLowerCase().trim(), ) > -1 ); }); if (sourceColumn) { item.source = { ...sourceColumn, columnName: `${sourceColumn.tableAsName || sourceColumn.tableCode}.${ sourceColumn.columnName }`, select: `${sourceColumn.tableAsName || sourceColumn.tableCode}.${ sourceColumn.columnName }`, has: '', type: 'field', }; } return item; }); }, /** * @Author: Jason Liu * @description: 确定 */ fixed() { // 处理数据 this.nodeData.mapping = this.newColums.filter((item) => { item.isDiff = undefined; item.referColumn = undefined; return !!item.target.columnName; }); let isPk = false; let index = this.nodeData.mapping.filter((item) => { if (item.target.pk) { isPk = true; } return item.target.notNull && !item.source.columnName; }).length; if (!isPk) { this.$message.error($t('请至少设置一列为主键列')); } else if (index > 0) { this.$message.error($t('存在非空列未设置输入列名信息!')); } else { this.show = false; this.$emit('input', this.nodeData); this.$emit('change', this.nodeData); } }, }, watch: { set(val) { this.show = val; if (val) { this.nodeData = JSON.DeepCopy(this.value); this.parseTable(); } }, job(val) { this.textData = val.data; }, show(val) { this.$emit('show', val); }, }, };