|
@@ -16,15 +16,17 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
-import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.nokia.common.dingtalk.DingtalkUtil;
|
|
import com.nokia.common.dingtalk.DingtalkUtil;
|
|
import com.nokia.common.ssh.SftpUtil;
|
|
import com.nokia.common.ssh.SftpUtil;
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 投诉清单各地市投诉率
|
|
* 投诉清单各地市投诉率
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class TslTaskService {
|
|
public class TslTaskService {
|
|
|
|
|
|
@@ -56,9 +58,6 @@ public class TslTaskService {
|
|
@Autowired
|
|
@Autowired
|
|
private MessageService messageService;
|
|
private MessageService messageService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private ThreadPoolTaskScheduler taskScheduler;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 定时任务
|
|
* 定时任务
|
|
*/
|
|
*/
|
|
@@ -68,8 +67,8 @@ public class TslTaskService {
|
|
calendar.add(Calendar.DATE, -1);
|
|
calendar.add(Calendar.DATE, -1);
|
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
String day = format.format(calendar.getTime());
|
|
String day = format.format(calendar.getTime());
|
|
- // 30分钟检查一次
|
|
|
|
- checkRemoteDirAndWaitForFileOk(day, 1000L * 60 * 30).thenRun(() -> {
|
|
|
|
|
|
+ // 60分钟检查一次
|
|
|
|
+ checkRemoteDirAndWaitForFileOk(day, 1000L * 60 * 60).thenRun(() -> {
|
|
download(day);
|
|
download(day);
|
|
}).thenRun(() -> {
|
|
}).thenRun(() -> {
|
|
try {
|
|
try {
|
|
@@ -330,7 +329,7 @@ public class TslTaskService {
|
|
*
|
|
*
|
|
* @param day 20230622 样式的表示月份的字符串
|
|
* @param day 20230622 样式的表示月份的字符串
|
|
*/
|
|
*/
|
|
- private void download(String day) {
|
|
|
|
|
|
+ public void download(String day) {
|
|
// 创建SftpUtil
|
|
// 创建SftpUtil
|
|
SftpUtil sftpUtil = getSftpUtil();
|
|
SftpUtil sftpUtil = getSftpUtil();
|
|
String remotePath = remoteDir + day;
|
|
String remotePath = remoteDir + day;
|
|
@@ -356,19 +355,24 @@ public class TslTaskService {
|
|
/**
|
|
/**
|
|
* 检查文件是否存在,如果不存在等待milliseconds毫秒后重新检查,直到文件已存在
|
|
* 检查文件是否存在,如果不存在等待milliseconds毫秒后重新检查,直到文件已存在
|
|
*
|
|
*
|
|
|
|
+ * 这种实现方式不推荐,存在一个会打开很多线程的问题,即每次检查失败都会打开一个新的线程继续检查
|
|
|
|
+ * 所以这里也无法使用固定线程数量的线程池
|
|
|
|
+ *
|
|
* @param day 20230719
|
|
* @param day 20230719
|
|
* @param milliseconds 毫秒数
|
|
* @param milliseconds 毫秒数
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
private CompletableFuture<Void> checkRemoteDirAndWaitForFileOk(String day, Long milliseconds) {
|
|
private CompletableFuture<Void> checkRemoteDirAndWaitForFileOk(String day, Long milliseconds) {
|
|
return CompletableFuture.runAsync(() -> {
|
|
return CompletableFuture.runAsync(() -> {
|
|
checkRemoteDir(day);
|
|
checkRemoteDir(day);
|
|
- }, taskScheduler).handle((result, ex) -> {
|
|
|
|
|
|
+ }).handle((result, ex) -> {
|
|
if (ex != null) {
|
|
if (ex != null) {
|
|
String msg = ex.getMessage();
|
|
String msg = ex.getMessage();
|
|
// 发现文件不存在
|
|
// 发现文件不存在
|
|
if (msg.endsWith("No such file")) {
|
|
if (msg.endsWith("No such file")) {
|
|
// 发送提醒
|
|
// 发送提醒
|
|
|
|
+ log.error("投诉清单各地市投诉率账期 " + day + " 文件未具备,请提醒生产方进行生产。");
|
|
messageService.error("投诉清单各地市投诉率账期 " + day + " 文件未具备,请提醒生产方进行生产。");
|
|
messageService.error("投诉清单各地市投诉率账期 " + day + " 文件未具备,请提醒生产方进行生产。");
|
|
// 等待一段时间
|
|
// 等待一段时间
|
|
sleep(milliseconds);
|
|
sleep(milliseconds);
|
|
@@ -376,6 +380,7 @@ public class TslTaskService {
|
|
return checkRemoteDirAndWaitForFileOk(day, milliseconds).join();
|
|
return checkRemoteDirAndWaitForFileOk(day, milliseconds).join();
|
|
}
|
|
}
|
|
// 其他异常不进行重试
|
|
// 其他异常不进行重试
|
|
|
|
+ log.error("投诉清单各地市投诉率检查 " + day + " 账期文件时发生异常:" + msg);
|
|
messageService.error("投诉清单各地市投诉率检查 " + day + " 账期文件时发生异常:" + msg);
|
|
messageService.error("投诉清单各地市投诉率检查 " + day + " 账期文件时发生异常:" + msg);
|
|
// 重新抛出异常
|
|
// 重新抛出异常
|
|
throw new RuntimeException(ex.getMessage());
|
|
throw new RuntimeException(ex.getMessage());
|
|
@@ -402,13 +407,13 @@ public class TslTaskService {
|
|
/**
|
|
/**
|
|
* 检查文件是否存在
|
|
* 检查文件是否存在
|
|
*
|
|
*
|
|
- * @param month
|
|
|
|
|
|
+ * @param day 20230731 代表某一天的字符串
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- private void checkRemoteDir(String month) {
|
|
|
|
|
|
+ private void checkRemoteDir(String day) {
|
|
SftpUtil sftpUtil = getSftpUtil();
|
|
SftpUtil sftpUtil = getSftpUtil();
|
|
- String remotePath = remoteDir + month;
|
|
|
|
|
|
+ String remotePath = remoteDir + day;
|
|
try {
|
|
try {
|
|
// 连接到sftp服务器
|
|
// 连接到sftp服务器
|
|
sftpUtil.connect();
|
|
sftpUtil.connect();
|