Commit 430b30f7 by 林永健

fix parse sql bug

1 parent 2555c198
...@@ -28,7 +28,7 @@ import java.util.stream.Collectors; ...@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class SopDataService { public class SopDataService {
private final String updateStagePrefix = "update cdp_customer_sop_journey set sop_journey_stage='%1$s',sop_journey_stage_enter_time=now() where sop_journey_stage!='%1$s'"; private final String updateStagePrefix = "update cdp_customer_sop_journey set sop_journey_stage='%1$s',sop_journey_stage_enter_time=now() where sop_journey_stage!='%1$s' and sop_journey_id='%2$s'";
@Autowired @Autowired
private SopDataFilterActionMapper sopDataFilterActionMapper; private SopDataFilterActionMapper sopDataFilterActionMapper;
...@@ -195,7 +195,7 @@ public class SopDataService { ...@@ -195,7 +195,7 @@ public class SopDataService {
log.warn("parse actions fail, json:{}, res: {}", conditionJson, actions); log.warn("parse actions fail, json:{}, res: {}", conditionJson, actions);
return; return;
} }
res.put(k, actions.stream().map(p -> parseSQL(p, stageName)).collect(Collectors.joining(" "))); res.put(k, actions.stream().map(p -> parseSQL(p, stageName, inst.getInstId())).collect(Collectors.joining(" ")));
}); });
return res; return res;
} }
...@@ -203,7 +203,7 @@ public class SopDataService { ...@@ -203,7 +203,7 @@ public class SopDataService {
/** /**
* 将指定条件SQL进行拼接 * 将指定条件SQL进行拼接
*/ */
public String parseSQL(SopDataActionDTO action, String StageName) { public String parseSQL(SopDataActionDTO action, String StageName, String instId) {
String res = action.getSql(); String res = action.getSql();
if (CollectionUtils.isEmpty(action.getConditions())) { if (CollectionUtils.isEmpty(action.getConditions())) {
return res; return res;
...@@ -217,10 +217,10 @@ public class SopDataService { ...@@ -217,10 +217,10 @@ public class SopDataService {
subCondStrList.add(parseSQLWithOperator(subCondition)); subCondStrList.add(parseSQLWithOperator(subCondition));
} }
String subCondStr = joinWithDelimiter(" and ", subCondStrList); String subCondStr = joinWithDelimiter(" and ", subCondStrList);
condStr = sqlAnd(condStr, subCondStr);
if (condition.getSql().toLowerCase().contains("(select ")) { if (condition.getSql().toLowerCase().contains("(select ")) {
subCondStr += ")"; condStr += ")";
} }
condStr = sqlAnd(condStr, subCondStr);
} }
condStrList.add(condStr); condStrList.add(condStr);
} }
...@@ -232,7 +232,7 @@ public class SopDataService { ...@@ -232,7 +232,7 @@ public class SopDataService {
.replace(">", ">") .replace(">", ">")
.replace("&eq;", "=") .replace("&eq;", "=")
.replace("≠", "!="); .replace("≠", "!=");
return String.format(updateStagePrefix, StageName) + res + ";"; return sqlAnd(String.format(updateStagePrefix, StageName, instId), res) + ";";
} }
private String parseSQLWithOperator(SopDataConditionDTO condition) { private String parseSQLWithOperator(SopDataConditionDTO condition) {
...@@ -277,7 +277,6 @@ public class SopDataService { ...@@ -277,7 +277,6 @@ public class SopDataService {
if (CollectionUtils.isEmpty(parts)) { if (CollectionUtils.isEmpty(parts)) {
return ""; return "";
} }
parts = parts.stream().filter(Objects::nonNull).filter(p -> StringUtils.hasLength(p.trim())).collect(Collectors.toList()); return parts.stream().filter(Objects::nonNull).filter(p -> StringUtils.hasLength(p.trim())).collect(Collectors.joining(join));
return String.join(join, parts);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!