|
@@ -1,5 +1,7 @@
|
|
package com.gyee.table.service.impl;
|
|
package com.gyee.table.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -83,8 +85,14 @@ public class ObjectServiceImpl implements IObjectService {
|
|
table.setTableHeader(tableColumnHeader);
|
|
table.setTableHeader(tableColumnHeader);
|
|
table.setTableData(lms);
|
|
table.setTableData(lms);
|
|
//截取sql
|
|
//截取sql
|
|
- if (sql.contains("limit")){
|
|
|
|
- String newSql = sql.split("limit")[0];
|
|
|
|
|
|
+ if (sql.contains("limit")||sql.contains("LIMIT")){
|
|
|
|
+
|
|
|
|
+ String newSql = "";
|
|
|
|
+ if(sql.contains("LIMIT"))
|
|
|
|
+ newSql= sql.split("LIMIT")[0];
|
|
|
|
+ else if (sql.contains("limit")){
|
|
|
|
+ newSql= sql.split("limit")[0];
|
|
|
|
+ }
|
|
List<LinkedHashMap<String, Object>> linkedHashMaps = objectMapper.selectAll(newSql);
|
|
List<LinkedHashMap<String, Object>> linkedHashMaps = objectMapper.selectAll(newSql);
|
|
table.setCount(linkedHashMaps.size());
|
|
table.setCount(linkedHashMaps.size());
|
|
}else {
|
|
}else {
|
|
@@ -93,6 +101,23 @@ public class ObjectServiceImpl implements IObjectService {
|
|
return Result.successData(ResultCode.SUCCESS,table);
|
|
return Result.successData(ResultCode.SUCCESS,table);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject selectBySqlToEchart(Map map) {
|
|
|
|
+ String sql = (String)map.get("sql");
|
|
|
|
+ if (StringUtils.isBlank(sql)) {
|
|
|
|
+ return Result.error(ResultCode.PARAM_IS_BLANK);
|
|
|
|
+ } else {
|
|
|
|
+ Matcher matcher = this.compile.matcher(sql);
|
|
|
|
+ if (matcher.find()) {
|
|
|
|
+ String group = matcher.group(0);
|
|
|
|
+ return Result.error(ResultCode.ERROR_UNSUPPORTED_SQL, "查看字符:" + group);
|
|
|
|
+ } else {
|
|
|
|
+ List<LinkedHashMap<String, Object>> lms = this.objectMapper.selectAll(sql);
|
|
|
|
+ return Result.successData(ResultCode.SUCCESS, lms);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据表头和数据生成默认表头
|
|
* 根据表头和数据生成默认表头
|
|
* @param tablename
|
|
* @param tablename
|
|
@@ -102,8 +127,11 @@ public class ObjectServiceImpl implements IObjectService {
|
|
private List<TableColumnHeader> createTableColumnHeader(String tablename, LinkedHashMap<String, Object> solhm) {
|
|
private List<TableColumnHeader> createTableColumnHeader(String tablename, LinkedHashMap<String, Object> solhm) {
|
|
List<TableColumnHeader> tableHeaderColumns = new ArrayList<>();
|
|
List<TableColumnHeader> tableHeaderColumns = new ArrayList<>();
|
|
long tableId = tableColumnHeaderMapper.selectCount(Wrappers.emptyWrapper()) + 1;
|
|
long tableId = tableColumnHeaderMapper.selectCount(Wrappers.emptyWrapper()) + 1;
|
|
|
|
+ int id=0;
|
|
for (String s : solhm.keySet()) {
|
|
for (String s : solhm.keySet()) {
|
|
TableColumnHeader tch = new TableColumnHeader();
|
|
TableColumnHeader tch = new TableColumnHeader();
|
|
|
|
+ id=id+1;
|
|
|
|
+ tch.setId(String.valueOf(id));
|
|
tch.setTid(tableId);
|
|
tch.setTid(tableId);
|
|
tch.setName(tablename);
|
|
tch.setName(tablename);
|
|
tch.setType("");
|
|
tch.setType("");
|
|
@@ -121,6 +149,7 @@ public class ObjectServiceImpl implements IObjectService {
|
|
tch.setFilters(emptyArray);
|
|
tch.setFilters(emptyArray);
|
|
tch.setFormattype("");
|
|
tch.setFormattype("");
|
|
tch.setFormat(emptyArray);
|
|
tch.setFormat(emptyArray);
|
|
|
|
+ tch.setFixed(false);
|
|
|
|
|
|
tableHeaderColumns.add(tch);
|
|
tableHeaderColumns.add(tch);
|
|
}
|
|
}
|