This commit is contained in:
2024-03-21 18:28:51 +08:00
parent 68e5dda2b8
commit 59585e6369
7 changed files with 93 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ redkale.server[0].protocol = HTTP
redkale.server[0].port = 80 redkale.server[0].port = 80
redkale.server[0].host = 0.0.0.0 redkale.server[0].host = 0.0.0.0
redkale.server[0].maxbody = 2m redkale.server[0].maxbody = 2m
redkale.server[0].root = root
# --- request --- # --- request ---
redkale.server[0].request.remoteaddr = request.headers.X-Real-IP redkale.server[0].request.remoteaddr = request.headers.X-Real-IP

10
pom.xml
View File

@@ -38,7 +38,7 @@
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>LATEST</version> <version>8.0.33</version>
</dependency> </dependency>
<!-- arangodb支持 --> <!-- arangodb支持 -->
@@ -57,7 +57,7 @@
<dependency> <dependency>
<groupId>com.jfinal</groupId> <groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId> <artifactId>jfinal</artifactId>
<version>5.1.5</version> <version>3.3</version>
</dependency> </dependency>
<!-- poi支持 --> <!-- poi支持 -->
@@ -80,6 +80,12 @@
<version>RELEASE</version> <version>RELEASE</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.9</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@@ -80,7 +80,7 @@
<thead> <thead>
<tr> <tr>
<!-- 'sort':field.order>0 --> <!-- 'sort':field.order>0 -->
<!--<th>操作</th>--> <th>操作</th>
<th v-for="field in cfg.shows" <th v-for="field in cfg.shows"
v-if="field.inType != 'HIDDEN'" v-if="field.inType != 'HIDDEN'"
v-text="field.label || getFieldLabel(field.col)" v-text="field.label || getFieldLabel(field.col)"
@@ -93,11 +93,11 @@
<!-- <!--
<td v-for="field in cfg.shows" v-title="dealFieldFmt(row, field.col)" v-text="dealFieldFmt(row, field.col)"></td> <td v-for="field in cfg.shows" v-title="dealFieldFmt(row, field.col)" v-text="dealFieldFmt(row, field.col)"></td>
--> -->
<!--<td> <td v-if="cfg.details.length">
<a href="javascript:;" @click="detailData=row; detail()">详情</a> <a href="javascript:;" @click="detailData=row; detail()">详情</a>
<a href="javascript:;" @click="detailData=row; edit()">编辑</a> <a href="javascript:;" disabled @click="detailData=row; edit()">编辑</a>
<a href="javascript:;" @click="detailData=row; del()">删除</a> <a href="javascript:;" disabled @click="detailData=row; del()">删除</a>
</td>--> </td>
<td v-for="field in cfg.shows" <td v-for="field in cfg.shows"
v-if="field.inType != 'HIDDEN'" v-if="field.inType != 'HIDDEN'"
v-title="dealFieldFmt(row, field)" v-title="dealFieldFmt(row, field)"
@@ -141,7 +141,7 @@
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
<h4 class="modal-title" v-text="cfg.title + ' - [详情]'"> </h4> <h4 class="modal-title" v-text="cfg.title + ' - [详情]'"> </h4>
</div> </div>
<div class="modal-body"> <div class="modal-body" style="width: auto">
<table class="table table-bordered table-hover"> <table class="table table-bordered table-hover">
<tr v-for="i in parseInt(cfg.details.length/2)"> <tr v-for="i in parseInt(cfg.details.length/2)">
@@ -306,6 +306,9 @@
for (i in res["filters"]) { for (i in res["filters"]) {
res["filters"][i]['type'] = res["filters"][i]['filterType'][0]['name'] res["filters"][i]['type'] = res["filters"][i]['filterType'][0]['name']
} }
if (!res.details || res.details.length === 0) {
res.details = res.shows
}
this.cfg = res this.cfg = res
}); });
}, },

View File

@@ -66,14 +66,14 @@
<select class="form-control" v-model="linkItem.f1"> <select class="form-control" v-model="linkItem.f1">
<option></option> <option></option>
<option v-for="item in tableInfoA.items" <option v-for="item in tableInfoA.items"
:value="aliasA + '.' +item.name" v-text="aliasA + '.' +item.name + ' --- '+ item.label"></option> :value="aliasA + '.' +item.name" v-text="strJoin(aliasA + '.' +item.name,item.label, '---')"></option>
</select> </select>
</td> </td>
<td> <td>
<select class="form-control" v-model="linkItem.f2"> <select class="form-control" v-model="linkItem.f2">
<option></option> <option></option>
<option v-for="item in tableInfoB.items" <option v-for="item in tableInfoB.items"
:value="aliasB + '.' +item.name" v-text="aliasB + '.' +item.name + ' --- '+ item.label"> :value="aliasB + '.' +item.name" v-text="strJoin(aliasB + '.' +item.name, item.label, '---')">
</option> </option>
</select> </select>
</td> </td>
@@ -103,7 +103,7 @@
</div> </div>
<div class="modal-body" style="text-align: center"> <div class="modal-body" style="text-align: center">
<select class="form-control" v-model="newLinkTable"> <select class="form-control" v-model="newLinkTable">
<option v-for="x in tables" :value="x" v-text="x.name + ' --- ' + x.comment" v-show="!isDisable(x)"></option> <option v-for="x in tables" :value="x" v-text="strJoin(x.name, x.comment, '---')" v-show="!isDisable(x)"></option>
</select> </select>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@@ -299,6 +299,12 @@
}, },
showInfo() { showInfo() {
$('#f-info').modal({moveable: true}) $('#f-info').modal({moveable: true})
},
strJoin(a,b,c) {
if (a && b) {
return a + ' ' + c + ' ' + b
}
return a + b
} }
}, },
mounted: function () { mounted: function () {

View File

@@ -1,7 +1,6 @@
package net.tccn.base; package net.tccn.base;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.net.http.RestMapping;
import org.redkale.service.Service; import org.redkale.service.Service;
import org.redkale.source.CacheMemorySource; import org.redkale.source.CacheMemorySource;
@@ -21,9 +20,9 @@ public class BaseService implements Service {
@Resource(name = "SERVER_ROOT") @Resource(name = "SERVER_ROOT")
protected File webroot; protected File webroot;
public Logger logger = Logger.getLogger(this.getClass().getSimpleName()); protected Logger logger = Logger.getLogger(this.getClass().getSimpleName());
public static boolean isWinos = System.getProperty("os.name").contains("Window"); protected static boolean isWinos = System.getProperty("os.name").contains("Window");
@Resource(name = "cache") @Resource(name = "cache")
protected static CacheMemorySource cacheSource = new CacheMemorySource("cache"); protected static CacheMemorySource cacheSource = new CacheMemorySource("cache");
@@ -31,13 +30,12 @@ public class BaseService implements Service {
@Resource(name = "APP_HOME") @Resource(name = "APP_HOME")
protected File APP_HOME; protected File APP_HOME;
public static Properties prop = new Properties(); protected static Properties prop = new Properties();
protected static TplKit tplKit = TplKit.use(true); protected static TplKit tplKit = TplKit.use(true);
private static boolean tplInit = false; private static boolean tplInit = false;
@RestMapping(ignore = true) protected <T> T getT(String key, Class<T> clazz, Supplier<T> supplier) {
public <T> T getT(String key, Class<T> clazz, Supplier<T> supplier) {
Object obj = cacheSource.getAndRefresh(key, 1000 * 60 * 3, clazz); Object obj = cacheSource.getAndRefresh(key, 1000 * 60 * 3, clazz);
if (obj != null) { if (obj != null) {
return (T) obj; return (T) obj;
@@ -50,12 +48,11 @@ public class BaseService implements Service {
return t; return t;
} }
@RestMapping(ignore = true) protected String platId(String token) {
public String platId(String token) {
return MetaKit.getPlatId(token); return MetaKit.getPlatId(token);
} }
public boolean isEmpty(Object obj) { protected boolean isEmpty(Object obj) {
return Utils.isEmpty(obj); return Utils.isEmpty(obj);
} }
} }

View File

@@ -1,5 +1,10 @@
package net.tccn.base; package net.tccn.base;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.*;
import net.tccn.base.dbq.jdbc.api.DbSource; import net.tccn.base.dbq.jdbc.api.DbSource;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@@ -211,4 +216,45 @@ public class Utils {
return _group; return _group;
} }
public static String parserSql(String originalSql) {
try {
Select select = (Select) CCJSqlParserUtil.parse(originalSql);
// 如果未设置分页,设置默认分页 99
if (select.getLimit() == null) {
Limit limit = new Limit().withRowCount(new LongValue(10));
select.setLimit(limit);
originalSql = select.toString();
}
return originalSql;
} catch (JSQLParserException e) {
throw new RuntimeException(e);
}
}
public static String parserCountSql(String originalSql) {
String sqlCount = "SELECT COUNT(1)";
try {
Select select = (Select) CCJSqlParserUtil.parse(originalSql);
PlainSelect plainSelect = select.getPlainSelect();
FromItem fromItem = plainSelect.getFromItem();
List<Join> joins = plainSelect.getJoins();
Expression where = plainSelect.getWhere();
sqlCount += " FROM " + fromItem;
if (joins != null) {
for (Join join : joins) {
sqlCount += " " + join;
}
}
sqlCount += " WHERE " + where;
} catch (Exception e) {
throw new RuntimeException(e);
}
return sqlCount;
}
} }

View File

@@ -3,7 +3,9 @@ package net.tccn.qtask.impl;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect; import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.template.Engine; import com.jfinal.template.Engine;
import com.jfinal.template.Template; import com.jfinal.template.Template;
import net.tccn.base.Kv;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.base.Utils;
import net.tccn.base.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.qtask.QTask; import net.tccn.qtask.QTask;
import net.tccn.qtask.Task; import net.tccn.qtask.Task;
@@ -31,6 +33,11 @@ public class QTaskMysql extends QTaskAbs implements QTask {
Template tpl = engine.getTemplateByString(task.getContent()); Template tpl = engine.getTemplateByString(task.getContent());
String sql = tpl.renderToString(getTask().getPara()).replaceAll("[\\s]+", " "); String sql = tpl.renderToString(getTask().getPara()).replaceAll("[\\s]+", " ");
// 聚合统计返回统计结果 TODO 待完善
if ((sql.startsWith("SELECT COUNT") || sql.startsWith("select count") || sql.startsWith("SELECT count") || sql.startsWith("select COUNT"))) {
return dbKit.find(sql, Kv.class);
}
/* /*
// todo: 从sql分析支持多种sql处理类别 // todo: 从sql分析支持多种sql处理类别
if (sql.startsWith("select count")) { if (sql.startsWith("select count")) {
@@ -58,6 +65,12 @@ public class QTaskMysql extends QTaskAbs implements QTask {
dbKit.exetute(sql); dbKit.exetute(sql);
}*/ }*/
return dbKit.queryList(sql, Map.class); // sql 解析-检查:未设置分页设置默认分页
sql = Utils.parserSql(sql);
Kv kv = Kv.of();
kv.set("count", dbKit.findLong(Utils.parserCountSql(sql)));
kv.set("list", dbKit.queryList(sql, Map.class));
return kv;
} }
} }