mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
commit:同步2.2版本
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.orangeforms.common.online.config;
|
||||
|
||||
import com.orangeforms.common.core.config.CoreProperties;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@@ -13,16 +14,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ConfigurationProperties(prefix = "common-online")
|
||||
public class OnlineProperties {
|
||||
|
||||
/**
|
||||
* 数据库类型。
|
||||
*/
|
||||
private String databaseType = CoreProperties.MYSQL_TYPE;
|
||||
/**
|
||||
* 仅以该前缀开头的数据表才会成为动态表单的候选数据表,如: zz_。如果为空,则所有表均可被选。
|
||||
*/
|
||||
private String tablePrefix;
|
||||
|
||||
/**
|
||||
* 在线表单业务操作的URL前缀。
|
||||
*/
|
||||
private String operationUrlPrefix;
|
||||
|
||||
/**
|
||||
* 上传文件的根路径。
|
||||
*/
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface OnlineDblinkMapper extends BaseDaoMapper<OnlineDblink> {
|
||||
+ "WHERE "
|
||||
+ " table_schema = (SELECT database()) "
|
||||
+ " <if test=\"prefix != null and prefix != ''\">"
|
||||
+ " AND table_name like '${prefix}%'"
|
||||
+ " AND table_name LIKE '${prefix}%'"
|
||||
+ " </if>"
|
||||
+ "</script>")
|
||||
List<Map<String, Object>> getTableListWithPrefix(@Param("prefix") String prefix);
|
||||
@@ -59,7 +59,9 @@ public interface OnlineDblinkMapper extends BaseDaoMapper<OnlineDblink> {
|
||||
" create_time createTime \n" +
|
||||
"FROM \n" +
|
||||
" information_schema.tables \n" +
|
||||
"WHERE table_schema = (SELECT database()) AND table_name = #{tableName}")
|
||||
"WHERE \n" +
|
||||
" table_schema = (SELECT database()) \n" +
|
||||
" AND table_name = #{tableName}")
|
||||
Map<String, Object> getTableByName(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
@@ -80,9 +82,13 @@ public interface OnlineDblinkMapper extends BaseDaoMapper<OnlineDblink> {
|
||||
" CHARACTER_MAXIMUM_LENGTH stringPrecision, \n" +
|
||||
" numeric_precision numericPrecision, \n" +
|
||||
" COLUMN_DEFAULT columnDefault \n" +
|
||||
"FROM information_schema.columns \n" +
|
||||
"WHERE table_name = #{tableName} \n" +
|
||||
" AND table_schema = (SELECT database()) ORDER BY ordinal_position")
|
||||
"FROM \n" +
|
||||
" information_schema.columns \n" +
|
||||
"WHERE \n" +
|
||||
" table_name = #{tableName} \n" +
|
||||
" AND table_schema = (SELECT database()) \n" +
|
||||
"ORDER BY \n" +
|
||||
" ordinal_position")
|
||||
List<Map<String, Object>> getTableColumnList(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
@@ -104,10 +110,12 @@ public interface OnlineDblinkMapper extends BaseDaoMapper<OnlineDblink> {
|
||||
" CHARACTER_MAXIMUM_LENGTH stringPrecision, \n" +
|
||||
" numeric_precision numericPrecision, \n" +
|
||||
" COLUMN_DEFAULT columnDefault \n" +
|
||||
"FROM information_schema.columns \n" +
|
||||
"WHERE table_name = #{tableName} \n" +
|
||||
"FROM \n" +
|
||||
" information_schema.columns \n" +
|
||||
"WHERE \n" +
|
||||
" table_name = #{tableName} \n" +
|
||||
" AND column_name = #{columnName} \n" +
|
||||
" AND table_schema = (SELECT database()) ORDER BY ordinal_position")
|
||||
" AND table_schema = (SELECT database())")
|
||||
Map<String, Object> getTableColumnByName(
|
||||
@Param("tableName") String tableName, @Param("columnName") String columnName);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -129,7 +127,6 @@ public class OnlineDblinkServiceImpl extends BaseService<OnlineDblink, Long> imp
|
||||
}
|
||||
|
||||
/**
|
||||
* X
|
||||
* 获取指定DBLink下,指定表名的数据表对象,及其关联字段列表。
|
||||
*
|
||||
* @param dblink 数据库链接对象。
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.orangeforms.common.core.annotation.MyDataSourceResolver;
|
||||
import com.orangeforms.common.core.config.CoreProperties;
|
||||
import com.orangeforms.common.core.constant.AggregationType;
|
||||
import com.orangeforms.common.core.exception.NoDataPermException;
|
||||
import com.orangeforms.common.core.constant.GlobalDeletedFlag;
|
||||
@@ -16,6 +17,7 @@ import com.orangeforms.common.core.object.Tuple2;
|
||||
import com.orangeforms.common.core.util.RedisKeyUtil;
|
||||
import com.orangeforms.common.datafilter.constant.DataPermRuleType;
|
||||
import com.orangeforms.common.datafilter.config.DataFilterProperties;
|
||||
import com.orangeforms.common.online.config.OnlineProperties;
|
||||
import com.orangeforms.common.online.model.constant.*;
|
||||
import com.orangeforms.common.online.service.OnlineVirtualColumnService;
|
||||
import com.orangeforms.common.online.util.OnlineOperationHelper;
|
||||
@@ -68,6 +70,8 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private DataFilterProperties dataFilterProperties;
|
||||
@Autowired
|
||||
private OnlineProperties onlineProperties;
|
||||
|
||||
/**
|
||||
* 聚合返回数据中,聚合键的常量字段名。
|
||||
@@ -108,7 +112,7 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
List<ColumnData> columnDataList,
|
||||
Map<OnlineDatasourceRelation, List<List<ColumnData>>> slaveDataListMap) {
|
||||
Object id = this.saveNew(masterTable, columnDataList);
|
||||
// 迭代多个一对多关联。
|
||||
// 迭代多个关联列表。
|
||||
for (Map.Entry<OnlineDatasourceRelation, List<List<ColumnData>>> entry : slaveDataListMap.entrySet()) {
|
||||
Long masterColumnId = entry.getKey().getMasterColumnId();
|
||||
ColumnData masterColumnData = null;
|
||||
@@ -119,9 +123,9 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
}
|
||||
}
|
||||
Long slaveColumnId = entry.getKey().getSlaveColumnId();
|
||||
// 迭代一对多关联中的数据集合
|
||||
// 迭代关联中的数据集合
|
||||
for (List<ColumnData> slaveColumnDataList : entry.getValue()) {
|
||||
// 迭代一对多关联记录的字段列表。
|
||||
// 迭代关联记录的字段列表。
|
||||
for (ColumnData slaveColumnData : slaveColumnDataList) {
|
||||
if (slaveColumnData.getColumn().getColumnId().equals(slaveColumnId)) {
|
||||
slaveColumnData.setColumnValue(masterColumnData.getColumnValue());
|
||||
@@ -642,6 +646,10 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
|
||||
private String makeSelectFields(OnlineTable slaveTable, String relationVariableName) {
|
||||
StringBuilder selectFieldBuider = new StringBuilder(512);
|
||||
String intString = "SIGNED";
|
||||
if (onlineProperties.getDatabaseType().equals(CoreProperties.POSTGRESQL_TYPE)) {
|
||||
intString = "INT8";
|
||||
}
|
||||
// 拼装主表的select fields字段。
|
||||
for (OnlineColumn column : slaveTable.getColumnMap().values()) {
|
||||
OnlineColumn deletedColumn = slaveTable.getLogicDeleteColumn();
|
||||
@@ -654,7 +662,20 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
.append(slaveTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS SIGNED) ")
|
||||
.append(" AS ")
|
||||
.append(intString)
|
||||
.append(") ")
|
||||
.append(relationVariableName)
|
||||
.append(OnlineConstant.RELATION_TABLE_COLUMN_SEPARATOR)
|
||||
.append(column.getColumnName())
|
||||
.append(",");
|
||||
} else if ("date".equals(column.getColumnType())) {
|
||||
selectFieldBuider
|
||||
.append("CAST(")
|
||||
.append(slaveTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS CHAR(10)) ")
|
||||
.append(relationVariableName)
|
||||
.append(OnlineConstant.RELATION_TABLE_COLUMN_SEPARATOR)
|
||||
.append(column.getColumnName())
|
||||
@@ -676,6 +697,10 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
|
||||
private String makeSelectFields(OnlineTable masterTable, List<OnlineDatasourceRelation> relationList) {
|
||||
StringBuilder selectFieldBuider = new StringBuilder(512);
|
||||
String intString = "SIGNED";
|
||||
if (onlineProperties.getDatabaseType().equals(CoreProperties.POSTGRESQL_TYPE)) {
|
||||
intString = "INT8";
|
||||
}
|
||||
if (CollUtil.isNotEmpty(relationList)) {
|
||||
for (OnlineDatasourceRelation relation : relationList) {
|
||||
OnlineTable slaveTable = relation.getSlaveTable();
|
||||
@@ -691,7 +716,20 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
.append(slaveTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS SIGNED) ")
|
||||
.append(" AS ")
|
||||
.append(intString)
|
||||
.append(") ")
|
||||
.append(relation.getVariableName())
|
||||
.append(OnlineConstant.RELATION_TABLE_COLUMN_SEPARATOR)
|
||||
.append(column.getColumnName())
|
||||
.append(",");
|
||||
} else if ("date".equals(column.getColumnType())) {
|
||||
selectFieldBuider
|
||||
.append("CAST(")
|
||||
.append(slaveTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS CHAR(10)) ")
|
||||
.append(relation.getVariableName())
|
||||
.append(OnlineConstant.RELATION_TABLE_COLUMN_SEPARATOR)
|
||||
.append(column.getColumnName())
|
||||
@@ -722,7 +760,18 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
|
||||
.append(masterTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS SIGNED) ")
|
||||
.append(" AS ")
|
||||
.append(intString)
|
||||
.append(") ")
|
||||
.append(column.getColumnName())
|
||||
.append(",");
|
||||
} else if ("date".equals(column.getColumnType())) {
|
||||
selectFieldBuider
|
||||
.append("CAST(")
|
||||
.append(masterTable.getTableName())
|
||||
.append(".")
|
||||
.append(column.getColumnName())
|
||||
.append(" AS CHAR(10)) ")
|
||||
.append(column.getColumnName())
|
||||
.append(",");
|
||||
} else {
|
||||
|
||||
@@ -213,9 +213,19 @@ public class OnlineOperationHelper {
|
||||
List<List<ColumnData>> relationDataList = new LinkedList<>();
|
||||
relationDataMap.put(relation, relationDataList);
|
||||
OnlineTable slaveTable = relation.getSlaveTable();
|
||||
JSONArray slaveObjectArray = slaveData.getJSONArray(key);
|
||||
for (int i = 0; i < slaveObjectArray.size(); i++) {
|
||||
JSONObject slaveObject = slaveObjectArray.getJSONObject(i);
|
||||
if (relation.getRelationType().equals(RelationType.ONE_TO_MANY)) {
|
||||
JSONArray slaveObjectArray = slaveData.getJSONArray(key);
|
||||
for (int i = 0; i < slaveObjectArray.size(); i++) {
|
||||
JSONObject slaveObject = slaveObjectArray.getJSONObject(i);
|
||||
ResponseResult<List<ColumnData>> slaveColumnDataListResult =
|
||||
this.buildTableData(slaveTable, slaveObject, false, relation.getSlaveColumnId());
|
||||
if (!slaveColumnDataListResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(slaveColumnDataListResult);
|
||||
}
|
||||
relationDataList.add(slaveColumnDataListResult.getData());
|
||||
}
|
||||
} else if (relation.getRelationType().equals(RelationType.ONE_TO_ONE)) {
|
||||
JSONObject slaveObject = slaveData.getJSONObject(key);
|
||||
ResponseResult<List<ColumnData>> slaveColumnDataListResult =
|
||||
this.buildTableData(slaveTable, slaveObject, false, relation.getSlaveColumnId());
|
||||
if (!slaveColumnDataListResult.isSuccess()) {
|
||||
|
||||
Reference in New Issue
Block a user