|
@@ -27,10 +27,10 @@ import com.boman.web.core.service.save.IBaseSaveService;
|
|
import com.boman.web.core.service.select.IBaseSelectService;
|
|
import com.boman.web.core.service.select.IBaseSelectService;
|
|
import com.boman.web.core.service.submit.IBaseSubmitService;
|
|
import com.boman.web.core.service.submit.IBaseSubmitService;
|
|
import com.boman.web.core.service.update.IBaseUpdateService;
|
|
import com.boman.web.core.service.update.IBaseUpdateService;
|
|
-import com.boman.web.core.utils.ColumnUtils;
|
|
|
|
import com.boman.web.core.utils.IdUtils;
|
|
import com.boman.web.core.utils.IdUtils;
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -245,11 +245,13 @@ public class TableServiceCmdService {
|
|
List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
, showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
, showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
// 处理时间
|
|
// 处理时间
|
|
- handlerDate(result, columns);
|
|
|
|
|
|
+// handlerDate(result, columns);
|
|
// 处理字典值
|
|
// 处理字典值
|
|
- handlerSysDictData(result, columns);
|
|
|
|
|
|
+// handlerSysDictData(result, columns);
|
|
// 处理外键
|
|
// 处理外键
|
|
- handlerForeignKey(result, columns);
|
|
|
|
|
|
+// handlerForeignKey(result, columns);
|
|
|
|
+
|
|
|
|
+ handler(result, columns);
|
|
// 定制接口
|
|
// 定制接口
|
|
result = isCustomized(dto.getTable(),result,"trigger_retrieve");
|
|
result = isCustomized(dto.getTable(),result,"trigger_retrieve");
|
|
|
|
|
|
@@ -257,41 +259,64 @@ public class TableServiceCmdService {
|
|
return AjaxResult.success(rows);
|
|
return AjaxResult.success(rows);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void handler(List<JSONObject> result, List<GenTableColumn> columns){
|
|
|
|
+ // 处理时间
|
|
|
|
+ handlerDate(result, columns);
|
|
|
|
+ // 处理字典值
|
|
|
|
+ handlerSysDictData(result, columns);
|
|
|
|
+ // 处理外键
|
|
|
|
+ handlerForeignKey(result, columns);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 处理外键
|
|
|
|
+ *
|
|
|
|
+ * @param result result
|
|
|
|
+ * @param columns 该表对应的所有的列
|
|
|
|
+ */
|
|
private void handlerForeignKey(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
private void handlerForeignKey(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
// 拿到所有有fk的列
|
|
// 拿到所有有fk的列
|
|
- columns = filter(columns, col -> ObjectUtils.isNotEmpty(col.getForeignKey()));
|
|
|
|
- for (GenTableColumn column : columns) {
|
|
|
|
|
|
+ List<GenTableColumn> fkColumns = filter(columns, col -> ObjectUtils.isNotEmpty(col.getForeignKey()));
|
|
|
|
+
|
|
|
|
+ for (GenTableColumn column : fkColumns) {
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
-// Long selfTableId = column.getTableId();
|
|
|
|
String selfColumnName = column.getColumnName();
|
|
String selfColumnName = column.getColumnName();
|
|
for (JSONObject json : result) {
|
|
for (JSONObject json : result) {
|
|
- if (json.containsKey(selfColumnName)) {
|
|
|
|
- Object value = json.get(selfColumnName);
|
|
|
|
-
|
|
|
|
|
|
+ if (json.containsKey(selfColumnName.toUpperCase()) || json.containsKey(selfColumnName.toLowerCase())) {
|
|
|
|
+ // 外键在table_column中的id
|
|
Long fkColumnId = Long.parseLong(column.getForeignKey());
|
|
Long fkColumnId = Long.parseLong(column.getForeignKey());
|
|
GenTableColumn fkTableColumn = remoteGenTableColumnService.getById(fkColumnId);
|
|
GenTableColumn fkTableColumn = remoteGenTableColumnService.getById(fkColumnId);
|
|
|
|
+ String fkColumnName = fkTableColumn.getColumnName();
|
|
Long fkTableId = fkTableColumn.getTableId();
|
|
Long fkTableId = fkTableColumn.getTableId();
|
|
GenTable fkGenTable = remoteGenTableService.getByTableId(fkTableId);
|
|
GenTable fkGenTable = remoteGenTableService.getByTableId(fkTableId);
|
|
- String fkTableName= fkGenTable.getTableName();
|
|
|
|
-
|
|
|
|
- // select * from fkTableName where fkTableColumn.columnName = value;
|
|
|
|
-
|
|
|
|
-// jsonObject.put(columnName, "");
|
|
|
|
-// jsonObject.put("columnName", "");
|
|
|
|
-
|
|
|
|
|
|
+ // 显示键 table_column 表的id
|
|
|
|
+ Long dkColumnId = fkGenTable.getDkColumn();
|
|
|
|
+ GenTableColumn dkTableColumn = remoteGenTableColumnService.getById(dkColumnId);
|
|
|
|
+ String dkColumnName = dkTableColumn.getColumnName();
|
|
|
|
+ String fkTableName = fkGenTable.getTableName();
|
|
|
|
+ Object primaryTableFKvalue = json.get(selfColumnName);
|
|
|
|
+ // "DEPT_ID": {"value": 104, "name": "开发部"}
|
|
|
|
+ Map<String, Object> param = Maps.newHashMap();
|
|
|
|
+ param.put(fkColumnName, primaryTableFKvalue);
|
|
|
|
+ List<JSONObject> fkList = selectService.selectByMap(fkTableName, param);
|
|
|
|
+
|
|
|
|
+ for (JSONObject object : fkList) {
|
|
|
|
+ Object value = object.get(dkColumnName);
|
|
|
|
+ jsonObject.put(SINGLE_OBJ_NAME, primaryTableFKvalue);
|
|
|
|
+ jsonObject.put(SINGLE_OBJ_VALUE, value);
|
|
|
|
+ json.put(selfColumnName.toLowerCase(), jsonObject);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 功能描述: 把timeStamp转为string
|
|
|
|
|
|
+ * 功能描述: 把timeStamp转为string, 默认类型为:YYYY_MM_DD
|
|
*
|
|
*
|
|
* @param result 被转的数据
|
|
* @param result 被转的数据
|
|
*/
|
|
*/
|
|
@@ -353,21 +378,28 @@ public class TableServiceCmdService {
|
|
public AjaxResult getObject(BaseTableSaveDTO dto) {
|
|
public AjaxResult getObject(BaseTableSaveDTO dto) {
|
|
requireNonNull(dto.getTable());
|
|
requireNonNull(dto.getTable());
|
|
|
|
|
|
- // 拿到每个字段对应的查询类型,=、 like、 >、 <
|
|
|
|
- // 拿到pkName
|
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
-
|
|
|
|
JSONObject fixedData = dto.getFixedData();
|
|
JSONObject fixedData = dto.getFixedData();
|
|
fixedData = ifNullSetEmpty(fixedData);
|
|
fixedData = ifNullSetEmpty(fixedData);
|
|
Long id = fixedData.getLong(FormDataConstant.ID);
|
|
Long id = fixedData.getLong(FormDataConstant.ID);
|
|
requireNonNull(id);
|
|
requireNonNull(id);
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
|
+ // id = -1时,查询该表单对应的字段名称
|
|
|
|
+ if (ltZero(id)) {
|
|
|
|
+ return getByTableName(genTable.getTableName(), columns);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 默认查所有字段,不支持自定义
|
|
// 默认查所有字段,不支持自定义
|
|
- JSONObject jsonObject = selectService.selectById(genTable.getTableName(), pkName, id);
|
|
|
|
|
|
+ JSONObject json = selectService.selectById(genTable.getTableName(), pkName, id);
|
|
// name=username, value=zhangsan, type=input, types=[{},{}]
|
|
// name=username, value=zhangsan, type=input, types=[{},{}]
|
|
- handlerDate(Collections.singletonList(jsonObject), columns);
|
|
|
|
- List<JSONObject> result = packSingleObj(jsonObject, columns);
|
|
|
|
|
|
+
|
|
|
|
+ handler(Collections.singletonList(json), columns);
|
|
|
|
+
|
|
|
|
+ List<JSONObject> list = packSingleObj(json, columns);
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ result.put(SHOW_DATA, list);
|
|
|
|
+ result.put(BUTTON_LIST, getButton(genTable.getTableName()));
|
|
return AjaxResult.success(result);
|
|
return AjaxResult.success(result);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -529,9 +561,9 @@ public class TableServiceCmdService {
|
|
* @param condition condition
|
|
* @param condition condition
|
|
* @return com.boman.common.core.web.domain.AjaxResult
|
|
* @return com.boman.common.core.web.domain.AjaxResult
|
|
*/
|
|
*/
|
|
- public AjaxResult getButton(BaseTableSaveDTO condition) {
|
|
|
|
- GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
|
- return AjaxResult.success("成功", Strings.nullToEmpty(genTable.getMenuRole()));
|
|
|
|
|
|
+ public String getButton(String tableName) {
|
|
|
|
+ GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
|
|
|
|
+ return Strings.nullToEmpty(genTable.getMenuRole());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -713,6 +745,7 @@ public class TableServiceCmdService {
|
|
* @return com.boman.gen.domain.GenTable
|
|
* @return com.boman.gen.domain.GenTable
|
|
*/
|
|
*/
|
|
private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
|
|
private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
|
|
|
|
+ tableName = tableName.trim().toLowerCase();
|
|
String key = requireNonNull(redisKeyPrefix) + requireNonNull(tableName);
|
|
String key = requireNonNull(redisKeyPrefix) + requireNonNull(tableName);
|
|
GenTable genTable = redisService.getCacheObject(key);
|
|
GenTable genTable = redisService.getCacheObject(key);
|
|
if (ObjectUtils.isEmpty(genTable)) {
|
|
if (ObjectUtils.isEmpty(genTable)) {
|
|
@@ -748,11 +781,11 @@ public class TableServiceCmdService {
|
|
return AjaxResult.success(genTable);
|
|
return AjaxResult.success(genTable);
|
|
} else {
|
|
} else {
|
|
// 带折叠的展示
|
|
// 带折叠的展示
|
|
- return getByTableName(allColumns);
|
|
|
|
|
|
+ return getByTableName(genTable.getTableName(), allColumns);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public AjaxResult getByTableName( List<GenTableColumn> allColumns) {
|
|
|
|
|
|
+ public AjaxResult getByTableName(String tableName, List<GenTableColumn> allColumns) {
|
|
List<GenTableColumn> parentColumns = filter(allColumns, col -> HR.equalsIgnoreCase(col.getHtmlType()));
|
|
List<GenTableColumn> parentColumns = filter(allColumns, col -> HR.equalsIgnoreCase(col.getHtmlType()));
|
|
|
|
|
|
// 把孩子放入父亲的怀抱
|
|
// 把孩子放入父亲的怀抱
|
|
@@ -770,8 +803,10 @@ public class TableServiceCmdService {
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
packDictDataToColumns(hrColumn.getHrChildren(), ObjectUtils::isNotEmpty);
|
|
packDictDataToColumns(hrColumn.getHrChildren(), ObjectUtils::isNotEmpty);
|
|
}
|
|
}
|
|
-
|
|
|
|
- return AjaxResult.success(parentColumns);
|
|
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ result.put(BUTTON_LIST, getButton(tableName));
|
|
|
|
+ result.put(SHOW_DATA, parentColumns);
|
|
|
|
+ return AjaxResult.success(result);
|
|
}
|
|
}
|
|
|
|
|
|
public void packDictDataToColumns(List<GenTableColumn> columns, Predicate<String> predicate) {
|
|
public void packDictDataToColumns(List<GenTableColumn> columns, Predicate<String> predicate) {
|