|
@@ -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.boman.common.core.constant.GenConstants;
|
|
|
import com.boman.common.core.utils.DateUtils;
|
|
|
import com.boman.common.core.utils.SecurityUtils;
|
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
@@ -18,6 +19,7 @@ import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
import com.boman.gen.domain.GenTableRelation;
|
|
|
import com.boman.system.api.RemoteDictDataService;
|
|
|
+import com.boman.system.api.domain.SysFile;
|
|
|
import com.boman.web.core.constant.FormDataConstant;
|
|
|
import com.boman.web.core.constant.MaskConstant;
|
|
|
import com.boman.web.core.constant.SubmitConstant;
|
|
@@ -241,6 +243,9 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
// 拿到所有有fk的列
|
|
|
List<GenTableColumn> fkColumns = filter(columns, col -> ObjectUtils.isNotEmpty(col.getForeignKey()));
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(fkColumns)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
for (GenTableColumn column : fkColumns) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
@@ -288,13 +293,44 @@ public class TableServiceCmdService {
|
|
|
|
|
|
for (JSONObject jsonObject : result) {
|
|
|
for (GenTableColumn column : columns) {
|
|
|
- if (jsonObject.containsKey(column.getColumnName()) && DATETIME.equalsIgnoreCase(column.getColumnType())) {
|
|
|
+ if (jsonObject.containsKey(column.getColumnName()) && NEED_CONVERT_DATE_LIST.contains(column.getColumnType())) {
|
|
|
getStrByTimeStamp(jsonObject, column.getColumnName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 处理附件,把数据拿出来转换成name、url形式
|
|
|
+ *
|
|
|
+ * @param result 被转的数据
|
|
|
+ */
|
|
|
+ private void handlerAnnex(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (JSONObject jsonObject : result) {
|
|
|
+ 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(2);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 功能描述: 把返回值中含有字典值的转为可视化的心事
|
|
|
*
|
|
@@ -357,7 +393,7 @@ public class TableServiceCmdService {
|
|
|
|
|
|
// 默认查所有字段,不支持自定义
|
|
|
JSONObject json = selectService.selectById(tableName, pkName, id);
|
|
|
-
|
|
|
+ requireNonNull(json, "id 为[" + id + "]的数据不存在, 表名为[" + tableName + "]");
|
|
|
List<GenTableColumn> parentColumns = filter(columns, col -> HR.equalsIgnoreCase(col.getHtmlType()));
|
|
|
// 处理成hr的形式
|
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
@@ -369,6 +405,11 @@ public class TableServiceCmdService {
|
|
|
handlerSysDictData(Collections.singletonList(json), Collections.singletonList(column));
|
|
|
handlerDate(Collections.singletonList(json), Collections.singletonList(column));
|
|
|
handlerForeignKey(Collections.singletonList(json), Collections.singletonList(column));
|
|
|
+ if (GenConstants.HTML_IMAGE_UPLOAD.equalsIgnoreCase(column.getHtmlType())
|
|
|
+ || GenConstants.HTML_FILE_UPLOAD.equalsIgnoreCase(column.getHtmlType()) ) {
|
|
|
+ handlerAnnex(Collections.singletonList(json), Collections.singletonList(column));
|
|
|
+ }
|
|
|
+
|
|
|
column.setColumnValue(json.get(column.getColumnName()));
|
|
|
}
|
|
|
|
|
@@ -773,6 +814,7 @@ public class TableServiceCmdService {
|
|
|
|
|
|
public AjaxResult getByTableName(String tableName, List<GenTableColumn> allColumns) {
|
|
|
List<GenTableColumn> parentColumns = filter(allColumns, col -> HR.equalsIgnoreCase(col.getHtmlType()));
|
|
|
+ allColumns = filterData(allColumns, 0, MaskConstant.LIST_VISIBLE::equals);
|
|
|
|
|
|
// 把孩子放入父亲的怀抱
|
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
@@ -789,6 +831,7 @@ public class TableServiceCmdService {
|
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
|
packDictDataToColumns(hrColumn.getHrChildren(), ObjectUtils::isNotEmpty);
|
|
|
}
|
|
|
+
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put(BUTTON_LIST, getButton(tableName));
|
|
|
result.put(SHOW_DATA, parentColumns);
|
|
@@ -796,7 +839,9 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
|
|
|
public void packDictDataToColumns(List<GenTableColumn> columns, Predicate<String> predicate) {
|
|
|
- requireNonNull(columns, "columns 为空");
|
|
|
+ if (isEmpty(columns)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
for (GenTableColumn column : columns) {
|
|
|
String dictType = column.getDictType();
|
|
|
if (predicate.test(dictType)) {
|