|
|
@@ -19,10 +19,11 @@ import java.util.List;
|
|
|
public class ScreenUtil {
|
|
|
@Autowired
|
|
|
ObjectMapper objectMapper;
|
|
|
- public ScreenStr screensUtil(List<Screen> screenList, String xColumn, String xColumnType){
|
|
|
+
|
|
|
+ public ScreenStr screensUtil(List<Screen> screenList, String xColumn, String xColumnType) {
|
|
|
//返回值
|
|
|
ScreenStr screenStr = new ScreenStr();
|
|
|
- if (screenList.size() == 0){
|
|
|
+ if (screenList.size() == 0) {
|
|
|
screenStr.setRet("");
|
|
|
screenStr.setWithColumnRet("");
|
|
|
return screenStr;
|
|
|
@@ -30,27 +31,28 @@ public class ScreenUtil {
|
|
|
String ret = ""; //筛选条件
|
|
|
String withColumnRet = ""; //与目标列相同的筛选条件
|
|
|
Iterator isList = screenList.iterator();
|
|
|
- while (isList.hasNext()){
|
|
|
+ while (isList.hasNext()) {
|
|
|
Screen screen = (Screen) isList.next();
|
|
|
String columnName = screen.getColumnName();
|
|
|
String columnType = screen.getColumnType();
|
|
|
String symbol = screen.getSymbol();
|
|
|
String value = screen.getValue();
|
|
|
|
|
|
- if (columnType != "time" && !("time".equals(columnType))){
|
|
|
+ if (columnType != "time" && !("time".equals(columnType))) {
|
|
|
String symbVal = getSymbAndVal(symbol, value, columnType);
|
|
|
- if (xColumn.equals(columnName)){
|
|
|
+ if (xColumn.equals(columnName)) {
|
|
|
withColumnRet = ret + " and " + columnName + " " + symbVal;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ret = ret + " and " + columnName + " " + symbVal;
|
|
|
}
|
|
|
System.out.println("ret:" + ret);
|
|
|
- }if(columnType == "time" || "time".equals(columnType)){
|
|
|
+ }
|
|
|
+ if (columnType == "time" || "time".equals(columnType)) {
|
|
|
String symbVal = getTimeSymbAndVal(symbol, value);
|
|
|
String column = getTimeColumn(columnName, xColumnType);
|
|
|
- if (xColumn.equals(columnName)){
|
|
|
+ if (xColumn.equals(columnName)) {
|
|
|
withColumnRet = ret + " and " + column + " " + symbVal;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ret = ret + " and " + column + " " + symbVal;
|
|
|
}
|
|
|
}
|
|
|
@@ -59,30 +61,31 @@ public class ScreenUtil {
|
|
|
screenStr.setWithColumnRet(withColumnRet);
|
|
|
return screenStr;
|
|
|
}
|
|
|
- public String getSymbAndVal(String symbol, String value, String columnType){
|
|
|
+
|
|
|
+ public String getSymbAndVal(String symbol, String value, String columnType) {
|
|
|
String values = "" + value;
|
|
|
String tar = "";
|
|
|
- if ("contain".equals(symbol)){
|
|
|
+ if ("contain".equals(symbol)) {
|
|
|
if ("categorical".equals(columnType)) {
|
|
|
tar = "in " + getContainsCate(value);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
tar = "like '%" + values + "%'";
|
|
|
}
|
|
|
- }else if("notContain".equals(symbol)){
|
|
|
+ } else if ("notContain".equals(symbol)) {
|
|
|
if ("categorical".equals(columnType)) {
|
|
|
tar = "not in " + getContainsCate(value);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
tar = "not like '%" + values + "%'";
|
|
|
}
|
|
|
- }else if("startsWith".equals(symbol)){
|
|
|
+ } else if ("startsWith".equals(symbol)) {
|
|
|
tar = "like '" + values + "%'";
|
|
|
- }else if("endsWith".equals(symbol)){
|
|
|
- tar = "like '%" + values +"'";
|
|
|
- }else if("null".equals(symbol)){
|
|
|
+ } else if ("endsWith".equals(symbol)) {
|
|
|
+ tar = "like '%" + values + "'";
|
|
|
+ } else if ("null".equals(symbol)) {
|
|
|
tar = "is null";
|
|
|
- }else if ("notNull".equals(symbol)){
|
|
|
+ } else if ("notNull".equals(symbol)) {
|
|
|
tar = "is not null";
|
|
|
- }else if ("between".equals(symbol)){
|
|
|
+ } else if ("between".equals(symbol)) {
|
|
|
tar = "";
|
|
|
String[] str = value.split(",");
|
|
|
String str1 = str[0];
|
|
|
@@ -95,57 +98,56 @@ public class ScreenUtil {
|
|
|
return tar;
|
|
|
}
|
|
|
|
|
|
- public String getTimeColumn(String columnName, String xColumnType){
|
|
|
- if ("year".equals(xColumnType)){
|
|
|
- return "to_char(" + columnName +", 'yyyy')";
|
|
|
- }else if("month".equals(xColumnType)){
|
|
|
- return "to_char(" + columnName +", 'yyyy-mm')";
|
|
|
- }else if ("day".equals(xColumnType)){
|
|
|
- return "to_char(" + columnName +", 'yyyy-mm-dd')";
|
|
|
- }else if ("quarter".equals(xColumnType)){
|
|
|
- return "to_char(" + columnName +", 'yyyy-Q')";
|
|
|
- }else if("week".equals(xColumnType)){
|
|
|
- return "to_char(" + columnName +", 'yyyy-ww')";
|
|
|
- }else {
|
|
|
- return "to_char(" + columnName +", 'yyyy-mm-dd')";
|
|
|
+ public String getTimeColumn(String columnName, String xColumnType) {
|
|
|
+ if ("year".equals(xColumnType)) {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy')";
|
|
|
+ } else if ("month".equals(xColumnType)) {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy-mm')";
|
|
|
+ } else if ("day".equals(xColumnType)) {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy-mm-dd')";
|
|
|
+ } else if ("quarter".equals(xColumnType)) {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy-Q')";
|
|
|
+ } else if ("week".equals(xColumnType)) {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy-ww')";
|
|
|
+ } else {
|
|
|
+ return "to_char(" + columnName + ", 'yyyy-mm-dd')";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private String getTimeSymbAndVal(String symbol, String value){
|
|
|
+ private String getTimeSymbAndVal(String symbol, String value) {
|
|
|
String values = "" + value;
|
|
|
String tar = "";
|
|
|
- if("null".equals(symbol)){
|
|
|
+ if ("null".equals(symbol)) {
|
|
|
tar = "is null";
|
|
|
- }else if ("notNull".equals(symbol)){
|
|
|
+ } else if ("notNull".equals(symbol)) {
|
|
|
tar = "is not null";
|
|
|
- }else if ("between".equals(symbol)){
|
|
|
+ } else if ("between".equals(symbol)) {
|
|
|
tar = "";
|
|
|
String[] str = value.split(",");
|
|
|
String str1 = str[0];
|
|
|
String str2 = str[1];
|
|
|
tar = "between '" + str1 + "' and '" + str2 + "'";
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
tar = symbol + " '" + values + "'";
|
|
|
}
|
|
|
return tar;
|
|
|
}
|
|
|
|
|
|
- public String getContainsCate(String value){
|
|
|
+ public String getContainsCate(String value) {
|
|
|
System.out.println("走这里了吗");
|
|
|
List<String> val = new ArrayList<>();
|
|
|
CollectionType javaType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, String.class);
|
|
|
try {
|
|
|
- val = objectMapper.readValue(value, javaType); //这里不需要强制转换
|
|
|
+ val = objectMapper.readValue(value, javaType); //这里不需要强制转换
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
String valueString = "";
|
|
|
Iterator isList = val.iterator();
|
|
|
- while (isList.hasNext()){
|
|
|
+ while (isList.hasNext()) {
|
|
|
String v = String.valueOf(isList.next());
|
|
|
- System.out.println("v"+v);
|
|
|
+ System.out.println("v" + v);
|
|
|
valueString = valueString + ", '" + v + "'";
|
|
|
}
|
|
|
valueString = valueString.replaceFirst(",", "(") + ")";
|