|
@@ -1,9 +1,14 @@
|
|
|
package com.util;
|
|
package com.util;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fasterxml.jackson.databind.type.CollectionType;
|
|
|
import com.model.bo.Screen;
|
|
import com.model.bo.Screen;
|
|
|
import com.model.bo.ScreenStr;
|
|
import com.model.bo.ScreenStr;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -12,6 +17,8 @@ import java.util.List;
|
|
|
*/
|
|
*/
|
|
|
@Component
|
|
@Component
|
|
|
public class ScreenUtil {
|
|
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();
|
|
ScreenStr screenStr = new ScreenStr();
|
|
@@ -31,7 +38,7 @@ public class ScreenUtil {
|
|
|
String value = screen.getValue();
|
|
String value = screen.getValue();
|
|
|
|
|
|
|
|
if (columnType != "time" && !("time".equals(columnType))){
|
|
if (columnType != "time" && !("time".equals(columnType))){
|
|
|
- String symbVal = getSymbAndVal(symbol, value);
|
|
|
|
|
|
|
+ String symbVal = getSymbAndVal(symbol, value, columnType);
|
|
|
if (xColumn.equals(columnName)){
|
|
if (xColumn.equals(columnName)){
|
|
|
withColumnRet = ret + " and " + columnName + " " + symbVal;
|
|
withColumnRet = ret + " and " + columnName + " " + symbVal;
|
|
|
}else {
|
|
}else {
|
|
@@ -52,13 +59,21 @@ public class ScreenUtil {
|
|
|
screenStr.setWithColumnRet(withColumnRet);
|
|
screenStr.setWithColumnRet(withColumnRet);
|
|
|
return screenStr;
|
|
return screenStr;
|
|
|
}
|
|
}
|
|
|
- public String getSymbAndVal(String symbol, String value){
|
|
|
|
|
|
|
+ public String getSymbAndVal(String symbol, String value, String columnType){
|
|
|
String values = "" + value;
|
|
String values = "" + value;
|
|
|
String tar = "";
|
|
String tar = "";
|
|
|
if ("contain".equals(symbol)){
|
|
if ("contain".equals(symbol)){
|
|
|
- tar = "like '%" + values + "%'";
|
|
|
|
|
|
|
+ if ("categorical".equals(columnType)) {
|
|
|
|
|
+ tar = "in " + getContainsCate(value);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ tar = "like '%" + values + "%'";
|
|
|
|
|
+ }
|
|
|
}else if("notContain".equals(symbol)){
|
|
}else if("notContain".equals(symbol)){
|
|
|
- tar = "not like '%" + values + "%'";
|
|
|
|
|
|
|
+ if ("categorical".equals(columnType)) {
|
|
|
|
|
+ tar = "not in " + getContainsCate(value);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ tar = "not like '%" + values + "%'";
|
|
|
|
|
+ }
|
|
|
}else if("startsWith".equals(symbol)){
|
|
}else if("startsWith".equals(symbol)){
|
|
|
tar = "like '" + values + "%'";
|
|
tar = "like '" + values + "%'";
|
|
|
}else if("endsWith".equals(symbol)){
|
|
}else if("endsWith".equals(symbol)){
|
|
@@ -76,6 +91,7 @@ public class ScreenUtil {
|
|
|
} else {
|
|
} else {
|
|
|
tar = symbol + " '" + values + "'";
|
|
tar = symbol + " '" + values + "'";
|
|
|
}
|
|
}
|
|
|
|
|
+ System.out.println("tar:" + tar);
|
|
|
return tar;
|
|
return tar;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -114,4 +130,25 @@ public class ScreenUtil {
|
|
|
}
|
|
}
|
|
|
return tar;
|
|
return tar;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ 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); //这里不需要强制转换
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String valueString = "";
|
|
|
|
|
+ Iterator isList = val.iterator();
|
|
|
|
|
+ while (isList.hasNext()){
|
|
|
|
|
+ String v = String.valueOf(isList.next());
|
|
|
|
|
+ System.out.println("v"+v);
|
|
|
|
|
+ valueString = valueString + ", '" + v + "'";
|
|
|
|
|
+ }
|
|
|
|
|
+ valueString = valueString.replaceFirst(",", "(") + ")";
|
|
|
|
|
+ return valueString;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|