@Test public void listByPage() throws Exception { CompensationQuery query = new CompensationQuery(); query.setApplicationName("alipay-service"); PageParameter pageParameter = new PageParameter(1, 1); query.setPageParameter(pageParameter); query.setRetry(2); query.setTransId("2075304338"); final CommonPager<TccCompensationVO> pager = compensationService.listByPage(query); Assert.assertNotNull(pager.getDataList()); }
@Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> commonPager = new CommonPager<>(); final String redisKeyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(query.getApplicationName()); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; Set<byte[]> keys; List<TccCompensationVO> voList; int totalCount; if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); final List<TccCompensationVO> all = findAll(keys); final List<TccCompensationVO> collect = all.stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); if (keys.size() <= 0 || keys.size() < start) { return commonPager; } totalCount = keys.size(); voList = findByPage(keys, start, pageSize); } if (keys.size() <= 0 || keys.size() < start) { return commonPager; } commonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); commonPager.setDataList(voList); return commonPager; }
RedisCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> commonPager = new CommonPager<>(); final String redisKeyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(query.getApplicationName()); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; Set<byte[]> keys; List<TccCompensationVO> voList; int totalCount; if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); final List<TccCompensationVO> all = findAll(keys); final List<TccCompensationVO> collect = all.stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); if (keys.size() <= 0 || keys.size() < start) { return commonPager; } totalCount = keys.size(); voList = findByPage(keys, start, pageSize); } if (keys.size() <= 0 || keys.size() < start) { return commonPager; } commonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); commonPager.setDataList(voList); return commonPager; } }
RedisCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> commonPager = new CommonPager<>(); final String redisKeyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(query.getApplicationName()); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; Set<byte[]> keys; List<TccCompensationVO> voList; int totalCount; if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); final List<TccCompensationVO> all = findAll(keys); final List<TccCompensationVO> collect = all.stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); if (keys.size() <= 0 || keys.size() < start) { return commonPager; } totalCount = keys.size(); voList = findByPage(keys, start, pageSize); } if (keys.size() <= 0 || keys.size() < start) { return commonPager; } commonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); commonPager.setDataList(voList); return commonPager; } RedisCompensationServiceImpl(JedisClient jedisClient, ObjectSerializer objectSerializer); }
RedisCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> commonPager = new CommonPager<>(); final String redisKeyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(query.getApplicationName()); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; Set<byte[]> keys; List<TccCompensationVO> voList; int totalCount; if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); final List<TccCompensationVO> all = findAll(keys); final List<TccCompensationVO> collect = all.stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); if (keys.size() <= 0 || keys.size() < start) { return commonPager; } totalCount = keys.size(); voList = findByPage(keys, start, pageSize); } if (keys.size() <= 0 || keys.size() < start) { return commonPager; } commonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); commonPager.setDataList(voList); return commonPager; } RedisCompensationServiceImpl(JedisClient jedisClient, ObjectSerializer objectSerializer); @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); }
RedisCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> commonPager = new CommonPager<>(); final String redisKeyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(query.getApplicationName()); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; Set<byte[]> keys; List<TccCompensationVO> voList; int totalCount; if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); final List<TccCompensationVO> all = findAll(keys); final List<TccCompensationVO> collect = all.stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { keys = Sets.newHashSet(String.join(":", redisKeyPrefix, query.getTransId()).getBytes()); totalCount = keys.size(); voList = findAll(keys).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { keys = jedisClient.keys((redisKeyPrefix + "*").getBytes()); if (keys.size() <= 0 || keys.size() < start) { return commonPager; } totalCount = keys.size(); voList = findByPage(keys, start, pageSize); } if (keys.size() <= 0 || keys.size() < start) { return commonPager; } commonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); commonPager.setDataList(voList); return commonPager; } RedisCompensationServiceImpl(JedisClient jedisClient, ObjectSerializer objectSerializer); @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);  }