|
@@ -67,51 +67,47 @@ public class QueryCondition implements IFormat {
|
|
|
StringJoiner joiner = new StringJoiner(StringPool.EMPTY);
|
|
|
joiner.add(column.toSql());
|
|
|
|
|
|
- if (value instanceof IQueryColumn iQueryColumn) {
|
|
|
- joiner.add(logic);
|
|
|
- joiner.add(iQueryColumn.toSql());
|
|
|
- } else {
|
|
|
- switch (logic) {
|
|
|
- case SqlConstant.BETWEEN, SqlConstant.NOT_BETWEEN -> {
|
|
|
- joiner.add(logic);
|
|
|
- Object[] valueObj = (Object[]) value;
|
|
|
- SqlUtil.putValue(joiner, valueObj[0]);
|
|
|
- joiner.add(SqlConstant.AND);
|
|
|
- SqlUtil.putValue(joiner, valueObj[1]);
|
|
|
- }
|
|
|
- case SqlConstant.LIKE, SqlConstant.NOT_LIKE -> {
|
|
|
- joiner.add(logic);
|
|
|
- joiner.add("concat('%',");
|
|
|
- SqlUtil.putValue(joiner, value);
|
|
|
- joiner.add(",'%')");
|
|
|
- }
|
|
|
- case SqlConstant.LIKE_LEFT, SqlConstant.NOT_LIKE_LEFT -> {
|
|
|
- joiner.add(SqlConstant.LIKE);
|
|
|
- joiner.add("concat('%',");
|
|
|
- SqlUtil.putValue(joiner, value);
|
|
|
- joiner.add(")");
|
|
|
- }
|
|
|
- case SqlConstant.LIKE_RIGHT, SqlConstant.NOT_LIKE_RIGHT -> {
|
|
|
- joiner.add(SqlConstant.LIKE);
|
|
|
- joiner.add("concat(");
|
|
|
- SqlUtil.putValue(joiner, value);
|
|
|
- joiner.add(",'%')");
|
|
|
- }
|
|
|
- case SqlConstant.IS_NULL, SqlConstant.IS_NOT_NULL -> joiner.add(logic);
|
|
|
- case SqlConstant.IN, SqlConstant.NOT_IN -> {
|
|
|
- joiner.add(logic);
|
|
|
- List<Object> inList = new ArrayList<>((Collection<?>) value);
|
|
|
- joiner.add("(");
|
|
|
- for (int i = 0; i < inList.size(); i++) {
|
|
|
- SqlUtil.putValue(joiner, inList.get(i));
|
|
|
- joiner.add(inList.size() == i + 1 ? ")" : ",");
|
|
|
- }
|
|
|
- }
|
|
|
- default -> {
|
|
|
- joiner.add(logic);
|
|
|
- SqlUtil.putParam(joiner, value);
|
|
|
+ switch (logic) {
|
|
|
+ case SqlConstant.EQ, SqlConstant.NE, SqlConstant.GT, SqlConstant.LT, SqlConstant.GE, SqlConstant.LE -> {
|
|
|
+ joiner.add(logic);
|
|
|
+ SqlUtil.putValue(joiner, value);
|
|
|
+ }
|
|
|
+ case SqlConstant.BETWEEN, SqlConstant.NOT_BETWEEN -> {
|
|
|
+ joiner.add(logic);
|
|
|
+ Object[] valueObj = (Object[]) value;
|
|
|
+ SqlUtil.putValue(joiner, valueObj[0]);
|
|
|
+ joiner.add(SqlConstant.AND);
|
|
|
+ SqlUtil.putValue(joiner, valueObj[1]);
|
|
|
+ }
|
|
|
+ case SqlConstant.LIKE, SqlConstant.NOT_LIKE -> {
|
|
|
+ joiner.add(logic);
|
|
|
+ joiner.add("concat('%',");
|
|
|
+ SqlUtil.putValue(joiner, value);
|
|
|
+ joiner.add(",'%')");
|
|
|
+ }
|
|
|
+ case SqlConstant.LIKE_LEFT, SqlConstant.NOT_LIKE_LEFT -> {
|
|
|
+ joiner.add(SqlConstant.LIKE);
|
|
|
+ joiner.add("concat('%',");
|
|
|
+ SqlUtil.putValue(joiner, value);
|
|
|
+ joiner.add(")");
|
|
|
+ }
|
|
|
+ case SqlConstant.LIKE_RIGHT, SqlConstant.NOT_LIKE_RIGHT -> {
|
|
|
+ joiner.add(SqlConstant.LIKE);
|
|
|
+ joiner.add("concat(");
|
|
|
+ SqlUtil.putValue(joiner, value);
|
|
|
+ joiner.add(",'%')");
|
|
|
+ }
|
|
|
+ case SqlConstant.IS_NULL, SqlConstant.IS_NOT_NULL -> joiner.add(logic);
|
|
|
+ case SqlConstant.IN, SqlConstant.NOT_IN -> {
|
|
|
+ joiner.add(logic);
|
|
|
+ List<Object> inList = new ArrayList<>((Collection<?>) value);
|
|
|
+ joiner.add("(");
|
|
|
+ for (int i = 0; i < inList.size(); i++) {
|
|
|
+ SqlUtil.putValue(joiner, inList.get(i));
|
|
|
+ joiner.add(inList.size() == i + 1 ? ")" : ",");
|
|
|
}
|
|
|
}
|
|
|
+ default -> throw new IllegalArgumentException("未知方法");
|
|
|
}
|
|
|
|
|
|
String sql = joiner.toString();
|