Compare commits
No commits in common. "80920a28a55c2162ca4e86218f49a0edc8f83913" and "ef5ff147ae722ff27dee17d95da6b858f869b042" have entirely different histories.
80920a28a5
...
ef5ff147ae
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"JAVA_HOME": "C:\\Users\\13910\\.jdks\\corretto-21.0.5"
|
|
||||||
}
|
|
@ -93,11 +93,6 @@
|
|||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>5.8.38</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.gisbi</groupId>
|
<groupId>io.gisbi</groupId>
|
||||||
<artifactId>api-permissions</artifactId>
|
<artifactId>api-permissions</artifactId>
|
||||||
@ -189,15 +184,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.11.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>21</source>
|
|
||||||
<target>21</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
@ -201,7 +201,7 @@ public class RoleController {
|
|||||||
boolean isOk = true;
|
boolean isOk = true;
|
||||||
String[] temp = userids.split(",");
|
String[] temp = userids.split(",");
|
||||||
for (String userid : temp) {
|
for (String userid : temp) {
|
||||||
isOk = isOk && userService.addUserRole(roleid, userid);
|
isOk = isOk && userService.addUserRoles(roleid, userid);
|
||||||
}
|
}
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
|
@ -86,5 +86,5 @@ public interface IUserService extends IService<User> {
|
|||||||
* userids 用户id组
|
* userids 用户id组
|
||||||
* 返回值说明: 是否新增成功
|
* 返回值说明: 是否新增成功
|
||||||
***********************************/
|
***********************************/
|
||||||
boolean addUserRole(String roleid, String userid);
|
boolean addUserRoles(String roleid, String userid);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||||||
* 返回值说明: 是否新增成功
|
* 返回值说明: 是否新增成功
|
||||||
***********************************/
|
***********************************/
|
||||||
@Override
|
@Override
|
||||||
public boolean addUserRole(String roleid, String userid) {
|
public boolean addUserRoles(String roleid, String userid) {
|
||||||
boolean isOk = true;
|
boolean isOk = true;
|
||||||
if (StringUtils.isEmpty(roleid) || StringUtils.isEmpty(userid)) {
|
if (StringUtils.isEmpty(roleid) || StringUtils.isEmpty(userid)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package io.gisbi.dataset.manage;
|
package io.gisbi.dataset.manage;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import io.gisbi.api.chart.dto.DeSortField;
|
import io.gisbi.api.chart.dto.DeSortField;
|
||||||
import io.gisbi.api.dataset.dto.*;
|
import io.gisbi.api.dataset.dto.*;
|
||||||
import io.gisbi.api.dataset.union.DatasetGroupInfoDTO;
|
import io.gisbi.api.dataset.union.DatasetGroupInfoDTO;
|
||||||
@ -9,10 +7,6 @@ import io.gisbi.api.dataset.union.DatasetTableInfoDTO;
|
|||||||
import io.gisbi.chart.utils.ChartDataBuild;
|
import io.gisbi.chart.utils.ChartDataBuild;
|
||||||
import io.gisbi.commons.utils.SqlparserUtils;
|
import io.gisbi.commons.utils.SqlparserUtils;
|
||||||
import io.gisbi.dataset.constant.DatasetTableType;
|
import io.gisbi.dataset.constant.DatasetTableType;
|
||||||
import io.gisbi.dataset.dao.auto.entity.CoreDatasetTable;
|
|
||||||
import io.gisbi.dataset.dao.auto.entity.CoreDatasetTableField;
|
|
||||||
import io.gisbi.dataset.dao.auto.mapper.CoreDatasetTableFieldMapper;
|
|
||||||
import io.gisbi.dataset.dao.auto.mapper.CoreDatasetTableMapper;
|
|
||||||
import io.gisbi.dataset.utils.DatasetUtils;
|
import io.gisbi.dataset.utils.DatasetUtils;
|
||||||
import io.gisbi.dataset.utils.FieldUtils;
|
import io.gisbi.dataset.utils.FieldUtils;
|
||||||
import io.gisbi.dataset.utils.TableUtils;
|
import io.gisbi.dataset.utils.TableUtils;
|
||||||
@ -77,10 +71,7 @@ public class DatasetDataManage {
|
|||||||
private DatasetTableSqlLogManage datasetTableSqlLogManage;
|
private DatasetTableSqlLogManage datasetTableSqlLogManage;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private PluginManageApi pluginManage;
|
private PluginManageApi pluginManage;
|
||||||
@Resource
|
|
||||||
private CoreDatasetTableFieldMapper coreDatasetTableFieldMapper;
|
|
||||||
@Resource
|
|
||||||
private CoreDatasetTableMapper coreDatasetTableMapper;
|
|
||||||
@Resource
|
@Resource
|
||||||
private DataSourceManage dataSourceManage;
|
private DataSourceManage dataSourceManage;
|
||||||
|
|
||||||
@ -1148,333 +1139,4 @@ public class DatasetDataManage {
|
|||||||
return nodes;
|
return nodes;
|
||||||
|
|
||||||
}
|
}
|
||||||
//-----------------------下面代码为扩展代码,实现了数据表的增删改查功能--zhengsl at 2025-05-20----------------------------------------------------------------------------------------//
|
|
||||||
public List<CoreDatasetTable> getTablesByAppId(Long id) throws Exception {
|
|
||||||
QueryWrapper<CoreDatasetTable> wrapper = new QueryWrapper<>();
|
|
||||||
wrapper.eq("app_id", id);
|
|
||||||
wrapper.eq("type", "db");
|
|
||||||
List<CoreDatasetTable> tables = coreDatasetTableMapper.selectList(wrapper);
|
|
||||||
return tables;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CoreDatasetTableField> getFieldsByTableId(Long id) throws Exception {
|
|
||||||
QueryWrapper<CoreDatasetTableField> wrapper = new QueryWrapper<>();
|
|
||||||
wrapper.eq("dataset_table_id", id);
|
|
||||||
wrapper.eq("checked", true);
|
|
||||||
wrapper.isNull("chart_id");
|
|
||||||
List<CoreDatasetTableField> fields = coreDatasetTableFieldMapper.selectList(wrapper);
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addTableData(Long datasourceId, String tableData) throws Exception {
|
|
||||||
// 根据数据源 id 查询数据源信息,调用通用数据源执行器
|
|
||||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
|
||||||
if (coreDatasource == null) {
|
|
||||||
DEException.throwException("数据源不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 tableData JSON 字符串 "{ \"tableName\": \"user\", \"data\": [ { \"fieldName\": \"id\", \"fieldType\": \"varchar\", \"IsPrimaryKey\": true, \"fieldValue\": \"0001\" }, { \"fieldName\": \"name\", \"fieldType\": \"varchar\", \"fieldValue\": \"张三\" } ] }";
|
|
||||||
Map<String, Object> dataMap = JsonUtil.parseObject(tableData, Map.class);
|
|
||||||
String tableName = (String) dataMap.get("tableName");
|
|
||||||
List<Map<String, Object>> fieldList = (List<Map<String, Object>>) dataMap.get("data");
|
|
||||||
|
|
||||||
if (fieldList == null || fieldList.isEmpty()) {
|
|
||||||
DEException.throwException("没有可插入的数据字段");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建插入语句
|
|
||||||
StringBuilder columns = new StringBuilder();
|
|
||||||
StringBuilder values = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < fieldList.size(); i++) {
|
|
||||||
Map<String, Object> field = fieldList.get(i);
|
|
||||||
String fieldName = (String) field.get("fieldName");
|
|
||||||
Object fieldValue = field.get("fieldValue");
|
|
||||||
|
|
||||||
if (i > 0) {
|
|
||||||
columns.append(", ");
|
|
||||||
values.append(", ");
|
|
||||||
}
|
|
||||||
columns.append(fieldName);
|
|
||||||
if (fieldValue instanceof String) {
|
|
||||||
values.append("'").append(fieldValue).append("'");
|
|
||||||
} else {
|
|
||||||
values.append(fieldValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, columns.toString(), values.toString());
|
|
||||||
|
|
||||||
// 调用执行器,向数据表中插入 tableData 数据
|
|
||||||
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
|
|
||||||
BeanUtils.copyBean(datasourceSchemaDTO, coreDatasource);
|
|
||||||
|
|
||||||
Provider provider = ProviderFactory.getProvider(coreDatasource.getType());
|
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
|
||||||
datasourceRequest.setQuery(sql);
|
|
||||||
datasourceRequest.setDsList(Map.of(datasourceSchemaDTO.getId(), datasourceSchemaDTO));
|
|
||||||
|
|
||||||
logger.debug("执行插入数据的SQL: {}", sql);
|
|
||||||
|
|
||||||
// 执行插入操作
|
|
||||||
Map<String, Object> result = provider.fetchResultField(datasourceRequest);
|
|
||||||
return result != null && !result.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updateTableData(Long datasourceId, String tableData) throws Exception {
|
|
||||||
// 获取数据源信息
|
|
||||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
|
||||||
if (coreDatasource == null) {
|
|
||||||
DEException.throwException("数据源不存在");
|
|
||||||
}
|
|
||||||
//String tableDataJson = "{ \"tableName\": \"user\", \"primaryKeyField\": \"id\", \"primaryKeyValue\": \"0001\", \"data\": [ { \"fieldName\": \"name\", \"fieldType\": \"varchar\", \"fieldValue\": \"李四\" } ] }";
|
|
||||||
// 解析 JSON 数据
|
|
||||||
Map<String, Object> dataMap = JsonUtil.parseObject(tableData, Map.class);
|
|
||||||
String tableName = (String) dataMap.get("tableName");
|
|
||||||
String primaryKeyField = (String) dataMap.get("primaryKeyField");
|
|
||||||
Object primaryKeyValue = dataMap.get("primaryKeyValue");
|
|
||||||
List<Map<String, Object>> fieldList = (List<Map<String, Object>>) dataMap.get("data");
|
|
||||||
|
|
||||||
if (fieldList == null || fieldList.isEmpty()) {
|
|
||||||
DEException.throwException("没有可更新的数据字段");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(tableName)) {
|
|
||||||
DEException.throwException("表名不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(primaryKeyField) || primaryKeyValue == null) {
|
|
||||||
DEException.throwException("主键字段或值不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建 UPDATE 语句
|
|
||||||
StringBuilder setClause = new StringBuilder();
|
|
||||||
for (int i = 0; i < fieldList.size(); i++) {
|
|
||||||
Map<String, Object> field = fieldList.get(i);
|
|
||||||
String fieldName = (String) field.get("fieldName");
|
|
||||||
Object fieldValue = field.get("fieldValue");
|
|
||||||
|
|
||||||
if (i > 0) {
|
|
||||||
setClause.append(", ");
|
|
||||||
}
|
|
||||||
if (fieldValue instanceof String) {
|
|
||||||
setClause.append(String.format("%s = '%s'", fieldName, fieldValue));
|
|
||||||
} else {
|
|
||||||
setClause.append(String.format("%s = %s", fieldName, fieldValue));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String whereClause = String.format("%s = ", primaryKeyField);
|
|
||||||
if (primaryKeyValue instanceof String) {
|
|
||||||
whereClause += String.format("'%s'", primaryKeyValue);
|
|
||||||
} else {
|
|
||||||
whereClause += primaryKeyValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = String.format("UPDATE %s SET %s WHERE %s", tableName, setClause.toString(), whereClause);
|
|
||||||
|
|
||||||
// 调用执行器执行 SQL
|
|
||||||
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
|
|
||||||
BeanUtils.copyBean(datasourceSchemaDTO, coreDatasource);
|
|
||||||
|
|
||||||
Provider provider = ProviderFactory.getProvider(coreDatasource.getType());
|
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
|
||||||
datasourceRequest.setQuery(sql);
|
|
||||||
datasourceRequest.setDsList(Map.of(datasourceSchemaDTO.getId(), datasourceSchemaDTO));
|
|
||||||
|
|
||||||
logger.debug("执行更新数据的SQL: {}", sql);
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
Map<String, Object> result = provider.fetchResultField(datasourceRequest);
|
|
||||||
return result != null && !result.isEmpty();
|
|
||||||
}
|
|
||||||
public boolean deleteTableData(Long datasourceId, String whereJson) throws Exception {
|
|
||||||
// 获取数据源信息
|
|
||||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
|
||||||
if (coreDatasource == null) {
|
|
||||||
DEException.throwException("数据源不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 JSON 数据
|
|
||||||
//String tableDataJson = "{ \"tableName\": \"user\", \"primaryKeyField\": \"id\", \"primaryKeyValue\": \"0001\" }";
|
|
||||||
Map<String, Object> dataMap = JsonUtil.parseObject(whereJson, Map.class);
|
|
||||||
String tableName = (String) dataMap.get("tableName");
|
|
||||||
String primaryKeyField = (String) dataMap.get("primaryKeyField");
|
|
||||||
Object primaryKeyValue = dataMap.get("primaryKeyValue");
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(tableName)) {
|
|
||||||
DEException.throwException("表名不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(primaryKeyField) || primaryKeyValue == null) {
|
|
||||||
DEException.throwException("主键字段或值不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建 DELETE 语句
|
|
||||||
String whereClause = String.format("%s = ", primaryKeyField);
|
|
||||||
if (primaryKeyValue instanceof String) {
|
|
||||||
whereClause += String.format("'%s'", primaryKeyValue);
|
|
||||||
} else {
|
|
||||||
whereClause += primaryKeyValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = String.format("DELETE FROM %s WHERE %s", tableName, whereClause);
|
|
||||||
|
|
||||||
// 调用执行器执行 SQL
|
|
||||||
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
|
|
||||||
BeanUtils.copyBean(datasourceSchemaDTO, coreDatasource);
|
|
||||||
|
|
||||||
Provider provider = ProviderFactory.getProvider(coreDatasource.getType());
|
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
|
||||||
datasourceRequest.setQuery(sql);
|
|
||||||
datasourceRequest.setDsList(Map.of(datasourceSchemaDTO.getId(), datasourceSchemaDTO));
|
|
||||||
|
|
||||||
logger.debug("执行删除数据的SQL: {}", sql);
|
|
||||||
|
|
||||||
// 执行删除操作
|
|
||||||
Map<String, Object> result = provider.fetchResultField(datasourceRequest);
|
|
||||||
return result != null && !result.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Map<String, Object>> queryTableDataPaged(Long datasourceId, String queryJson) throws Exception {
|
|
||||||
// 获取数据源信息
|
|
||||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
|
||||||
if (coreDatasource == null) {
|
|
||||||
DEException.throwException("数据源不存在");
|
|
||||||
}
|
|
||||||
//String queryJson = "{ \"tableName\": \"user\", \"conditions\": [ { \"field\": \"name\", \"operator\": \"like\", \"value\": \"张\" }, { \"field\": \"id\", \"operator\": \"in\", \"value\": [1, 2, 3] } ], \"pageNum\": 1, \"pageSize\": 10 }";
|
|
||||||
|
|
||||||
// 解析 JSON 查询参数
|
|
||||||
Map<String, Object> dataMap = JsonUtil.parseObject(queryJson, Map.class);
|
|
||||||
String tableName = (String) dataMap.get("tableName");
|
|
||||||
List<Map<String, Object>> conditionList = (List<Map<String, Object>>) dataMap.get("conditions");
|
|
||||||
|
|
||||||
Integer pageNum = (Integer) dataMap.getOrDefault("pageNum", 1);
|
|
||||||
Integer pageSize = (Integer) dataMap.getOrDefault("pageSize", 10);
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(tableName)) {
|
|
||||||
DEException.throwException("表名不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建 WHERE 条件子句
|
|
||||||
StringBuilder whereClause = new StringBuilder();
|
|
||||||
|
|
||||||
if (conditionList != null && !conditionList.isEmpty()) {
|
|
||||||
whereClause.append(" WHERE ");
|
|
||||||
for (int i = 0; i < conditionList.size(); i++) {
|
|
||||||
Map<String, Object> condition = conditionList.get(i);
|
|
||||||
String field = (String) condition.get("field");
|
|
||||||
String operator = ((String) condition.get("operator")).toLowerCase();
|
|
||||||
Object value = condition.get("value");
|
|
||||||
|
|
||||||
if (i > 0) {
|
|
||||||
whereClause.append(" AND ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理不同类型的条件
|
|
||||||
switch (operator) {
|
|
||||||
case "like":
|
|
||||||
whereClause.append(String.format("%s LIKE '%%%s%%'", field, value));
|
|
||||||
break;
|
|
||||||
case "=":
|
|
||||||
appendValue(whereClause, field, value, "=");
|
|
||||||
break;
|
|
||||||
case "<":
|
|
||||||
appendValue(whereClause, field, value, "<");
|
|
||||||
break;
|
|
||||||
case ">":
|
|
||||||
appendValue(whereClause, field, value, ">");
|
|
||||||
break;
|
|
||||||
case "<=":
|
|
||||||
appendValue(whereClause, field, value, "<=");
|
|
||||||
break;
|
|
||||||
case ">=":
|
|
||||||
appendValue(whereClause, field, value, ">=");
|
|
||||||
break;
|
|
||||||
case "!=":
|
|
||||||
case "<>":
|
|
||||||
appendValue(whereClause, field, value, "<>");
|
|
||||||
break;
|
|
||||||
case "in":
|
|
||||||
if (!(value instanceof List<?>)) {
|
|
||||||
DEException.throwException("IN 操作符要求值为列表类型");
|
|
||||||
}
|
|
||||||
List<?> values = (List<?>) value;
|
|
||||||
String inValues = values.stream()
|
|
||||||
.map(v -> v instanceof String ? "'" + v + "'" : v.toString())
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
whereClause.append(String.format("%s IN (%s)", field, inValues));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DEException.throwException("不支持的操作符: " + operator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建基础查询语句
|
|
||||||
String baseSql = String.format("SELECT * FROM %s%s", tableName, whereClause);
|
|
||||||
|
|
||||||
// 根据数据库类型生成分页语句
|
|
||||||
String dbType = coreDatasource.getType().toLowerCase();
|
|
||||||
String pagedSql = buildPagedSQL(baseSql, dbType, pageNum, pageSize);
|
|
||||||
|
|
||||||
// 构建 COUNT 查询语句用于分页计算
|
|
||||||
String countSql = String.format("SELECT COUNT(*) FROM %s%s", tableName, whereClause);
|
|
||||||
|
|
||||||
// 执行查询
|
|
||||||
DatasourceSchemaDTO schemaDTO = new DatasourceSchemaDTO();
|
|
||||||
BeanUtils.copyBean(schemaDTO, coreDatasource);
|
|
||||||
|
|
||||||
Provider provider = ProviderFactory.getProvider(coreDatasource.getType());
|
|
||||||
DatasourceRequest request = new DatasourceRequest();
|
|
||||||
request.setDsList(Map.of(schemaDTO.getId(), schemaDTO));
|
|
||||||
|
|
||||||
// 1. 查询分页数据
|
|
||||||
request.setQuery(pagedSql);
|
|
||||||
Map<String, Object> result = provider.fetchResultField(request);
|
|
||||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) result.get("data");
|
|
||||||
|
|
||||||
// 2. 查询总记录数
|
|
||||||
request.setQuery(countSql);
|
|
||||||
Map<String, Object> countResult = provider.fetchResultField(request);
|
|
||||||
long total = Long.parseLong(((List<String[]>) countResult.get("data")).get(0)[0]);
|
|
||||||
|
|
||||||
// 封装分页结果
|
|
||||||
Page<Map<String, Object>> page = new Page<>();
|
|
||||||
page.setCurrent(pageNum);
|
|
||||||
page.setSize(pageSize);
|
|
||||||
page.setTotal(total);
|
|
||||||
page.setRecords(dataList);
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendValue(StringBuilder sb, String field, Object value, String op) {
|
|
||||||
if (value instanceof String) {
|
|
||||||
sb.append(String.format("%s %s '%s'", field, op, value));
|
|
||||||
} else {
|
|
||||||
sb.append(String.format("%s %s %s", field, op, value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String buildPagedSQL(String baseSql, String dbType, int pageNum, int pageSize) {
|
|
||||||
int offset = (pageNum - 1) * pageSize;
|
|
||||||
|
|
||||||
switch (dbType) {
|
|
||||||
case "mysql":
|
|
||||||
case "mariadb":
|
|
||||||
return String.format("%s LIMIT %d OFFSET %d", baseSql, pageSize, offset);
|
|
||||||
case "postgresql":
|
|
||||||
return String.format("%s LIMIT %d OFFSET %d", baseSql, pageSize, offset);
|
|
||||||
case "oracle":
|
|
||||||
int start = offset + 1;
|
|
||||||
int end = offset + pageSize;
|
|
||||||
return String.format("SELECT * FROM (SELECT ROWNUM rn, t.* FROM (%s) t WHERE ROWNUM <= %d) WHERE rn >= %d", baseSql, end, start);
|
|
||||||
case "sqlserver":
|
|
||||||
return String.format("%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY", baseSql, offset, pageSize);
|
|
||||||
default:
|
|
||||||
// 默认使用 MySQL 方式
|
|
||||||
return String.format("%s LIMIT %d OFFSET %d", baseSql, pageSize, offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.gisbi.dataset.server;
|
package io.gisbi.dataset.server;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import io.gisbi.api.dataset.DatasetDataApi;
|
import io.gisbi.api.dataset.DatasetDataApi;
|
||||||
import io.gisbi.api.dataset.dto.BaseTreeNodeDTO;
|
import io.gisbi.api.dataset.dto.BaseTreeNodeDTO;
|
||||||
import io.gisbi.api.dataset.dto.EnumValueRequest;
|
import io.gisbi.api.dataset.dto.EnumValueRequest;
|
||||||
@ -8,15 +7,11 @@ import io.gisbi.api.dataset.dto.MultFieldValuesRequest;
|
|||||||
import io.gisbi.api.dataset.dto.PreviewSqlDTO;
|
import io.gisbi.api.dataset.dto.PreviewSqlDTO;
|
||||||
import io.gisbi.api.dataset.union.DatasetGroupInfoDTO;
|
import io.gisbi.api.dataset.union.DatasetGroupInfoDTO;
|
||||||
import io.gisbi.api.dataset.dto.EnumObj;
|
import io.gisbi.api.dataset.dto.EnumObj;
|
||||||
import io.gisbi.dataset.dao.auto.entity.CoreDatasetTable;
|
|
||||||
import io.gisbi.dataset.dao.auto.entity.CoreDatasetTableField;
|
|
||||||
import io.gisbi.dataset.manage.DatasetDataManage;
|
import io.gisbi.dataset.manage.DatasetDataManage;
|
||||||
import io.gisbi.extensions.datasource.dto.DatasetTableDTO;
|
import io.gisbi.extensions.datasource.dto.DatasetTableDTO;
|
||||||
import io.gisbi.extensions.datasource.dto.DatasetTableFieldDTO;
|
import io.gisbi.extensions.datasource.dto.DatasetTableFieldDTO;
|
||||||
import io.gisbi.utils.LogUtil;
|
import io.gisbi.utils.LogUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@ -37,7 +32,6 @@ public class DatasetDataServer implements DatasetDataApi {
|
|||||||
return datasetDataManage.previewDataWithLimit(datasetGroupInfoDTO, 0, 100, false);
|
return datasetDataManage.previewDataWithLimit(datasetGroupInfoDTO, 0, 100, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DatasetTableFieldDTO> tableField(DatasetTableDTO datasetTableDTO) throws Exception {
|
public List<DatasetTableFieldDTO> tableField(DatasetTableDTO datasetTableDTO) throws Exception {
|
||||||
return datasetDataManage.getTableFields(datasetTableDTO);
|
return datasetDataManage.getTableFields(datasetTableDTO);
|
||||||
@ -106,47 +100,4 @@ public class DatasetDataServer implements DatasetDataApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("getTablesByAppId")
|
|
||||||
public List<CoreDatasetTable> getTablesByAppId(Long id) throws Exception {
|
|
||||||
List<CoreDatasetTable> result = datasetDataManage.getTablesByAppId(id);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@GetMapping("getFieldsByTableId")
|
|
||||||
public List<CoreDatasetTableField> getFieldsByTableId(Long id) throws Exception {
|
|
||||||
List<CoreDatasetTableField> result = datasetDataManage.getFieldsByTableId(id);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@PostMapping("addTableData")
|
|
||||||
public boolean addTableData(Long datasourceId, String tableData) throws Exception {
|
|
||||||
boolean result = datasetDataManage.addTableData(
|
|
||||||
datasourceId,
|
|
||||||
tableData
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@PostMapping("updateTableData")
|
|
||||||
public boolean updateTableData(Long datasourceId, String tableData) throws Exception {
|
|
||||||
boolean result = datasetDataManage.updateTableData(
|
|
||||||
datasourceId,
|
|
||||||
tableData
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@PostMapping("deleteTableData")
|
|
||||||
public boolean deleteTableData(Long datasourceId, String whereJson) throws Exception {
|
|
||||||
boolean result = datasetDataManage.deleteTableData(
|
|
||||||
datasourceId,
|
|
||||||
whereJson
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@GetMapping("queryTableDataPaged")
|
|
||||||
public Page<Map<String, Object>> queryTableDataPaged(Long datasourceId, String queryJson) throws Exception {
|
|
||||||
Page<Map<String, Object>> result = datasetDataManage.queryTableDataPaged(
|
|
||||||
datasourceId,
|
|
||||||
queryJson
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user