|
@@ -3,9 +3,7 @@ package com.boman.web.core.service;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
import com.boman.common.core.constant.GenConstants;
|
|
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.SecurityUtils;
|
|
import com.boman.common.core.utils.array.ArrayUtils;
|
|
import com.boman.common.core.utils.array.ArrayUtils;
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
@@ -13,33 +11,19 @@ import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
import com.boman.common.redis.RedisKey;
|
|
import com.boman.common.redis.RedisKey;
|
|
import com.boman.common.redis.service.RedisService;
|
|
import com.boman.common.redis.service.RedisService;
|
|
-import com.boman.domain.GenTable;
|
|
|
|
-import com.boman.domain.GenTableColumn;
|
|
|
|
-import com.boman.domain.SysDictData;
|
|
|
|
-import com.boman.domain.SysRoleData;
|
|
|
|
import com.boman.domain.constant.*;
|
|
import com.boman.domain.constant.*;
|
|
-import com.boman.domain.exception.UnSuchFunctionException;
|
|
|
|
import com.boman.gen.api.RemoteGenTableColumnService;
|
|
import com.boman.gen.api.RemoteGenTableColumnService;
|
|
import com.boman.gen.api.RemoteGenTableService;
|
|
import com.boman.gen.api.RemoteGenTableService;
|
|
-import com.boman.system.api.RemoteDeptService;
|
|
|
|
|
|
+import com.boman.domain.GenTable;
|
|
|
|
+import com.boman.domain.GenTableColumn;
|
|
import com.boman.system.api.RemoteDictDataService;
|
|
import com.boman.system.api.RemoteDictDataService;
|
|
-import com.boman.system.api.RemoteRoleDataService;
|
|
|
|
-import com.boman.system.api.RemoteUserService;
|
|
|
|
-import com.boman.system.api.domain.SysFile;
|
|
|
|
-import com.boman.system.api.domain.SysMenu;
|
|
|
|
-import com.boman.system.api.domain.SysRole;
|
|
|
|
-import com.boman.system.api.domain.SysUser;
|
|
|
|
-import com.boman.system.api.model.LoginUser;
|
|
|
|
-import com.boman.web.core.domain.ActionType;
|
|
|
|
-import com.boman.web.core.domain.FormDataDto;
|
|
|
|
-import com.boman.web.core.domain.RowResult;
|
|
|
|
-import com.boman.web.core.domain.TableContext;
|
|
|
|
|
|
+import com.boman.domain.SysFile;
|
|
|
|
+import com.boman.web.core.domain.*;
|
|
import com.boman.web.core.service.delete.IBaseDeleteService;
|
|
import com.boman.web.core.service.delete.IBaseDeleteService;
|
|
import com.boman.web.core.service.save.IBaseSaveService;
|
|
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.AuthUtils;
|
|
|
|
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;
|
|
@@ -56,10 +40,13 @@ import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.function.Predicate;
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
|
|
+import static com.boman.common.core.constant.GenConstants.HTML_FILE_UPLOAD;
|
|
|
|
+import static com.boman.common.core.constant.GenConstants.HTML_IMAGE_UPLOAD;
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
import static com.boman.domain.constant.FormDataConstant.*;
|
|
import static com.boman.domain.constant.FormDataConstant.*;
|
|
-import static com.boman.web.core.utils.AuthUtils.*;
|
|
|
|
import static com.boman.web.core.utils.ColumnUtils.*;
|
|
import static com.boman.web.core.utils.ColumnUtils.*;
|
|
|
|
+import static com.boman.web.core.utils.HandlerFormDataUtils.*;
|
|
|
|
+import static com.boman.web.core.utils.JSONObjectUtils.containsKeyIgnoreCase;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author shiqian
|
|
* @author shiqian
|
|
@@ -84,27 +71,18 @@ public class TableServiceCmdService {
|
|
@Resource
|
|
@Resource
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
@Resource
|
|
@Resource
|
|
- private TableContext tableContext;
|
|
|
|
- @Resource
|
|
|
|
private RemoteDictDataService remoteDictDataService;
|
|
private RemoteDictDataService remoteDictDataService;
|
|
@Resource
|
|
@Resource
|
|
private RemoteGenTableService remoteGenTableService;
|
|
private RemoteGenTableService remoteGenTableService;
|
|
@Resource
|
|
@Resource
|
|
private RemoteGenTableColumnService remoteGenTableColumnService;
|
|
private RemoteGenTableColumnService remoteGenTableColumnService;
|
|
- @Resource
|
|
|
|
- private RemoteDeptService remoteDeptService;
|
|
|
|
- @Resource
|
|
|
|
- private RemoteRoleDataService remoteRoleDataService;
|
|
|
|
- @Resource
|
|
|
|
- private RemoteUserService remoteUserService;
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
|
public final AjaxResult objectSave(FormDataDto dto) {
|
|
public final AjaxResult objectSave(FormDataDto dto) {
|
|
AjaxResult result = AjaxResult.success();
|
|
AjaxResult result = AjaxResult.success();
|
|
|
|
|
|
- // 权限校验在此方法中
|
|
|
|
- TableContext context = tableContext.createContext(dto);
|
|
|
|
|
|
+ TableContext context = TableContext.createContext(dto);
|
|
// 拿到pkName和maxId
|
|
// 拿到pkName和maxId
|
|
String pkName = context.getPkName();
|
|
String pkName = context.getPkName();
|
|
JSONObject commitData = context.getCommitData();
|
|
JSONObject commitData = context.getCommitData();
|
|
@@ -117,7 +95,7 @@ public class TableServiceCmdService {
|
|
|
|
|
|
// 新增
|
|
// 新增
|
|
if (ActionType.INSERT.equals(context.getActionType())) {
|
|
if (ActionType.INSERT.equals(context.getActionType())) {
|
|
- Long maxId = IdUtils.getMaxId(dto.getTable(), pkName);
|
|
|
|
|
|
+ Integer maxId = IdUtils.getMaxId(dto.getTable(), pkName);
|
|
RowResult rowResult = saveService.insertRow(context, maxId);
|
|
RowResult rowResult = saveService.insertRow(context, maxId);
|
|
if (RowResult.checkSuccess(rowResult)) {
|
|
if (RowResult.checkSuccess(rowResult)) {
|
|
LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
@@ -177,34 +155,25 @@ public class TableServiceCmdService {
|
|
*/
|
|
*/
|
|
public AjaxResult objectDelete(FormDataDto dto) {
|
|
public AjaxResult objectDelete(FormDataDto dto) {
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
-
|
|
|
|
|
|
+ Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
|
+ requireNonNull(idArr);
|
|
|
|
+ // 拿到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());
|
|
|
|
|
|
- Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
|
- requireNonNull(idArr, "删除时,所传idList为空");
|
|
|
|
-
|
|
|
|
- RowResult rowResult;
|
|
|
|
List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
for (Long id : idArr) {
|
|
for (Long id : idArr) {
|
|
- // 校验权限
|
|
|
|
- if (BooleanUtils.isTrue(checkAuthObjectDelete(genTable, id, pkName))) {
|
|
|
|
- rowResult = deleteService.deleteById(dto.getTable(), pkName, id);
|
|
|
|
- if (rowResult.isOk()) {
|
|
|
|
- LOGGER.info("删除成功, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- LOGGER.info("删除失败, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
|
|
|
|
- } else {
|
|
|
|
- rowResult = RowResult.create(RowResult.FAIL, "无操作权限");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ RowResult rowResult = deleteService.deleteById(dto.getTable(), pkName, id);
|
|
result.add(rowResult);
|
|
result.add(rowResult);
|
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"));
|
|
|
|
+
|
|
return AjaxResult.success(result);
|
|
return AjaxResult.success(result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 功能描述: 通用删除接口 (真的删除)
|
|
* 功能描述: 通用删除接口 (真的删除)
|
|
*
|
|
*
|
|
@@ -223,22 +192,10 @@ public class TableServiceCmdService {
|
|
List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
-
|
|
|
|
- RowResult rowResult;
|
|
|
|
for (Long id : idArr) {
|
|
for (Long id : idArr) {
|
|
- // 校验权限
|
|
|
|
- if (BooleanUtils.isTrue(checkAuthObjectDelete(genTable, id, pkName))) {
|
|
|
|
- rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
|
|
|
|
- if (rowResult.isOk()) {
|
|
|
|
- LOGGER.info("逻辑删除成功, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- LOGGER.info("逻辑删除失败, tableName: {}, id: {}, 操作人: {}", tableContext.getTableName(), id, getLoginUser().getUsername());
|
|
|
|
- } else {
|
|
|
|
- rowResult = RowResult.create(RowResult.FAIL, "无操作权限");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ RowResult rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
|
|
result.add(rowResult);
|
|
result.add(rowResult);
|
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", id);
|
|
}
|
|
}
|
|
|
|
|
|
return AjaxResult.success(result);
|
|
return AjaxResult.success(result);
|
|
@@ -253,17 +210,16 @@ public class TableServiceCmdService {
|
|
public AjaxResult queryList(FormDataDto dto) {
|
|
public AjaxResult queryList(FormDataDto dto) {
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
|
+ String tableName = genTable.getTableName();
|
|
JSONObject fixedData = ifNullSetEmpty(dto.getFixedData());
|
|
JSONObject fixedData = ifNullSetEmpty(dto.getFixedData());
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
|
|
|
// 查询条件
|
|
// 查询条件
|
|
JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
- // 权限
|
|
|
|
- checkAuthQueryList(genTable, condition);
|
|
|
|
// 检查列
|
|
// 检查列
|
|
checkColumn(condition, columns);
|
|
checkColumn(condition, columns);
|
|
// 封装好以后的查询条件
|
|
// 封装好以后的查询条件
|
|
- JSONObject packCondition = ifNullSetEmpty(selectService.packColCondition(columns, condition));
|
|
|
|
|
|
+ JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
|
|
JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
|
|
JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
|
|
// 检查列
|
|
// 检查列
|
|
checkColumn(showData, genTable.getColumns());
|
|
checkColumn(showData, genTable.getColumns());
|
|
@@ -281,12 +237,14 @@ public class TableServiceCmdService {
|
|
return AjaxResult.success(rows);
|
|
return AjaxResult.success(rows);
|
|
}
|
|
}
|
|
|
|
|
|
- List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
|
|
- , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
|
|
|
|
+ List<JSONObject> result = selectService.selectByCondition(tableName, condition, packCondition, showData, dto);
|
|
|
|
+ result = filter(result, ObjectUtils::isNotEmpty);
|
|
// 处理blob
|
|
// 处理blob
|
|
- handlerBlobWithJSONObject(genTable.getIsContainsBlob(), result);
|
|
|
|
|
|
+ handleBlob(result, genTable.getIsContainsBlob());
|
|
// 处理日期、外键、字典值
|
|
// 处理日期、外键、字典值
|
|
- handler(result = filter(result, ObjectUtils::isNotEmpty), columns);
|
|
|
|
|
|
+ handleDictForQueryList(result, columns);
|
|
|
|
+ handleDateTimeForQueryList(result, columns);
|
|
|
|
+ handleFkForQueryList(result, columns);
|
|
// 定制接口
|
|
// 定制接口
|
|
result = isCustomized(dto.getTable(), result, "trigger_retrieve");
|
|
result = isCustomized(dto.getTable(), result, "trigger_retrieve");
|
|
|
|
|
|
@@ -294,126 +252,6 @@ 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);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 功能描述: 处理外键 todo 待优化
|
|
|
|
- *
|
|
|
|
- * @param result result
|
|
|
|
- * @param columns 该表对应的所有的列
|
|
|
|
- */
|
|
|
|
- private void handlerForeignKey(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
|
|
- if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- // 拿到所有有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();
|
|
|
|
- String selfColumnName = column.getColumnName();
|
|
|
|
- for (JSONObject json : result) {
|
|
|
|
- if (json.containsKey(selfColumnName.toUpperCase()) || json.containsKey(selfColumnName.toLowerCase())) {
|
|
|
|
- Map<String, Object> fkInfoMap = column.getFkInfo();
|
|
|
|
- Object fkTableName = fkInfoMap.get(FK_TABLE_NAME);
|
|
|
|
- Object fkColumnName = fkInfoMap.get(FK_COLUMN_NAME);
|
|
|
|
- Object dkColumnName = fkInfoMap.get(DK_COLUMN_NAME);
|
|
|
|
- Object primaryTableFkValue = json.get(selfColumnName);
|
|
|
|
-
|
|
|
|
- JSONObject param = new JSONObject();
|
|
|
|
- param.put(fkColumnName.toString(), primaryTableFkValue);
|
|
|
|
- JSONObject fkInfo = selectService.getOneByMap(fkTableName.toString(), param);
|
|
|
|
-
|
|
|
|
- Object value = fkInfo.get(dkColumnName);
|
|
|
|
- jsonObject.put(SINGLE_OBJ_NAME, primaryTableFkValue);
|
|
|
|
- jsonObject.put(SINGLE_OBJ_VALUE, value);
|
|
|
|
- json.put(selfColumnName.toLowerCase(), jsonObject);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 功能描述: 把timeStamp转为string, 默认类型为:YYYY_MM_DD
|
|
|
|
- *
|
|
|
|
- * @param result 被转的数据
|
|
|
|
- */
|
|
|
|
- private void handlerDate(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()) && NEED_CONVERT_DATE_LIST.contains(column.getColumnType())) {
|
|
|
|
- Date date = jsonObject.getTimestamp(column.getColumnName());
|
|
|
|
- if (null != date) {
|
|
|
|
- jsonObject.put(column.getColumnName(), DateUtils.dateTime(date));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 功能描述: 处理附件,把数据拿出来转换成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());
|
|
|
|
- List<SysFile> fileList = JSON.parseObject(value, new TypeReference<List<SysFile>>() {
|
|
|
|
- }.getType());
|
|
|
|
- jsonObject.put(column.getColumnName(), fileList);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 功能描述: 把返回值中含有字典值的转为可视化的心事
|
|
|
|
- *
|
|
|
|
- * @param result 被转的数据
|
|
|
|
- */
|
|
|
|
- private void handlerSysDictData(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
|
|
- if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (JSONObject jsonObject : result) {
|
|
|
|
- for (GenTableColumn column : columns) {
|
|
|
|
- String dictType = column.getDictType();
|
|
|
|
- if (isNotEmpty(dictType) && jsonObject.containsKey(column.getColumnName())) {
|
|
|
|
- String dictLabel = null;
|
|
|
|
- try {
|
|
|
|
- dictLabel = remoteDictDataService.selectDictLabel(dictType, jsonObject.getString(column.getColumnName()));
|
|
|
|
- jsonObject.put(column.getColumnName(), dictLabel);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 功能描述: 获取单表单数据
|
|
* 功能描述: 获取单表单数据
|
|
*
|
|
*
|
|
@@ -438,25 +276,39 @@ public class TableServiceCmdService {
|
|
JSONObject json = selectService.selectById(tableName, pkName, id);
|
|
JSONObject json = selectService.selectById(tableName, pkName, id);
|
|
requireNonNull(json, "id 为[" + id + "]的数据不存在, 表名为[" + tableName + "]");
|
|
requireNonNull(json, "id 为[" + id + "]的数据不存在, 表名为[" + tableName + "]");
|
|
// 处理blob
|
|
// 处理blob
|
|
- handlerBlobWithJSONObject(genTable.getIsContainsBlob(), Collections.singletonList(json));
|
|
|
|
- List<GenTableColumn> parentColumns = filterHrAndSort(columns);
|
|
|
|
|
|
+ handleBlob(Collections.singletonList(json), genTable.getIsContainsBlob());
|
|
|
|
|
|
|
|
+ List<GenTableColumn> parentColumns = filterHrAndSort(columns);
|
|
// 处理成hr的形式
|
|
// 处理成hr的形式
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
for (GenTableColumn hrColumn : parentColumns) {
|
|
List<GenTableColumn> children = Lists.newArrayListWithCapacity(16);
|
|
List<GenTableColumn> children = Lists.newArrayListWithCapacity(16);
|
|
for (GenTableColumn column : columns) {
|
|
for (GenTableColumn column : columns) {
|
|
if (hrColumn.getId().equals(column.getHrParentId())) {
|
|
if (hrColumn.getId().equals(column.getHrParentId())) {
|
|
- // handler column
|
|
|
|
- if (json.containsKey(column.getColumnName())) {
|
|
|
|
- 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));
|
|
|
|
|
|
+ String columnName = column.getColumnName();
|
|
|
|
+ String columnType = column.getColumnType();
|
|
|
|
+ String htmlType = column.getHtmlType();
|
|
|
|
+ String dictType = column.getDictType();
|
|
|
|
+ if (containsKeyIgnoreCase(json, columnName)) {
|
|
|
|
+ // sysDict
|
|
|
|
+ if (isNotEmpty(dictType)) {
|
|
|
|
+ // 既要sysDictData还得要columnValue
|
|
|
|
+ column.setSysDictData(listSysDictDataByType(dictType));
|
|
|
|
+ column.setColumnValue(json.get(columnName));
|
|
|
|
+ }
|
|
|
|
+ // dateTime
|
|
|
|
+ if (NEED_CONVERT_DATE_LIST.contains(columnType)) {
|
|
|
|
+ column.setColumnValue(getStrDate(json.getTimestamp(columnName)));
|
|
|
|
+ }
|
|
|
|
+ // fk
|
|
|
|
+ if (isNotEmpty(column.getForeignKey())) {
|
|
|
|
+ column.setFkInfo(getFkMap(column.getFkInfo(), json.get(columnName)));
|
|
|
|
+ }
|
|
|
|
+ // annex
|
|
|
|
+ if (HTML_IMAGE_UPLOAD.equalsIgnoreCase(htmlType) || HTML_FILE_UPLOAD.equalsIgnoreCase(htmlType)) {
|
|
|
|
+ column.setAnnex(getAnnex(json.getString(columnName)));
|
|
}
|
|
}
|
|
|
|
|
|
- column.setColumnValue(json.get(column.getColumnName()));
|
|
|
|
|
|
+ column.setReadonly(SubmitConstant.STATUS.equals(columnName));
|
|
}
|
|
}
|
|
|
|
|
|
children.add(column);
|
|
children.add(column);
|
|
@@ -509,7 +361,7 @@ public class TableServiceCmdService {
|
|
// genTable.getMenuRole() 暂时数据库没有数据,
|
|
// genTable.getMenuRole() 暂时数据库没有数据,
|
|
jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
|
|
jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
|
|
|
|
|
|
- jsonObject.put(ViewTypeConst.VIEW_TYPE, Strings.nullToEmpty(genTable.getTplCategory()));
|
|
|
|
|
|
+ jsonObject.put(ViewConst.VIEW_TYPE, Strings.nullToEmpty(genTable.getTplCategory()));
|
|
jsonObject.put(RULES, packRequireColumn(columns));
|
|
jsonObject.put(RULES, packRequireColumn(columns));
|
|
return AjaxResult.success(jsonObject);
|
|
return AjaxResult.success(jsonObject);
|
|
}
|
|
}
|
|
@@ -617,6 +469,7 @@ public class TableServiceCmdService {
|
|
if (!SubmitConstant.NOT_SUBMIT.equals(dbStatus)) {
|
|
if (!SubmitConstant.NOT_SUBMIT.equals(dbStatus)) {
|
|
commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
} else {
|
|
} else {
|
|
|
|
+ commitDatum.put(SubmitConstant.STATUS, SubmitConstant.SUBMITTED);
|
|
handlerSubmit(tableName, pkName, commitDatum);
|
|
handlerSubmit(tableName, pkName, commitDatum);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -624,6 +477,7 @@ public class TableServiceCmdService {
|
|
if (!SubmitConstant.SUBMITTED.equals(dbStatus)) {
|
|
if (!SubmitConstant.SUBMITTED.equals(dbStatus)) {
|
|
commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
commitDatum.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
} else {
|
|
} else {
|
|
|
|
+ commitDatum.put(SubmitConstant.STATUS, SubmitConstant.NOT_SUBMIT);
|
|
handlerSubmit(tableName, pkName, commitDatum);
|
|
handlerSubmit(tableName, pkName, commitDatum);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -814,18 +668,5 @@ public class TableServiceCmdService {
|
|
AjaxResult ajaxResult = remoteGenTableColumnService.listColumnsByTableId(table.getId());
|
|
AjaxResult ajaxResult = remoteGenTableColumnService.listColumnsByTableId(table.getId());
|
|
return ajaxResult;
|
|
return ajaxResult;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public List<SysDictData> listSysDictDataByType(String dictType) {
|
|
|
|
- List<SysDictData> sysDictData = null;
|
|
|
|
- try {
|
|
|
|
- sysDictData = remoteDictDataService.listByType(dictType);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- return sysDictData;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|