|
|
@@ -3,11 +3,13 @@ package com.uas.search.support;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.search.constant.model.PageInfo;
|
|
|
import com.uas.search.constant.model.PageParams;
|
|
|
+import com.uas.search.service.JdbcService;
|
|
|
import com.uas.search.service.impl.IndexServiceImpl;
|
|
|
import com.uas.search.util.CollectionUtils;
|
|
|
import com.uas.search.util.SearchUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
|
@@ -16,6 +18,7 @@ import java.io.File;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
import static com.uas.search.service.impl.IndexServiceImpl.PAGE_SIZE;
|
|
|
import static com.uas.search.service.impl.IndexServiceImpl.SINGLE_FILE_MAX_SIZE;
|
|
|
@@ -28,6 +31,9 @@ import static com.uas.search.service.impl.IndexServiceImpl.SINGLE_FILE_MAX_SIZE;
|
|
|
*/
|
|
|
public class DownloadService<T> {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private JdbcService jdbcService;
|
|
|
+
|
|
|
/**
|
|
|
* @param id 线程 id
|
|
|
* @param step 新增文件时,文件 id 的自增步长,(即线程数量)
|
|
|
@@ -52,18 +58,21 @@ public class DownloadService<T> {
|
|
|
logger.info(name + " startFileIndex 超过 " + endFileIndex);
|
|
|
return size;
|
|
|
}
|
|
|
- Long startTime = new Date().getTime();
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
logger.info(name + " 下载 " + tableName + "...");
|
|
|
|
|
|
Sort sort = new Sort(Sort.Direction.ASC, sortField);
|
|
|
// 分页获取数据
|
|
|
- PageParams pageParams = new PageParams();
|
|
|
- pageParams.setPage((startFileIndex - 1) * SINGLE_FILE_MAX_SIZE / PAGE_SIZE + 1);
|
|
|
- pageParams.setSize(IndexServiceImpl.PAGE_SIZE);
|
|
|
- PageInfo pageInfo = new PageInfo(pageParams, sort);
|
|
|
+// PageParams pageParams = new PageParams();
|
|
|
+// pageParams.setPage((startFileIndex - 1) * SINGLE_FILE_MAX_SIZE / PAGE_SIZE + 1);
|
|
|
+// pageParams.setSize(PAGE_SIZE);
|
|
|
+// PageInfo pageInfo = new PageInfo(pageParams, sort);
|
|
|
Page<T> pageResult = dao.findAll(pageInfo);
|
|
|
|
|
|
- int totalFiles = (int) Math.ceil(pageResult.getTotalElements() / (1.0 * SINGLE_FILE_MAX_SIZE));
|
|
|
+ jdbcService.getLimitId(tableName, Sort.Direction.ASC.name(), sortField, (long) (startFileIndex - 1) * SINGLE_FILE_MAX_SIZE, PAGE_SIZE);
|
|
|
+
|
|
|
+
|
|
|
+ int totalFiles = (int) Math.ceil(jdbcService.getTotalElements(tableName) / (1.0 * SINGLE_FILE_MAX_SIZE));
|
|
|
if (startFileIndex > totalFiles) {
|
|
|
logger.info(name + " startFileIndex 超过 " + totalFiles);
|
|
|
return size;
|