|
|
@ -14,9 +14,9 @@ import com.keyware.shandan.browser.entity.SearchConditionVo; |
|
|
|
import com.keyware.shandan.browser.service.*; |
|
|
|
import com.keyware.shandan.browser.service.*; |
|
|
|
import com.keyware.shandan.common.entity.Result; |
|
|
|
import com.keyware.shandan.common.entity.Result; |
|
|
|
import com.keyware.shandan.common.util.FileDownload; |
|
|
|
import com.keyware.shandan.common.util.FileDownload; |
|
|
|
import com.keyware.shandan.common.util.UUIDUtil; |
|
|
|
|
|
|
|
import com.keyware.shandan.frame.annotation.AppLog; |
|
|
|
import com.keyware.shandan.frame.annotation.AppLog; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
@ -24,7 +24,6 @@ import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 组合搜索前端控制器 |
|
|
|
* 组合搜索前端控制器 |
|
|
@ -51,8 +50,6 @@ public class SearchController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private MetadataSearchService metadataSearchService; |
|
|
|
private MetadataSearchService metadataSearchService; |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, ExportComponent> exportCache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 全文检索分页查询 |
|
|
|
* 全文检索分页查询 |
|
|
|
* |
|
|
|
* |
|
|
@ -196,49 +193,63 @@ public class SearchController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 数据导出-查询数据 |
|
|
|
* 目录数据导出-创建任务 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param directoryId 目录ID |
|
|
|
* @param directoryId 目录ID |
|
|
|
* @param condition 复杂查询条件 |
|
|
|
* @param condition 复杂查询条件 |
|
|
|
* @return 导出ID |
|
|
|
* @return 导出ID |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/export/directory/{directoryId}") |
|
|
|
@PostMapping("/export/directory/{directoryId}") |
|
|
|
public Result<Object> exportQuery(@PathVariable String directoryId, SearchConditionVo condition) { |
|
|
|
public Result<Object> exportQuery(@PathVariable String directoryId, SearchConditionVo condition, Authentication auth) { |
|
|
|
String exportId = UUIDUtil.getUUID(); |
|
|
|
String userId = auth.getPrincipal().toString(); |
|
|
|
ExportComponent export = new ExportComponent(exportId); |
|
|
|
ExportComponent export = null; |
|
|
|
|
|
|
|
// 这个逻辑只允许同一个用户同时只能有一个导出任务
|
|
|
|
|
|
|
|
if (ExportComponent.getCache(userId) != null) { |
|
|
|
|
|
|
|
export = ExportComponent.getCache(userId).values().stream().findFirst().orElse(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (export == null) { |
|
|
|
|
|
|
|
export = new ExportComponent(userId); |
|
|
|
// 查询数据
|
|
|
|
// 查询数据
|
|
|
|
List<DirectoryResource> list = metadataSearchService.searchAllListByCondition(directoryId, condition); |
|
|
|
List<DirectoryResource> list = metadataSearchService.searchAllListByCondition(directoryId, condition); |
|
|
|
export.setData(list); |
|
|
|
export.setData(list); |
|
|
|
// 打包数据
|
|
|
|
// 打包数据
|
|
|
|
export.start(); |
|
|
|
export.start(); |
|
|
|
exportCache.put(exportId, export); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Result.of(export.getProgress()); |
|
|
|
return Result.of(export.getProgress()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 数据导出-打包数据 |
|
|
|
* 目录数据导出-查询任务状态 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param exportId 导出ID |
|
|
|
* @param exportId 导出ID |
|
|
|
* @return 导出ID |
|
|
|
* @return 导出ID |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("/export/status/{exportId}") |
|
|
|
@GetMapping("/export/status/{exportId}") |
|
|
|
public Result<Object> exportStatus(@PathVariable String exportId) { |
|
|
|
public Result<Object> exportStatus(@PathVariable String exportId, Authentication auth) { |
|
|
|
ExportComponent export = exportCache.get(exportId); |
|
|
|
String userId = auth.getPrincipal().toString(); |
|
|
|
|
|
|
|
ExportComponent export = ExportComponent.getCache(userId, exportId); |
|
|
|
|
|
|
|
if (export == null) { |
|
|
|
|
|
|
|
return Result.of(null, false, "导出任务不存在"); |
|
|
|
|
|
|
|
} |
|
|
|
return Result.of(export.getProgress()); |
|
|
|
return Result.of(export.getProgress()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 数据导出-下载 |
|
|
|
* 目录数据导出-下载 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param response HttpServletResponse |
|
|
|
* @param response HttpServletResponse |
|
|
|
* @param exportId 导出ID |
|
|
|
* @param exportId 导出ID |
|
|
|
* @return - |
|
|
|
* @return - |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("/export/download/{exportId}") |
|
|
|
@GetMapping("/export/download/{exportId}") |
|
|
|
public String exportDownload(HttpServletResponse response, @PathVariable String exportId) { |
|
|
|
public String exportDownload(HttpServletResponse response, @PathVariable String exportId, Authentication auth) { |
|
|
|
String path = exportCache.remove(exportId).getExportPath() + ".zip"; |
|
|
|
String userId = auth.getPrincipal().toString(); |
|
|
|
|
|
|
|
ExportComponent export = ExportComponent.popCache(userId, exportId); |
|
|
|
|
|
|
|
if (export == null) { |
|
|
|
|
|
|
|
return "错误:导出任务不存在"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String path = export.getExportPath() + ".zip"; |
|
|
|
String downloadName = FileUtil.getName(path); |
|
|
|
String downloadName = FileUtil.getName(path); |
|
|
|
File file = new File(path); |
|
|
|
File file = new File(path); |
|
|
|
return FileDownload.download(response, file, downloadName, true); |
|
|
|
return FileDownload.download(response, file, downloadName, true); |
|
|
|