Merge pull request #5355 from dataease/pr@dev@fixdatasource

fix: sqlserver 过滤中文
This commit is contained in:
taojinlong 2023-05-29 17:00:30 +08:00 committed by GitHub
commit 19bf4cbf51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
package io.dataease.provider.query.sqlserver; package io.dataease.provider.query.sqlserver;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs; import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.base.domain.DatasetTableField; import io.dataease.plugins.common.base.domain.DatasetTableField;
@ -900,7 +899,9 @@ public class SqlserverQueryProvider extends QueryProvider {
whereValue = "''"; whereValue = "''";
} else if (StringUtils.containsIgnoreCase(item.getTerm(), "in") || StringUtils.containsIgnoreCase(item.getTerm(), "not in")) { } else if (StringUtils.containsIgnoreCase(item.getTerm(), "in") || StringUtils.containsIgnoreCase(item.getTerm(), "not in")) {
if(field.getType().equalsIgnoreCase("NVARCHAR")){ if(field.getType().equalsIgnoreCase("NVARCHAR")){
whereValue = Arrays.asList(value.split(",")).stream().map(str ->{return "N"+ str;}).collect(Collectors.joining(",")); whereValue = Arrays.asList(value.split(",")).stream().map(str -> {
return "N" + "'" + str + "'";
}).collect(Collectors.joining(","));
}else { }else {
whereValue = "('" + String.join("','", value.split(",")) + "')"; whereValue = "('" + String.join("','", value.split(",")) + "')";
} }
@ -1035,7 +1036,9 @@ public class SqlserverQueryProvider extends QueryProvider {
whereValue = "''"; whereValue = "''";
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "in") || StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "not in")) { } else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "in") || StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "not in")) {
if(field.getType().equalsIgnoreCase("NVARCHAR")) { if(field.getType().equalsIgnoreCase("NVARCHAR")) {
whereValue = Arrays.asList(value.split(",")).stream().map(str ->{return "N"+ str;}).collect(Collectors.joining(",")); whereValue = Arrays.asList(value.split(",")).stream().map(str -> {
return "N" + "'" + str + "'";
}).collect(Collectors.joining(","));
}else { }else {
whereValue = "('" + String.join("','", value.split(",")) + "')"; whereValue = "('" + String.join("','", value.split(",")) + "')";
} }
@ -1147,7 +1150,9 @@ public class SqlserverQueryProvider extends QueryProvider {
if (StringUtils.containsIgnoreCase(request.getOperator(), "in")) { if (StringUtils.containsIgnoreCase(request.getOperator(), "in")) {
if(request.getDatasetTableField().getType().equalsIgnoreCase("NVARCHAR")) { if(request.getDatasetTableField().getType().equalsIgnoreCase("NVARCHAR")) {
whereValue = value.stream().map(str ->{return "N"+ str;}).collect(Collectors.joining(",")); whereValue = value.stream().map(str -> {
return "N" + "'" + str + "'";
}).collect(Collectors.joining(","));
}else { }else {
whereValue = "('" + StringUtils.join(value, "','") + "')"; whereValue = "('" + StringUtils.join(value, "','") + "')";
} }
@ -1329,7 +1334,9 @@ public class SqlserverQueryProvider extends QueryProvider {
whereValue = "''"; whereValue = "''";
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) {
if(y.getType().equalsIgnoreCase("NVARCHAR")){ if(y.getType().equalsIgnoreCase("NVARCHAR")){
whereValue = Arrays.asList(f.getValue().split(",")).stream().map(str ->{return "N"+ str;}).collect(Collectors.joining(",")); whereValue = Arrays.asList(f.getValue().split(",")).stream().map(str -> {
return "N" + "'" + str + "'";
}).collect(Collectors.joining(","));
}else { }else {
whereValue = "('" + String.join("','", f.getValue().split(",")) + "')"; whereValue = "('" + String.join("','", f.getValue().split(",")) + "')";
} }