Commit 430b30f7 by 林永健

fix parse sql bug

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