自定義Sql + 拼接查詢條件 + 分頁
@Override
public Pagination<SnAfterSalesLog> pagiByCondition(int pageNo, int pageSize, String snHex) {
// 獲取自定義sql語句
Sql sql = getQueryRecordSqlByKey(SqlKey.LIST_ALL_WITH_SNBURNERTIME_PRODUCTNUMBER);
// 默認查詢條件
Cnd conditionParam = Cnd.where("t.deleted_at", "=", 0);
Cnd cndForCount = createDefaultQueryCondition();
if (StringUtils.isNoneBlank(snHex)) {
int sn = 0;
try {
sn = Integer.parseInt(snHex, 16);
} catch (Exception e) {
throw IgnisException.clientError("SN號轉(zhuǎn)換錯誤");
}
// 設(shè)置并拼接查詢條件
conditionParam.and("t.sn", "=", sn);
cndForCount.and(Field.SN, "=", sn);
sql.setCondition(conditionParam);
}
// 設(shè)置分頁
sql.setPager(new Pager(pageNo, pageSize));
List<SnAfterSalesLog> snAfterSalesLogs = query(sql, SnAfterSalesLog.class);
Pagination<SnAfterSalesLog> pagination = new Pagination<>(pageNo, pageSize);
pagination.setRecordCount(base().count(cndForCount));
pagination.setRecords(snAfterSalesLogs);
return pagination;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者