|
@@ -37,31 +37,44 @@ export function useModelConfig() {
|
|
|
* }
|
|
|
* */
|
|
|
const toFields = (sql) => {
|
|
|
+ const regexf = /from/i;
|
|
|
+ const regexas = /\s+AS\s+/i;
|
|
|
+ const regexs = /select/gi;
|
|
|
+ const regext = /FROM\s+([\w]+)/i;
|
|
|
+ const regexc = /[^,]*\([^)]*\) AS [^,]*/gi;
|
|
|
+ const regexcs = /\)\s+as\s+([\w]+)/i;
|
|
|
+ const regexjoin = /\b(LEFT\s+JOIN|RIGHT\s+JOIN|INNER\s+JOIN)\b/i;
|
|
|
+
|
|
|
|
|
|
- const regex1 = /from/i;
|
|
|
- const match = sql.match(regex1);
|
|
|
- const fromIndex = match?.index || 0;
|
|
|
- const fieldStr = sql.slice(0, fromIndex).replace(/select/gi,'');
|
|
|
+ const matchf = sql.match(regexf);
|
|
|
+ const fromIndex = matchf?.index || 0;
|
|
|
+ let matchcStr = sql.slice(0, fromIndex).replace(regexs,'');
|
|
|
+
|
|
|
+
|
|
|
+ const matchc = matchcStr.match(regexc);
|
|
|
+ let fieldc = [];
|
|
|
+ if (matchc){
|
|
|
+ matchcStr = matchcStr.replace(regexc, '');
|
|
|
+ fieldc = matchc.map(c=>c.match(regexcs)[1]);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- const fieldArr = fieldStr.split(',');
|
|
|
+ const fieldArr = matchcStr.split(',');
|
|
|
+
|
|
|
+ const sqlRelation = sql.slice(fromIndex);
|
|
|
|
|
|
- const sqlRelation = sql.slice(fromIndex)
|
|
|
- const regex = /\b(LEFT\s+JOIN|RIGHT\s+JOIN|INNER\s+JOIN)\b/i;
|
|
|
- const isJoin = regex.test(sqlRelation.toUpperCase());
|
|
|
-
|
|
|
+ const isJoin = regexjoin.test(sqlRelation.toUpperCase());
|
|
|
|
|
|
- const regex2 = /FROM\s+([\w_]+)/i;
|
|
|
- const matchStr = sqlRelation.match(regex2);
|
|
|
+ const matchStr = sqlRelation.match(regext);
|
|
|
const singleTable = ( matchStr && matchStr[1] ) || "";
|
|
|
|
|
|
|
|
|
- return fieldArr.map(item=> {
|
|
|
+ return fieldArr.concat(fieldc).map(item=> {
|
|
|
let str=item,table=singleTable,field,aliasStr;
|
|
|
|
|
|
- const asRegex = /\s+AS\s+/i;
|
|
|
- const hasAs = asRegex.test(item);
|
|
|
+ const hasAs = regexas.test(item);
|
|
|
if (hasAs){
|
|
|
- const asStr = item.match(asRegex)[0];
|
|
|
+ const asStr = item.match(regexas)[0];
|
|
|
str = item.split(asStr)[0];
|
|
|
aliasStr = item.split(asStr)[1].trim();
|
|
|
}
|
|
@@ -101,13 +114,11 @@ export function useModelConfig() {
|
|
|
const match = sql.match(regex1);
|
|
|
const fromIndex = match?.index || 0;
|
|
|
const sqlRelation = sql.slice(fromIndex);
|
|
|
- let SQLFields = "SELECT "
|
|
|
+ let SQLFields = "SELECT \r\n"
|
|
|
fields.forEach(({bizName,tableName,fieldName,dataType,comment},index) => {
|
|
|
- if (index===fields.length-1){
|
|
|
- SQLFields += `${tableName}.${fieldName} \r\n`
|
|
|
- }else {
|
|
|
- SQLFields += `${tableName}.${fieldName},\r\n`
|
|
|
- }
|
|
|
+
|
|
|
+ const isLast = index===fields.length-1
|
|
|
+ SQLFields += `\t${tableName}.${fieldName}${!isLast&&","}\r\n`
|
|
|
const initObj = bizs.find(item=>item.name===fieldName);
|
|
|
tableData.push({
|
|
|
id:Math.random(),
|
|
@@ -141,6 +152,7 @@ export function useModelConfig() {
|
|
|
const sqlResultToTable = (model,columns,fields,init,bizs) => {
|
|
|
try {
|
|
|
let tableData = [];
|
|
|
+ console.log(bizs)
|
|
|
columns.forEach(col=>{
|
|
|
|
|
|
let table="";
|
|
@@ -187,7 +199,7 @@ export function useModelConfig() {
|
|
|
isKey:DIM_TYPE_ENUM.IDENTIFY===initObj?.type,
|
|
|
common:DIM_TYPE_ENUM.CATEGORICAL===initObj?.type,
|
|
|
datetime:DIM_TYPE_ENUM.DATETIME===initObj?.type,
|
|
|
- measure:!initObj?.type
|
|
|
+ measure:bizs.length>0 && !initObj?.type
|
|
|
}
|
|
|
)
|
|
|
})
|