|
@@ -3,6 +3,7 @@ package com.boman.web.core.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.boman.common.core.constant.GenConstants;
|
|
|
import com.boman.common.core.utils.DateUtils;
|
|
|
import com.boman.common.core.utils.SecurityUtils;
|
|
@@ -33,7 +34,6 @@ import com.boman.web.core.service.update.IBaseUpdateService;
|
|
|
import com.boman.web.core.utils.IdUtils;
|
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -45,12 +45,10 @@ import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Predicate;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
import static com.boman.web.core.constant.FormDataConstant.*;
|
|
|
import static com.boman.web.core.utils.ColumnUtils.*;
|
|
|
-import static com.boman.web.core.utils.ColumnUtils.handlerBlobWithJSONObject;
|
|
|
|
|
|
/**
|
|
|
* @author shiqian
|
|
@@ -196,21 +194,21 @@ public class TableServiceCmdService {
|
|
|
public AjaxResult queryList(FormDataDto dto) {
|
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
|
|
|
|
- // 拿到每个字段对应的查询类型,=、 like、 >、 <
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
- JSONObject fixedData = dto.getFixedData();
|
|
|
- fixedData = ifNullSetEmpty(fixedData);
|
|
|
+ JSONObject fixedData = ifNullSetEmpty(dto.getFixedData());
|
|
|
+ List<GenTableColumn> columns = genTable.getColumns();
|
|
|
|
|
|
// 查询条件
|
|
|
JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
|
- checkColumn(condition, genTable.getColumns());
|
|
|
- List<GenTableColumn> columns = genTable.getColumns();
|
|
|
+ // 检查列
|
|
|
+ checkColumn(condition, columns);
|
|
|
// 封装好以后的查询条件
|
|
|
JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
|
|
|
- JSONArray jsonArray = fixedData.getJSONArray(SHOW_DATA);
|
|
|
- checkColumn(jsonArray, genTable.getColumns());
|
|
|
+ JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
|
|
|
+ // 检查列
|
|
|
+ checkColumn(showData, genTable.getColumns());
|
|
|
// 需要返回到前台的列, 需要判断是否是列表展示, 4为判断列表是否可见
|
|
|
- JSONArray showData = filterData(columns, 4, jsonArray, MaskConstant.LIST_VISIBLE::equals);
|
|
|
+ showData = filterData(columns, 4, showData, MaskConstant.LIST_VISIBLE::equals);
|
|
|
|
|
|
JSONObject rows = new JSONObject();
|
|
|
int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
|
|
@@ -223,7 +221,9 @@ public class TableServiceCmdService {
|
|
|
|
|
|
List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
|
, showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
|
+ // 处理blob
|
|
|
handlerBlobWithJSONObject(genTable.getIsContainsBlob(), result);
|
|
|
+ // 处理日期、外键、字典值
|
|
|
handler(result = filter(result, ObjectUtils::isNotEmpty), columns);
|
|
|
// 定制接口
|
|
|
result = isCustomized(dto.getTable(),result,"trigger_retrieve");
|
|
@@ -304,7 +304,10 @@ public class TableServiceCmdService {
|
|
|
for (JSONObject jsonObject : result) {
|
|
|
for (GenTableColumn column : columns) {
|
|
|
if (jsonObject.containsKey(column.getColumnName()) && NEED_CONVERT_DATE_LIST.contains(column.getColumnType())) {
|
|
|
- getStrByTimeStamp(jsonObject, column.getColumnName());
|
|
|
+ Date date = jsonObject.getTimestamp(column.getColumnName());
|
|
|
+ if (null != date) {
|
|
|
+ jsonObject.put(column.getColumnName(), DateUtils.dateTime(date));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -325,17 +328,8 @@ public class TableServiceCmdService {
|
|
|
for (GenTableColumn column : columns) {
|
|
|
if (jsonObject.containsKey(column.getColumnName())) {
|
|
|
String value = jsonObject.getString(column.getColumnName());
|
|
|
- JSONArray fileList = JSON.parseArray(value);
|
|
|
- ArrayList<SysFile> files = Lists.newArrayListWithCapacity(fileList.size());
|
|
|
- for (Object obj : fileList) {
|
|
|
- JSONObject fileItem = (JSONObject) obj;
|
|
|
- SysFile file = new SysFile();
|
|
|
- file.setName(fileItem.getString(SINGLE_OBJ_NAME));
|
|
|
- file.setUrl(fileItem.getString(URL));
|
|
|
- files.add(file);
|
|
|
- }
|
|
|
-
|
|
|
- jsonObject.put(column.getColumnName(), files);
|
|
|
+ List<SysFile> fileList = JSON.parseObject(value, new TypeReference<List<SysFile>>(){}.getType());
|
|
|
+ jsonObject.put(column.getColumnName(), fileList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -367,20 +361,6 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 把jsonObject中时间类型转为string,再放到jsonObject中,类型为: yyyy-mm-dd
|
|
|
- *
|
|
|
- * @param jsonObject jsonObject
|
|
|
- * @param columnType create_time update_time...
|
|
|
- */
|
|
|
- private void getStrByTimeStamp(JSONObject jsonObject, String columnType) {
|
|
|
- Date date = jsonObject.getTimestamp(columnType);
|
|
|
- if (null != date) {
|
|
|
- jsonObject.put(columnType, DateUtils.dateTime(date));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 获取单表单数据
|
|
|
*
|
|
@@ -389,14 +369,11 @@ public class TableServiceCmdService {
|
|
|
*/
|
|
|
public AjaxResult getObject(FormDataDto dto) {
|
|
|
String tableName = requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
|
-
|
|
|
- GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
|
|
|
- String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
- JSONObject fixedData = dto.getFixedData();
|
|
|
- Long id = fixedData.getLong(FormDataConstant.ID);
|
|
|
- requireNonNull(id, "如果是回显,则传参为此行记录的id, 如为新增,则传-1,传null可不行");
|
|
|
Boolean isUi = requireNonNull(dto.getIsUi(), "未传isUi这个参数");
|
|
|
+ Long id = dto.getFixedData().getLong(FormDataConstant.ID);
|
|
|
+ requireNonNull(id, "如果是回显,则传参为此行记录的id, 如为新增,则传-1,传null可不行");
|
|
|
|
|
|
+ GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
|
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
// id = -1时,查询该表单对应的字段名称
|
|
|
if (ltZero(id)) {
|
|
@@ -404,8 +381,10 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
|
|
|
// 默认查所有字段,不支持自定义
|
|
|
+ String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
JSONObject json = selectService.selectById(tableName, pkName, id);
|
|
|
requireNonNull(json, "id 为[" + id + "]的数据不存在, 表名为[" + tableName + "]");
|
|
|
+ // 处理blob
|
|
|
handlerBlobWithJSONObject(genTable.getIsContainsBlob(), Collections.singletonList(json));
|
|
|
List<GenTableColumn> parentColumns = filterHrAndSort(columns);
|
|
|
|
|
@@ -434,51 +413,11 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
-// result.put(SHOW_DATA, packSingleObj(json, columns));
|
|
|
result.put(SHOW_DATA, parentColumns);
|
|
|
result.put(BUTTON_LIST, getButton(tableName));
|
|
|
return AjaxResult.success(result);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 单对象查询,封装成此类型返给前台:name=username, value=zhangsan, type=input, types=[{},{}]
|
|
|
- *
|
|
|
- * @param jsonObject 数据库查出的字段名称对应字段值
|
|
|
- * @param columns 该表对应的所有的字段的信息
|
|
|
- * @return java.util.List<com.alibaba.fastjson.JSONObject>
|
|
|
- */
|
|
|
- private List<JSONObject> packSingleObj(JSONObject jsonObject, List<GenTableColumn> columns) {
|
|
|
- if (MapUtils.isEmpty(jsonObject)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- List<JSONObject> result = Lists.newArrayListWithCapacity(jsonObject.size());
|
|
|
-
|
|
|
- for (GenTableColumn column : columns) {
|
|
|
- JSONObject map = new JSONObject();
|
|
|
- for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
|
|
|
- if (column.getColumnName().equalsIgnoreCase(entry.getKey())) {
|
|
|
- map.put(SINGLE_OBJ_NAME, column.getColumnName());
|
|
|
- map.put(SINGLE_OBJ_VALUE, entry.getValue());
|
|
|
- String htmlType = column.getHtmlType();
|
|
|
- map.put(SINGLE_OBJ_TYPE, htmlType);
|
|
|
- if (NEED_QUERY_DICT_LIST.contains(htmlType)) {
|
|
|
- String dictType = column.getDictType();
|
|
|
- try {
|
|
|
- map.put(SINGLE_OBJ_TYPES, remoteDictDataService.listByType(dictType));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- result.add(map);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 封装成查询条件 key: 列名, value:查询条件_查询类别
|
|
|
* eg: [{"config_name": ["系统配置", "EQ", "varchar(100)"]}]
|
|
@@ -544,7 +483,7 @@ public class TableServiceCmdService {
|
|
|
// genTable.getMenuRole() 暂时数据库没有数据,
|
|
|
jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
|
|
|
|
|
|
- jsonObject.put(ViewConst.VIEW_TYPE, genTable.getTplCategory());
|
|
|
+ jsonObject.put(ViewConst.VIEW_TYPE, Strings.nullToEmpty(genTable.getTplCategory()));
|
|
|
return AjaxResult.success(jsonObject);
|
|
|
}
|
|
|
|
|
@@ -578,23 +517,6 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(queryList);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 获取表单表头
|
|
|
- * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
|
- * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
|
|
|
- *
|
|
|
- * eg:{
|
|
|
- * "table": "sys_config"
|
|
|
- * }
|
|
|
- *
|
|
|
- * @param condition condition
|
|
|
- * @return com.boman.common.core.web.domain.AjaxResult
|
|
|
- */
|
|
|
- public AjaxResult getTableHead(FormDataDto condition) {
|
|
|
- GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
- return AjaxResult.success(getTableHeadList(genTable));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 单独获取按钮
|
|
|
* 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
@@ -638,27 +560,6 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
- public String getChildColumnNameByParentTableName(GenTable parentGenTable, Long childTableTableId){
|
|
|
- requireNonNull(parentGenTable.getTableName(), "主表名称为空");
|
|
|
-// GenTable primaryTable = redisService.getCacheObject(RedisKey.TABLE_INFO + genTable.getTableName());
|
|
|
- Long parentTableId = parentGenTable.getTableId();
|
|
|
- List<GenTableRelation> relations = redisService.getCacheObject(RedisKey.RELATION_INFO);
|
|
|
- relations = relations.stream()
|
|
|
- .filter(relation -> relation.getRelationParentId().equals(parentTableId))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- for (GenTableRelation relation : relations) {
|
|
|
- if (relation.getRelationChildId().equals(6L)) {
|
|
|
- // tableColumnService.selectGenTableColumnListByTableId(childTableTableId);
|
|
|
-// return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return "";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 表单提交接口
|
|
|
*
|
|
@@ -675,12 +576,9 @@ public class TableServiceCmdService {
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
// 先去查出之前的状态
|
|
|
- List<Long> idList = commitData.stream().map(jsonObject -> jsonObject.getLong(FormDataConstant.ID))
|
|
|
- .collect(Collectors.toList());
|
|
|
- JSONArray showData = new JSONArray();
|
|
|
- showData.add(FormDataConstant.STATUS);
|
|
|
- showData.add(pkName);
|
|
|
- List<JSONObject> beforeList = selectService.selectByIdList(tableName, pkName, idList, showData);
|
|
|
+ List<Long> idList = map(commitData, jsonObject -> jsonObject.getLong(FormDataConstant.ID));
|
|
|
+
|
|
|
+ List<JSONObject> beforeList = selectService.selectByIdList(tableName, pkName, idList, Lists.newArrayList(pkName, STATUS));
|
|
|
requireNonNull(beforeList);
|
|
|
|
|
|
for (JSONObject commitDatum : commitData) {
|
|
@@ -800,32 +698,13 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 功能描述: 根据表名获取表信息、表字段和表字段对应的字典值
|
|
|
- * {
|
|
|
- * "table": "sys_config",
|
|
|
- * }
|
|
|
+ * 功能描述: 根据表名封装列的对应关系, 同时封装好字典值
|
|
|
*
|
|
|
- *
|
|
|
- * @param condition condition
|
|
|
+ * @param tableName tableName
|
|
|
+ * @param allColumns allColumns
|
|
|
+ * @param isUi 带折叠true, 不带折叠false
|
|
|
* @return com.boman.common.core.web.domain.AjaxResult
|
|
|
*/
|
|
|
-// public AjaxResult getByTableName(BaseTableSaveDTO condition) {
|
|
|
-// requireNonNull(condition.getTable(), "tableName = [" + condition.getTable() + "] 此表不存在");
|
|
|
-// requireNonNull(condition.getIsUi(), "根据表名获取表字段,未传 isUi 这个字段");
|
|
|
-// GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
-// List<GenTableColumn> allColumns = genTable.getColumns();
|
|
|
-// // 把新增可见的列过滤出来
|
|
|
-//// List<GenTableColumn> returnData = ColumnUtils.filterNeedShowData(allColumns, 0, INSERT_VISIBLE::equals);
|
|
|
-// // 普通的展示,不带折叠的
|
|
|
-// if (BooleanUtils.isFalse(condition.getIsUi())) {
|
|
|
-// packDictDataToColumns(allColumns, ObjectUtils::isNotEmpty);
|
|
|
-// return AjaxResult.success(genTable);
|
|
|
-// } else {
|
|
|
-// // 带折叠的展示
|
|
|
-// return getByTableName(genTable.getTableName(), allColumns, true);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
public AjaxResult getByTableName(String tableName, List<GenTableColumn> allColumns, Boolean isUi) {
|
|
|
List<GenTableColumn> resultCols;
|
|
|
List<GenTableColumn> parentColumns = filterHrAndSort(allColumns);
|