Nutz

自定义Sql + 拼接查询条件 + 分页

@Override
  public Pagination 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 snAfterSalesLogs = query(sql, SnAfterSalesLog.class);
    Pagination pagination = new Pagination<>(pageNo, pageSize);
    pagination.setRecordCount(base().count(cndForCount));
    pagination.setRecords(snAfterSalesLogs);
    return pagination;
  }

你可能感兴趣的:(Nutz)