Skip to content

Commit 5e2ed07

Browse files
authored
解决 JOIN ON 不支持 @cast,感谢 lindaifeng 的贡献~ Tencent#785
Tencent#785
2 parents 1f2d304 + 99b910a commit 5e2ed07

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4870,8 +4870,21 @@ protected String concatJoinOn(@NotNull String sql, @NotNull String quote, @NotNu
48704870

48714871
String rt = on.getRelateType();
48724872
if (StringUtil.isEmpty(rt, false)) {
4873-
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
4874-
+ quote + getSQLTableWithAlias(on.getTargetTable(), on.getTargetAlias()) + quote + "." + quote + on.getTargetKey() + quote;
4873+
// 解决 JOIN ON 不支持 @cast 问题
4874+
SQLConfig jc = j.getJoinConfig();
4875+
Map<String, String> castMap = jc == null ? null : jc.getCast();
4876+
if (castMap == null || castMap.isEmpty()) {
4877+
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
4878+
+ quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
4879+
} else {
4880+
String leftTableRelationSql = quote + jt + quote + "." + quote + on.getKey() + quote;
4881+
Object castValueType = castMap.get(on.getOriginKey());
4882+
if (castValueType != null) {
4883+
leftTableRelationSql = "CAST(" + leftTableRelationSql + " AS " + castValueType + ")";
4884+
}
4885+
sql += (first ? ON : AND) + leftTableRelationSql + (isNot ? " != " : " = ")
4886+
+ quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
4887+
}
48754888
}
48764889
else {
48774890
onJoinComplexRelation(sql, quote, j, jt, onList, on);

0 commit comments

Comments
 (0)