自定义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号转换错误");
}
// 设置并拼接查询条件
conditionParam.and("t.sn", "=", sn);
cndForCount.and(Field.SN, "=", sn);
sql.setCondition(conditionParam);
}
// 设置分页
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;
}