自己研究了下解决了,代码如下:
@
Override protected void processSelect(Select select, int index, String sql, Object obj) {
// 默认情况下,直接加到最外层查询的 where 后面
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
if (select.toString().contains("ROWNUM")) {
// oracle 分页的情况,需要找到最内层的查询,然后加到 where 后面
plainSelect = getInnerSelect(plainSelect);
}
// 给查询添加条件
GreaterThanEquals greaterThanEquals = getGreaterThanEquals();
Expression where = plainSelect.getWhere();
plainSelect.setWhere(where == null ? greaterThanEquals : new AndExpression(where, greaterThanEquals));
}
private static PlainSelect getInnerSelect(PlainSelect select) {
if (select.getFromItem() instanceof SubSelect) {
PlainSelect fromSelect = (PlainSelect) ((SubSelect) select.getFromItem()).getSelectBody();
return getInnerSelect(fromSelect);
}
return select;
}
@
NotNull private static GreaterThanEquals getGreaterThanEquals() {
GreaterThanEquals greaterThanEquals = new GreaterThanEquals();
greaterThanEquals.setLeftExpression(new Column("created_time"));
greaterThanEquals.setRightExpression(new DateValue("'2024-07-26'"));
return greaterThanEquals;
}