提交 034da93b authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 稳定版修改integer和double的错误

上级 c7b4b059
......@@ -13,6 +13,7 @@ import java.util.Objects;
public interface FourComsumer<T, Y, U, I> {
/**
* accept
* @param t
* @param y
* @param u
......@@ -20,6 +21,11 @@ public interface FourComsumer<T, Y, U, I> {
*/
void accept(T t, Y y, U u, I i);
/**
* andThen
* @param after
* @return
*/
default FourComsumer<T, Y, U, I> andThen(FourComsumer<? super T, ? super Y, ? super U, ? super I> after) {
Objects.requireNonNull(after);
......
......@@ -669,7 +669,7 @@ public class ModelImpl implements ModelService {
//引用校验
if (!isNull(quoteDao.findAllByColumnId(columnInfo.getId()))) {
List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList());
if (!validationQuote(quotes, (String) value)) {
if (!validationQuote(quotes, value)) {
throw new ApiException("引用校验不通过!");
}
}
......
package com.tykj.datawarehouse.model.utils;
import com.tykj.datawarehouse.base.result.ApiException;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
......@@ -36,15 +37,28 @@ public class CheckUtils {
throw new ApiException("校验不通过!");
}
public static Boolean validationQuote(List<String> quotes, String val) {
public static Boolean validationQuote(List<String> quotes, Object val) {
//如果没有引用就通过
if (quotes.size() == 0) {
return true;
}
//如果引用存在则通过
if (quotes.contains(val)) {
return true;
if (val instanceof String){
if (quotes.contains(val)) {
return true;
}
}
if (val instanceof Integer){
if (quotes.contains(val)) {
return true;
}
}
if (val instanceof Double){
if (quotes.contains(val)) {
return true;
}
}
throw new ApiException("引用不通过!");
}
......
......@@ -50,7 +50,7 @@ public class SqlUtil {
//基本部分
result.append(String.format("ALTER TABLE %s ADD COLUMN %s %s", table, name, type));
//字段长度
if (nonNull(length)) {
if (nonNull(length) && type.equals("java.lang.String")) {
result.append(String.format("(%s)", length));
}
result.append(";");
......@@ -77,12 +77,12 @@ public class SqlUtil {
&& nonNull(newType);
StringBuilder result = new StringBuilder();
if (hasValue) {
if (needLengthColumn(newType)){
result.append(String.format("ALTER TABLE %s MODIFY %s %s (%s) ;", table, name, newType,newLength));
}else {
if (needLengthColumn(newType)) {
result.append(String.format("ALTER TABLE %s MODIFY %s %s (%s) ;", table, name, newType, newLength));
} else {
result.append(String.format("ALTER TABLE %s MODIFY %s %s ;", table, name, newType));
}
if (isNull(newName)){
if (isNull(newName)) {
result.append(String.format("ALTER TABLE %s RENAME COLUMN %s TO %s ;", table, name, newName));
}
} else {
......@@ -94,16 +94,16 @@ public class SqlUtil {
/**
* 修改表的单个字段的SQL语句
*
* @param table 表名
* @param name 旧字段名
* @param newName 新字段名
* @param table 表名
* @param name 旧字段名
* @param newName 新字段名
* @return SQL语句
*/
public static String updateColumnName(String table, String name, String newName) {
boolean hasValue = !Strings.isNullOrEmpty(table);
StringBuilder result = new StringBuilder();
if (hasValue) {
if (!isNull(newName)){
if (!isNull(newName)) {
result.append(String.format("ALTER TABLE %s RENAME COLUMN %s TO %s ;", table, name, newName));
}
} else {
......@@ -123,8 +123,8 @@ public class SqlUtil {
return String.format("ALTER TABLE %s DROP %s;", table, name);
}
private static boolean needLengthColumn(String type){
switch (type){
private static boolean needLengthColumn(String type) {
switch (type) {
case "varchar":
return true;
default:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论