Java大批量查询 切割 切分 分批次查询

/**
	 * 切分查询
	 * @param phoneList 集合
	 * @return
	 */
	private List<PhoneNumberOperatorVO> queryOperator(List<String> phoneList) {
    
    
		int size = phoneList.size();
		int batchSize = 100; // 切割大小
		int batchCount = (size + batchSize - 1) / batchSize; // 计算需要分多少次查询
		List<PhoneNumberOperatorVO> exportList = new ArrayList<>();

		for (int i = 0; i < batchCount; i++) {
    
    
			int startIndex = i * batchSize; // 当前批次查询的起始索引
			int endIndex = Math.min(startIndex + batchSize, size); // 当前批次查询的结束索引
			List<String> batchPhoneList = phoneList.subList(startIndex, endIndex); // 当前批次的电话列表
			List<PhoneNumberOperatorVO> batchResult = ctSegmentNumberInfoMapper.queryOperatorList(batchPhoneList); // 查询当前批次的记录
			exportList.addAll(batchResult); // 将当前批次的结果添加到总结果列表中
		}
		return exportList;
	}

猜你喜欢

转载自blog.csdn.net/Ying_ph/article/details/134512187