最新逻辑同步
This commit is contained in:
parent
cde711f1d5
commit
d3a46db615
@ -2,9 +2,8 @@ package com.jsc.dsp.controller;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jsc.dsp.model.ReturnT;
|
import com.jsc.dsp.model.ReturnT;
|
||||||
import com.jsc.dsp.utils.AutoExportAndUpload;
|
import com.jsc.dsp.utils.ExportAndUploadUtils;
|
||||||
import com.jsc.dsp.utils.DatabaseConnector;
|
import com.jsc.dsp.utils.DatabaseConnector;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -20,7 +19,7 @@ public class ExportController {
|
|||||||
DatabaseConnector databaseConnector;
|
DatabaseConnector databaseConnector;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AutoExportAndUpload autoExportAndUpload;
|
ExportAndUploadUtils exportAndUploadUtils;
|
||||||
|
|
||||||
@PostMapping("/exportExcel")
|
@PostMapping("/exportExcel")
|
||||||
public ReturnT<String> exportExcel(@RequestBody JSONObject object) {
|
public ReturnT<String> exportExcel(@RequestBody JSONObject object) {
|
||||||
@ -33,25 +32,37 @@ public class ExportController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/triggerTask")
|
|
||||||
public ReturnT<String> triggerTask() {
|
|
||||||
try {
|
|
||||||
new Thread(() -> autoExportAndUpload.exportDataAndUpload()).start();
|
|
||||||
return new ReturnT<>(200, "", "");
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ReturnT<>(500, e.getMessage(), "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/exportTwitterExcel")
|
@PostMapping("/exportTwitterExcel")
|
||||||
public ReturnT<String> triggerTwitterTask(@RequestBody JSONObject object) {
|
public ReturnT<String> triggerTwitterTask(@RequestBody JSONObject object) {
|
||||||
try {
|
try {
|
||||||
String startTime = object.getString("startTime");
|
String startTime = object.getString("startTime");
|
||||||
new Thread(() -> autoExportAndUpload.exportTwitterDataAndUpload(startTime)).start();
|
databaseConnector.twitterToXlsx(startTime);
|
||||||
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(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/triggerTask")
|
||||||
|
public ReturnT<String> triggerTask() {
|
||||||
|
try {
|
||||||
|
new Thread(() -> exportAndUploadUtils.exportNewsDataAndUpload()).start();
|
||||||
|
return new ReturnT<>(200, "", "");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ReturnT<>(500, e.getMessage(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/triggerTwitterTask")
|
||||||
|
public ReturnT<String> triggerTwitterTask() {
|
||||||
|
try {
|
||||||
|
new Thread(() -> exportAndUploadUtils.exportTwitterDataAndUpload()).start();
|
||||||
|
return new ReturnT<>(200, "", "");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ReturnT<>(500, e.getMessage(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,50 +1,31 @@
|
|||||||
package com.jsc.dsp.task;
|
package com.jsc.dsp.task;
|
||||||
|
|
||||||
import com.jsc.dsp.service.ConfigService;
|
import com.jsc.dsp.utils.ExportAndUploadUtils;
|
||||||
import com.jsc.dsp.utils.AutoExportAndUpload;
|
|
||||||
import com.jsc.dsp.utils.DatabaseConnector;
|
|
||||||
import com.jsc.dsp.utils.FTPConnector;
|
|
||||||
import com.jsc.dsp.utils.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.nio.file.attribute.FileTime;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnProperty(name = "switch.auto-export-and-upload", havingValue = "true", matchIfMissing = true)
|
@ConditionalOnProperty(name = "switch.auto-export-and-upload", havingValue = "true", matchIfMissing = true)
|
||||||
public class AutoUpload {
|
public class AutoUpload {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AutoExportAndUpload autoExportAndUploadComponent;
|
ExportAndUploadUtils exportAndUploadUtils;
|
||||||
|
|
||||||
@Value("${custom.ftpUploadPath}")
|
@Value("${custom.ftpUploadPath}")
|
||||||
String ftpUploadPath;
|
String ftpUploadPath;
|
||||||
|
|
||||||
@Scheduled(cron = "${custom.exportTaskSchedule}")
|
@Scheduled(cron = "${custom.exportNewsTaskSchedule}")
|
||||||
public void exportNewsDataAndUpload() {
|
public void exportNewsDataAndUpload() {
|
||||||
autoExportAndUploadComponent.exportDataAndUpload();
|
exportAndUploadUtils.exportNewsDataAndUpload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "${custom.exportTwitterTaskSchedule}")
|
||||||
|
public void exportTwitterDataAndUpload() {
|
||||||
|
exportAndUploadUtils.exportTwitterDataAndUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,8 +42,11 @@ public class DatabaseConnector {
|
|||||||
@Resource
|
@Resource
|
||||||
EsDataTwitterRepository esDataTwitterRepository;
|
EsDataTwitterRepository esDataTwitterRepository;
|
||||||
|
|
||||||
@Value("${custom.excelOutputPath}")
|
@Value("${custom.newsExcelOutputPath}")
|
||||||
String excelOutputPath;
|
String newsExcelOutputPath;
|
||||||
|
|
||||||
|
@Value("${custom.twitterExcelOutputPath}")
|
||||||
|
String twitterExcelOutputPath;
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ public class DatabaseConnector {
|
|||||||
|
|
||||||
public void exportToXlsx(String startTime) {
|
public void exportToXlsx(String startTime) {
|
||||||
try {
|
try {
|
||||||
Path dirPath = Paths.get(excelOutputPath);
|
Path dirPath = Paths.get(newsExcelOutputPath);
|
||||||
if (!Files.exists(dirPath)) {
|
if (!Files.exists(dirPath)) {
|
||||||
Files.createDirectories(dirPath);
|
Files.createDirectories(dirPath);
|
||||||
}
|
}
|
||||||
@ -179,7 +182,7 @@ public class DatabaseConnector {
|
|||||||
|
|
||||||
public void twitterToXlsx(String startTime) {
|
public void twitterToXlsx(String startTime) {
|
||||||
try {
|
try {
|
||||||
Path dirPath = Paths.get(excelOutputPath);
|
Path dirPath = Paths.get(twitterExcelOutputPath);
|
||||||
if (!Files.exists(dirPath)) {
|
if (!Files.exists(dirPath)) {
|
||||||
Files.createDirectories(dirPath);
|
Files.createDirectories(dirPath);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user