|
@@ -13,14 +13,17 @@ import com.boman.common.redis.service.RedisService;
|
|
|
import com.boman.domain.GenTable;
|
|
|
import com.boman.domain.GenTableColumn;
|
|
|
import com.boman.domain.constant.MysqlDataTypeConst;
|
|
|
+import com.boman.domain.dto.FormDataDto;
|
|
|
import com.boman.domain.exception.UnknownColumnException;
|
|
|
import com.boman.web.core.domain.TableContext;
|
|
|
+import com.boman.web.core.service.TableServiceCmdService;
|
|
|
import com.google.common.base.Joiner;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Predicate;
|
|
@@ -456,4 +459,61 @@ public class ColumnUtils {
|
|
|
requireNonNull(genTable, String.format("表名为: %s 的表不存在缓存中", tableName));
|
|
|
return genTable.getColumns();
|
|
|
}
|
|
|
+
|
|
|
+ public static List<String> fkName(List<GenTableColumn> columns){
|
|
|
+ List<String> result = new ArrayList<>(columns.size());
|
|
|
+ for (GenTableColumn column : columns) {
|
|
|
+ Long foreignKey = column.getForeignKey();
|
|
|
+ if (isEmpty(foreignKey)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ result.add(column.getColumnName());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<String> fkNames(String tableName) {
|
|
|
+ TableServiceCmdService cmdService = SpringUtils.getBean(TableServiceCmdService.class);
|
|
|
+ GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
|
|
|
+ if (genTable == null) {
|
|
|
+ throw new IllegalArgumentException(String.format("表名: %s 为空", tableName));
|
|
|
+ }
|
|
|
+
|
|
|
+ return fkName(genTable.getColumns());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 复杂对象保存时,设置子表关联主表的外键值,
|
|
|
+ *
|
|
|
+ * @param tableNameIdMap 主表的map key:tableName value:id
|
|
|
+ * @param dto 需要保存的对象
|
|
|
+ * @param first 复杂对象保存,是否是最外层的
|
|
|
+ */
|
|
|
+ public static void putFkValue(Map<String, Long> tableNameIdMap, FormDataDto dto, boolean first) {
|
|
|
+ if (first) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject fixedData = dto.getFixedData();
|
|
|
+ for (Map.Entry<String, Object> entry : fixedData.entrySet()) {
|
|
|
+ Object value = entry.getValue();
|
|
|
+ if (value instanceof String) {
|
|
|
+ String strValue = (String) value;
|
|
|
+ if (!strValue.contains(FK_POINT)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] split = strValue.split(POINT);
|
|
|
+ String lastTableName = split[split.length - 1];
|
|
|
+ Long maxId = tableNameIdMap.get(lastTableName);
|
|
|
+ if (maxId == null) {
|
|
|
+ throw new RuntimeException(String.format("保存失败, 主表id: null, 表名为: %s ", lastTableName));
|
|
|
+ }
|
|
|
+ fixedData.put(entry.getKey(), maxId);
|
|
|
+ dto.setFixedData(fixedData);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|