|
|
|
@ -22,6 +22,8 @@ import com.fr.stable.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Bjorn |
|
|
|
@ -30,6 +32,15 @@ import java.util.List;
|
|
|
|
|
*/ |
|
|
|
|
public class AutoTypeCalculate { |
|
|
|
|
|
|
|
|
|
public static Pattern[] dataPatterns; |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
Pattern pattern1 = Pattern.compile("^(19|20)\\d{2}$"); |
|
|
|
|
Pattern pattern2 = Pattern.compile("^\\d{4}(0?[1-9]|1[012])$"); |
|
|
|
|
Pattern pattern3 = Pattern.compile("^\\d{4}(0?[1-9]|1[012])(0?[1-9]|[12]\\d|3[01])$"); |
|
|
|
|
dataPatterns = new Pattern[]{pattern1, pattern2, pattern3}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<VanChart> calculateType(String tableName, List<String> columns) { |
|
|
|
|
List<ColumnInfo> columnValue = calculateField(tableName, columns); |
|
|
|
|
if (columnValue.isEmpty()) { |
|
|
|
@ -86,9 +97,29 @@ public class AutoTypeCalculate {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//不是日期型数字才是指标
|
|
|
|
|
return !isNumberData(values); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isNumberData(List<String> values) { |
|
|
|
|
for (String value : values) { |
|
|
|
|
if (!isNumberData(value)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isNumberData(String value) { |
|
|
|
|
for (Pattern pattern : dataPatterns) { |
|
|
|
|
Matcher matcher = pattern.matcher(value); |
|
|
|
|
if (matcher.matches()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static List<ColumnInfo> calculateField(String tableName, List<String> columns) { |
|
|
|
|
NameTableData nameTableData = new NameTableData(tableName); |
|
|
|
|
TableDataSource dataSource = TableDataSourceTailor.extractTableData(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget()); |
|
|
|
|