推特推文信息打包逻辑优化

This commit is contained in:
DELL 2026-01-27 10:40:56 +08:00
parent 31580190e2
commit 49d20396b2
2 changed files with 18 additions and 17 deletions

View File

@ -43,10 +43,11 @@ public class ExportController {
} }
} }
@PostMapping("/triggerTwitterTask") @PostMapping("/exportTwitterExcel")
public ReturnT<String> triggerTwitterTask() { public ReturnT<String> triggerTwitterTask(@RequestBody JSONObject object) {
try { try {
new Thread(() -> autoExportAndUpload.exportTwitterDataAndUpload()).start(); String startTime = object.getString("startTime");
new Thread(() -> autoExportAndUpload.exportTwitterDataAndUpload(startTime)).start();
return new ReturnT<>(200, "", ""); return new ReturnT<>(200, "", "");
} catch (Exception e) { } catch (Exception e) {
return new ReturnT<>(500, e.getMessage(), ""); return new ReturnT<>(500, e.getMessage(), "");

View File

@ -75,13 +75,13 @@ public class AutoExportAndUpload {
zipAndUploadDirectory(excelOutputPath, zipFileFullName, remoteZipPath); zipAndUploadDirectory(excelOutputPath, zipFileFullName, remoteZipPath);
} }
public void exportTwitterDataAndUpload() { public void exportTwitterDataAndUpload(String startTime) {
logger.info("开始导出twitter excel数据..."); logger.info("开始导出twitter excel数据...");
String twitterLastLoadTime = configService.getConfigValueByName("twitter_last_loadtime"); // String twitterLastLoadTime = configService.getConfigValueByName("twitter_last_loadtime");
String currentLoadTime = StringUtils.DateToString(new Date()); String currentLoadTime = StringUtils.DateToString(new Date());
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
databaseConnector.twitterToXlsx(twitterLastLoadTime); databaseConnector.twitterToXlsx(startTime);
copyPagesFiles(twitterLastLoadTime, currentLoadTime); copyPagesFiles(startTime, currentLoadTime);
configService.setConfigValueByName("twitter_last_loadtime", currentLoadTime); configService.setConfigValueByName("twitter_last_loadtime", currentLoadTime);
String zipFileName = "data_twitter-" + timestamp + "-001.zip"; String zipFileName = "data_twitter-" + timestamp + "-001.zip";
String zipFileFullName = backupFilePath + File.separator + zipFileName; String zipFileFullName = backupFilePath + File.separator + zipFileName;
@ -124,16 +124,16 @@ public class AutoExportAndUpload {
} }
// 上传 ZIP 文件 // 上传 ZIP 文件
try (InputStream zipInputStream = Files.newInputStream(localZipFile)) { // try (InputStream zipInputStream = Files.newInputStream(localZipFile)) {
boolean uploaded = ftpConnector.uploadFile(zipInputStream, remoteZipPath); // boolean uploaded = ftpConnector.uploadFile(zipInputStream, remoteZipPath);
if (uploaded) { // if (uploaded) {
logger.info("ZIP 文件上传成功 - 本地: {}, FTP: {}", localZipPath, remoteZipPath); // logger.info("ZIP 文件上传成功 - 本地: {}, FTP: {}", localZipPath, remoteZipPath);
} else { // } else {
logger.error("ZIP 文件上传失败 - FTP: {}", remoteZipPath); // logger.error("ZIP 文件上传失败 - FTP: {}", remoteZipPath);
} // }
} catch (IOException e) { // } catch (IOException e) {
logger.error("读取本地 ZIP 文件失败: {}", localZipPath, e); // logger.error("读取本地 ZIP 文件失败: {}", localZipPath, e);
} // }
// 注意此处不再删除 localZipFile由调用方决定是否保留或清理 // 注意此处不再删除 localZipFile由调用方决定是否保留或清理
} }