|
|
@@ -76,9 +76,9 @@ public class DownloadHelper<T> {
|
|
|
private String sortField;
|
|
|
|
|
|
/**
|
|
|
- * dao
|
|
|
+ * class
|
|
|
*/
|
|
|
- private JpaRepository<T, Long> dao;
|
|
|
+ private Class className;
|
|
|
|
|
|
/**
|
|
|
* 下载的实现
|
|
|
@@ -122,11 +122,11 @@ public class DownloadHelper<T> {
|
|
|
* @param endFileIndex 结束的文件
|
|
|
* @param tableName 要下载的表
|
|
|
* @param sortField 排序字段
|
|
|
- * @param dao dao
|
|
|
+ * @param className 转换class
|
|
|
* @param downloadService 下载的实现
|
|
|
*/
|
|
|
- public DownloadHelper(Integer threadSize, Integer startFileIndex, Integer endFileIndex, String tableName, String sortField, JpaRepository<T, Long> dao, DownloadService<T> downloadService) {
|
|
|
- this(threadSize, startFileIndex, endFileIndex, tableName, sortField, dao, downloadService, CURRENT);
|
|
|
+ public DownloadHelper(Integer threadSize, Integer startFileIndex, Integer endFileIndex, String tableName, String sortField, Class className, DownloadService<T> downloadService) {
|
|
|
+ this(threadSize, startFileIndex, endFileIndex, tableName, sortField, className, downloadService, CURRENT);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -135,11 +135,11 @@ public class DownloadHelper<T> {
|
|
|
* @param endFileIndex 结束的文件
|
|
|
* @param tableName 要下载的表
|
|
|
* @param sortField 排序字段
|
|
|
- * @param dao dao
|
|
|
+ * @param className 转换class
|
|
|
* @param downloadService 下载的实现
|
|
|
* @param validateResult 下载完成后,是否对结果进行校验
|
|
|
*/
|
|
|
- public DownloadHelper(Integer threadSize, Integer startFileIndex, Integer endFileIndex, String tableName, String sortField, JpaRepository<T, Long> dao, DownloadService<T> downloadService, ValidateResult validateResult) {
|
|
|
+ public DownloadHelper(Integer threadSize, Integer startFileIndex, Integer endFileIndex, String tableName, String sortField, Class className, DownloadService<T> downloadService, ValidateResult validateResult) {
|
|
|
if (threadSize == null || threadSize < MIN_THREAD_SIZE || threadSize > MAX_THREAD_SIZE) {
|
|
|
throw new IllegalArgumentException("threadSize is between " + MIN_THREAD_SIZE + " and " + MAX_THREAD_SIZE);
|
|
|
}
|
|
|
@@ -152,7 +152,7 @@ public class DownloadHelper<T> {
|
|
|
this.endFileIndex = endFileIndex == null || endFileIndex < DEFAULT_START_FILE_INDEX ? DEFAULT_END_FILE_INDEX : endFileIndex;
|
|
|
this.tableName = tableName;
|
|
|
this.sortField = sortField;
|
|
|
- this.dao = dao;
|
|
|
+ this.className = className;
|
|
|
this.validateResult = validateResult;
|
|
|
start();
|
|
|
}
|
|
|
@@ -167,12 +167,13 @@ public class DownloadHelper<T> {
|
|
|
// 删除旧的文件
|
|
|
FileUtils.deleteSubFiles(new File(SearchUtils.getDataPath(tableName)));
|
|
|
}
|
|
|
+ // 获取下载总条数
|
|
|
getTotalElements(tableName);
|
|
|
logger.info(tableName + " 发现数据 " + totalElements + " 条");
|
|
|
// 线程数量不可高于下载的文件数量
|
|
|
threadSize = threadSize <= endFileIndex - startFileIndex + 1 ? threadSize : endFileIndex - startFileIndex + 1;
|
|
|
for (int i = 0; i < threadSize; i++) {
|
|
|
- completionService.submit(getTask(i, threadSize, startFileIndex + i, endFileIndex, tableName, sortField, dao));
|
|
|
+ completionService.submit(getTask(i, threadSize, startFileIndex + i, endFileIndex, tableName, sortField, className));
|
|
|
}
|
|
|
waitResult();
|
|
|
if (validateResult != null && validateResult != NONE) {
|
|
|
@@ -184,7 +185,7 @@ public class DownloadHelper<T> {
|
|
|
logger.error("第 " + retry + " 次校验,下载遗失的文件:" + missingFiles);
|
|
|
List<DownloadHelper<T>> downloadHelpers = new ArrayList<>();
|
|
|
for (Integer missingFile : missingFiles) {
|
|
|
- downloadHelpers.add(new DownloadHelper<>(1, missingFile, missingFile, tableName, sortField, dao, downloadService, NONE));
|
|
|
+ downloadHelpers.add(new DownloadHelper<>(1, missingFile, missingFile, tableName, sortField, className, downloadService, NONE));
|
|
|
}
|
|
|
for (DownloadHelper downloadHelper : downloadHelpers) {
|
|
|
downloadHelper.getResult();
|
|
|
@@ -204,7 +205,7 @@ public class DownloadHelper<T> {
|
|
|
* @param tableName 表名
|
|
|
*/
|
|
|
private void getTotalElements(String tableName) {
|
|
|
- totalElements = jdbcTemplate.queryForObject("select count(1) from " + tableName, Long.class);
|
|
|
+ totalElements = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Long.class);
|
|
|
// PageParams pageParams = new PageParams();
|
|
|
// pageParams.setPage(startFileIndex);
|
|
|
// pageParams.setSize(PAGE_SIZE);
|
|
|
@@ -221,14 +222,14 @@ public class DownloadHelper<T> {
|
|
|
* @param endFileIndex 结束的文件
|
|
|
* @param tableName 要下载的表
|
|
|
* @param sortField 排序字段
|
|
|
- * @param dao dao
|
|
|
+ * @param className 转换class
|
|
|
* @return 任务
|
|
|
*/
|
|
|
- private Callable<Long> getTask(final int id, final int step, final int startFileIndex, final int endFileIndex, final String tableName, final String sortField, final JpaRepository<T, Long> dao) {
|
|
|
+ private Callable<Long> getTask(final int id, final int step, final int startFileIndex, final int endFileIndex, final String tableName, final String sortField, final Class className) {
|
|
|
return new Callable<Long>() {
|
|
|
@Override
|
|
|
public Long call() throws Exception {
|
|
|
- return downloadService.download(id, step, startFileIndex, endFileIndex, tableName, sortField, dao);
|
|
|
+ return downloadService.download(id, step, startFileIndex, endFileIndex, tableName, sortField, className);
|
|
|
}
|
|
|
};
|
|
|
}
|