|
@@ -7,6 +7,7 @@ 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;
|
|
|
+import com.boman.common.core.utils.array.ArrayUtils;
|
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
@@ -16,7 +17,6 @@ import com.boman.domain.SysDictData;
|
|
|
import com.boman.domain.constant.*;
|
|
|
import com.boman.gen.api.RemoteGenTableColumnService;
|
|
|
import com.boman.gen.api.RemoteGenTableService;
|
|
|
-//import com.boman.gen.controller.MyController;
|
|
|
import com.boman.domain.GenTable;
|
|
|
import com.boman.domain.GenTableColumn;
|
|
|
import com.boman.system.api.RemoteDictDataService;
|
|
@@ -31,6 +31,7 @@ import com.boman.web.core.utils.IdUtils;
|
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -88,6 +89,8 @@ public class TableServiceCmdService {
|
|
|
checkColumn(commitData, context.getColumns());
|
|
|
// 必填项
|
|
|
handlerRequired(commitData, context.getColumns());
|
|
|
+ // 处理输入类型
|
|
|
+ handlerInputType(commitData, context.getColumns());
|
|
|
|
|
|
// 新增
|
|
|
if (ActionType.INSERT.equals(context.getActionType())) {
|
|
@@ -114,6 +117,22 @@ public class TableServiceCmdService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void handlerInputType(JSONObject commitData, List<GenTableColumn> columns) {
|
|
|
+ for (Map.Entry<String, Object> entry : commitData.entrySet()) {
|
|
|
+ Object value =entry.getValue();
|
|
|
+ for (GenTableColumn column : columns) {
|
|
|
+ if (entry.getKey().equals(column.getColumnName())
|
|
|
+ && ArrayUtils.arraysContains(GenConstants.COLUMNTYPE_NUMBER, getDbType(column.getColumnType()))) {
|
|
|
+ if ((value instanceof Number)) {
|
|
|
+ // ignore 这里的if不能删掉,因为else if有一个强转
|
|
|
+ } else if (!NumberUtils.isCreatable(((String) value))) {
|
|
|
+ throw new IllegalArgumentException(column.getColumnComment() + "只能输入数字");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void handlerRequired(JSONObject commitData, List<GenTableColumn> columns) {
|
|
|
for (GenTableColumn column : columns) {
|
|
|
if (GenTableColumn.IS_REQUIRED.equalsIgnoreCase(column.getIsRequired())) {
|
|
@@ -272,33 +291,6 @@ public class TableServiceCmdService {
|
|
|
jsonObject.put(SINGLE_OBJ_NAME, primaryTableFkValue);
|
|
|
jsonObject.put(SINGLE_OBJ_VALUE, value);
|
|
|
json.put(selfColumnName.toLowerCase(), jsonObject);
|
|
|
-
|
|
|
-
|
|
|
- // method();=> fkTableName、fkColumnName
|
|
|
- // 外键在table_column中的id
|
|
|
-// Long fkColumnId = Long.parseLong(column.getForeignKey());
|
|
|
-// GenTableColumn fkTableColumn = remoteGenTableColumnService.getById(fkColumnId);
|
|
|
-// String fkColumnName = fkTableColumn.getColumnName();
|
|
|
-// Long fkTableId = fkTableColumn.getTableId();
|
|
|
-// GenTable fkGenTable = remoteGenTableService.getByTableId(fkTableId);
|
|
|
-// // 显示键 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": "开发部"}
|
|
|
-// JSONObject param = new JSONObject();
|
|
|
-// param.put(fkColumnName, primaryTableFkValue);
|
|
|
-// List<JSONObject> fkList = selectService.getByMap(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;
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -462,7 +454,7 @@ public class TableServiceCmdService {
|
|
|
/**
|
|
|
* 功能描述: 获取表单查询字段、按钮、表头
|
|
|
* 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
|
- * 刷新的入口为 {@link MyController#loadTable(GenTable)}
|
|
|
+ *
|
|
|
* <p>
|
|
|
* eg:{
|
|
|
* "table": "sys_config",
|
|
@@ -498,13 +490,14 @@ public class TableServiceCmdService {
|
|
|
jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
|
|
|
|
|
|
jsonObject.put(ViewConst.VIEW_TYPE, Strings.nullToEmpty(genTable.getTplCategory()));
|
|
|
+ jsonObject.put(RULES, packRequireColumn(columns));
|
|
|
return AjaxResult.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: 获取表单查询字段
|
|
|
* 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
|
- * 刷新的入口为 {@link MyController#loadTable(GenTable)}
|
|
|
+ *
|
|
|
* <p>
|
|
|
* eg:{
|
|
|
* "table": "sys_config"
|