@Test public void listByPage() throws Exception { CompensationQuery query = new CompensationQuery(); PageParameter pageParameter = new PageParameter(1, 10); query.setPageParameter(pageParameter); query.setApplicationName("account-service"); final CommonPager<TccCompensationVO> pager = compensationService.listByPage(query); Assert.assertNotNull(pager.getDataList()); }
@Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder .append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ").append(tableName) .append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TccCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }
JdbcCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder .append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ").append(tableName) .append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TccCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; } }
JdbcCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder .append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ").append(tableName) .append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TccCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }  }
JdbcCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder .append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ").append(tableName) .append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TccCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }  @Override CommonPager<TccCompensationVO> listByPage(final CompensationQuery query); @Override Boolean batchRemove(final List<String> ids, final String applicationName); @Override Boolean updateRetry(final String id, final Integer retry, final String appName); void setDbType(final String dbType); }
JdbcCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder .append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ").append(tableName) .append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TccCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }  @Override CommonPager<TccCompensationVO> listByPage(final CompensationQuery query); @Override Boolean batchRemove(final List<String> ids, final String applicationName); @Override Boolean updateRetry(final String id, final Integer retry, final String appName); void setDbType(final String dbType);  }