|
@@ -0,0 +1,439 @@
|
|
|
|
+package com.nokia.dingtalk_auto.service;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.nokia.common.dingtalk.DingtalkUtil;
|
|
|
|
+import com.nokia.common.ssh.SftpUtil;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 投诉清单各地市投诉率
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class TslTaskService {
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.remoteDir}")
|
|
|
|
+ private String remoteDir;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.localDir}")
|
|
|
|
+ private String localDir;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.remoteHost}")
|
|
|
|
+ private String remoteHost;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.remotePort}")
|
|
|
|
+ private int remotePort;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.remoteUser}")
|
|
|
|
+ private String remoteUser;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.remotePassword}")
|
|
|
|
+ private String remotePassword;
|
|
|
|
+
|
|
|
|
+ @Value("${tsxt.tsl.openConversationId}")
|
|
|
|
+ private String openConversationId;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ @Qualifier("tsxtDingtalkUtil")
|
|
|
|
+ private DingtalkUtil dingtalkUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MessageService messageService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ThreadPoolTaskScheduler taskScheduler;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 定时任务
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 0 14 * * *")
|
|
|
|
+ public void cronTask() {
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
+ String day = format.format(calendar.getTime());
|
|
|
|
+ // 30分钟检查一次
|
|
|
|
+ checkRemoteDirAndWaitForFileOk(day, 1000L * 60 * 30).thenRun(() -> {
|
|
|
|
+ download(day);
|
|
|
|
+ }).thenRun(() -> {
|
|
|
|
+ try {
|
|
|
|
+ sendDingTalkMsg(day);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }).exceptionally(ex -> {
|
|
|
|
+ // 处理异常--发送提醒并重新抛出异常
|
|
|
|
+ messageService.error(ex.getMessage());
|
|
|
|
+ throw new RuntimeException(ex.getMessage());
|
|
|
|
+ }).join();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 手动发送
|
|
|
|
+ *
|
|
|
|
+ * @param day 20230607 样式的表示日期的字符串
|
|
|
|
+ */
|
|
|
|
+ public void runTaskManually(String day) {
|
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
|
+ download(day);
|
|
|
|
+ }).thenRun(() -> {
|
|
|
|
+ try {
|
|
|
|
+ sendDingTalkMsg(day);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }).exceptionally(ex -> {
|
|
|
|
+ // 处理异常--发送提醒并重新抛出异常
|
|
|
|
+ messageService.error(ex.getMessage());
|
|
|
|
+ throw new RuntimeException(ex.getMessage());
|
|
|
|
+ }).join();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 撤回消息
|
|
|
|
+ *
|
|
|
|
+ * @param messageId
|
|
|
|
+ */
|
|
|
|
+ public void recallMessage(List<String> messageIdList) {
|
|
|
|
+ dingtalkUtil.recallMessage(openConversationId, messageIdList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 撤回消息
|
|
|
|
+ *
|
|
|
|
+ * @param messageId
|
|
|
|
+ */
|
|
|
|
+ public void recallMessage(String messageId) {
|
|
|
|
+ dingtalkUtil.recallMessage(openConversationId, messageId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void sendDingTalkMsg(String day) throws Exception {
|
|
|
|
+ String msg = getMessageToSend(day);
|
|
|
|
+ List<String> messageIds = new ArrayList<>();
|
|
|
|
+ String title = "投诉清单各地市投诉率" + day;
|
|
|
|
+ String messageId0 = dingtalkUtil.sendMarkdown(openConversationId, msg, title);
|
|
|
|
+ messageIds.add(messageId0);
|
|
|
|
+ String localPath = localDir + "/" + day;
|
|
|
|
+ File[] files = new File(localPath).listFiles();
|
|
|
|
+
|
|
|
|
+ // 分开发送,保证发送文件的顺序
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-1-投诉率.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-2-客户端-战略考核.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-3-重复投诉率.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-4-超时工单.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-5-处理时长.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-6-满意率.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-7-解决率.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().endsWith("-8-响应率.png")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "image");
|
|
|
|
+ String messageId = dingtalkUtil.sendImage(openConversationId, mediaId);
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ if (file.getName().toLowerCase().equals("投诉清单各地市投诉率" + day + ".xlsx")) {
|
|
|
|
+ String mediaId = dingtalkUtil.upload(file.getAbsolutePath(), "file");
|
|
|
|
+ String messageId = dingtalkUtil.sendFile(openConversationId, mediaId, file.getName());
|
|
|
|
+ messageIds.add(messageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ messageService.message(String.format("投诉清单各地市投诉率 %s 账期 完成发送 ==消息id: %s", day, messageIds));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据要求组织一段话
|
|
|
|
+ *
|
|
|
|
+ * @param day
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private String getMessageToSend(String day) throws Exception {
|
|
|
|
+ String localPath = localDir + "/" + day + "/";
|
|
|
|
+ String localFile = localPath + "投诉清单各地市投诉率" + day + ".xlsx";
|
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(new SimpleDateFormat("yyyyMMdd").parse(day));
|
|
|
|
+ int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
|
+ stringBuffer.append(calendar.get(Calendar.YEAR))
|
|
|
|
+ .append("年")
|
|
|
|
+ .append(calendar.get(Calendar.MONTH) + 1)
|
|
|
|
+ .append("月截至")
|
|
|
|
+ .append(dayOfMonth)
|
|
|
|
+ .append("日移动网投诉情况统计:\n\n管理端-移网质量类:");
|
|
|
|
+ File file = new File(localFile);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ throw new Exception(String.format("文件--%s--不存在", localFile));
|
|
|
|
+ }
|
|
|
|
+ try (Workbook workbook = WorkbookFactory.create(file)) {
|
|
|
|
+ Sheet sheet = workbook.getSheet("管理端-移网质量类");
|
|
|
|
+ Row row;
|
|
|
|
+ List<List<Object>> list = new ArrayList<>();
|
|
|
|
+ List<List<Object>> list0 = new ArrayList<>();
|
|
|
|
+ for (int i = 2; i < 14; i++) {
|
|
|
|
+ row = sheet.getRow(i);
|
|
|
|
+ double value = row.getCell(dayOfMonth + 6).getNumericCellValue();
|
|
|
|
+ List<Object> list2 = new ArrayList<>();
|
|
|
|
+ list2.add(0, value);
|
|
|
|
+ list2.add(1, row.getCell(dayOfMonth + 7).getStringCellValue());
|
|
|
|
+ if (value > 0.0) {
|
|
|
|
+ list.add(list2);
|
|
|
|
+ }
|
|
|
|
+ list0.add(list2);
|
|
|
|
+ }
|
|
|
|
+ // 排序
|
|
|
|
+ list.sort((o1, o2) -> Double.compare((double) o2.get(0), (double) o1.get(0)));
|
|
|
|
+ list0.sort((o1, o2) -> Double.compare((double) o2.get(0), (double) o1.get(0)));
|
|
|
|
+ if (list.size() == 0) {
|
|
|
|
+ stringBuffer.append("投诉率:12个地市均已达标,<font color=#FF0000>");
|
|
|
|
+ } else {
|
|
|
|
+ stringBuffer.append("投诉率:<font color=#FF0000>");
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ stringBuffer.append(list.get(i).get(1).toString()).append("、");
|
|
|
|
+ }
|
|
|
|
+ stringBuffer.deleteCharAt(stringBuffer.length() - 1);
|
|
|
|
+ stringBuffer.append("</font>未达到目标值,<font color=#FF0000>");
|
|
|
|
+ }
|
|
|
|
+ StringBuffer stringBuffer2 = new StringBuffer();
|
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
|
+ stringBuffer2.append(list0.get(i).get(1).toString()).append("、");
|
|
|
|
+ }
|
|
|
|
+ stringBuffer2.deleteCharAt(stringBuffer2.length() - 1);
|
|
|
|
+ stringBuffer.append(stringBuffer2.toString()).append("</font>排名靠后");
|
|
|
|
+
|
|
|
|
+ // 1号忽略重复投诉率
|
|
|
|
+ if (day.endsWith("01")) {
|
|
|
|
+ stringBuffer.append("。\n\n客户端-移网网络体验:投诉问题解决满意率:<font color=#FF0000>");
|
|
|
|
+ } else {
|
|
|
|
+ stringBuffer.append(";重复投诉率:<font color=#FF0000>");
|
|
|
|
+ sheet = workbook.getSheet("管理端-重复投诉率");
|
|
|
|
+ stringBuffer.append(sheet.getRow(3).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(4).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(5).getCell(0).getStringCellValue())
|
|
|
|
+ .append("</font>增长较快。\n\n客户端-移网网络体验:投诉问题解决满意率:<font color=#FF0000>");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sheet = workbook.getSheet("客户端-投诉问题解决满意度");
|
|
|
|
+ stringBuffer.append(sheet.getRow(13).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(12).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(11).getCell(0).getStringCellValue())
|
|
|
|
+ .append("</font>较低,与达标值差距较大;投诉问题解决率:<font color=#FF0000>");
|
|
|
|
+
|
|
|
|
+ sheet = workbook.getSheet("客户端-投诉问题解决率");
|
|
|
|
+ stringBuffer.append(sheet.getRow(13).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(12).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(11).getCell(0).getStringCellValue())
|
|
|
|
+ .append("</font>较低,与达标值差距较大;投诉问题响应率:<font color=#FF0000>");
|
|
|
|
+
|
|
|
|
+ sheet = workbook.getSheet("客户端-投诉问题响应率");
|
|
|
|
+ stringBuffer.append(sheet.getRow(13).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(12).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(11).getCell(0).getStringCellValue())
|
|
|
|
+ .append("</font>较低,与达标值差距较大。\n\n投诉处理时长、超时工单概况:超时工单:<font color=#FF0000>");
|
|
|
|
+
|
|
|
|
+ sheet = workbook.getSheet("投诉处理时长、超时工单概况");
|
|
|
|
+ stringBuffer.append(sheet.getRow(2).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(3).getCell(0).getStringCellValue()).append("、")
|
|
|
|
+ .append(sheet.getRow(4).getCell(0).getStringCellValue())
|
|
|
|
+ .append("</font>分公司超时工单占比较高,<font color=#FF0000>");
|
|
|
|
+ list = new ArrayList<>();
|
|
|
|
+ for (int i = 2; i < 14; i++) {
|
|
|
|
+ List<Object> list2 = new ArrayList<>();
|
|
|
|
+ list.add(list2);
|
|
|
|
+ list2.add(0, sheet.getRow(i).getCell(2).getNumericCellValue());
|
|
|
|
+ list2.add(1, sheet.getRow(i).getCell(0).getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ list.sort((o1, o2) -> Double.compare((double) o2.get(0), (double) o1.get(0)));
|
|
|
|
+ stringBuffer.append(list.get(0).get(1).toString()).append("、")
|
|
|
|
+ .append(list.get(1).get(1).toString()).append("、")
|
|
|
|
+ .append(list.get(2).get(1).toString())
|
|
|
|
+ .append("</font>超时工单数量较多。平均处理时长:本月相对较长的地市为<font color=#FF0000>");
|
|
|
|
+
|
|
|
|
+ list = new ArrayList<>();
|
|
|
|
+ for (int i = 2; i < 14; i++) {
|
|
|
|
+ List<Object> list2 = new ArrayList<>();
|
|
|
|
+ list.add(list2);
|
|
|
|
+ list2.add(0, sheet.getRow(i).getCell(8).getNumericCellValue());
|
|
|
|
+ list2.add(1, sheet.getRow(i).getCell(6).getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ list.sort((o1, o2) -> Double.compare((double) o2.get(0), (double) o1.get(0)));
|
|
|
|
+ stringBuffer.append(list.get(0).get(1).toString()).append("、")
|
|
|
|
+ .append(list.get(1).get(1).toString()).append("、")
|
|
|
|
+ .append(list.get(2).get(1).toString()).append("</font>;与")
|
|
|
|
+ .append(sheet.getRow(1).getCell(7).getStringCellValue()).append("比<font color=#FF0000>")
|
|
|
|
+ .append(sheet.getRow(2).getCell(6).getStringCellValue()).append("</font>时长增幅较大。");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return stringBuffer.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 下载文件,根据给出的月份字符串拼接远端路径,把文件下载到本地。
|
|
|
|
+ *
|
|
|
|
+ * @param day 20230622 样式的表示月份的字符串
|
|
|
|
+ */
|
|
|
|
+ private void download(String day) {
|
|
|
|
+ // 创建SftpUtil
|
|
|
|
+ SftpUtil sftpUtil = getSftpUtil();
|
|
|
|
+ String remotePath = remoteDir + day;
|
|
|
|
+ String localPath = localDir + day;
|
|
|
|
+ File localFile = new File(localPath);
|
|
|
|
+ if (!localFile.exists()) {
|
|
|
|
+ localFile.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ // 连接到sftp服务器
|
|
|
|
+ sftpUtil.connect();
|
|
|
|
+ List<String> files = sftpUtil.ls(remotePath);
|
|
|
|
+ for (String fileName : files) {
|
|
|
|
+ sftpUtil.get(remotePath + "/" + fileName, localPath + "/" + fileName);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ sftpUtil.disconnect();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检查文件是否存在,如果不存在等待milliseconds毫秒后重新检查,直到文件已存在
|
|
|
|
+ *
|
|
|
|
+ * @param day 20230719
|
|
|
|
+ * @param milliseconds 毫秒数
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private CompletableFuture<Void> checkRemoteDirAndWaitForFileOk(String day, Long milliseconds) {
|
|
|
|
+ return CompletableFuture.runAsync(() -> {
|
|
|
|
+ checkRemoteDir(day);
|
|
|
|
+ }, taskScheduler).handle((result, ex) -> {
|
|
|
|
+ if (ex != null) {
|
|
|
|
+ String msg = ex.getMessage();
|
|
|
|
+ // 发现文件不存在
|
|
|
|
+ if (msg.endsWith("No such file")) {
|
|
|
|
+ // 发送提醒
|
|
|
|
+ messageService.error("投诉清单各地市投诉率账期 " + day + " 文件未具备,请提醒生产方进行生产。");
|
|
|
|
+ // 等待一段时间
|
|
|
|
+ sleep(milliseconds);
|
|
|
|
+ // 重新检查
|
|
|
|
+ return checkRemoteDirAndWaitForFileOk(day, milliseconds).join();
|
|
|
|
+ }
|
|
|
|
+ // 其他异常不进行重试
|
|
|
|
+ messageService.error("投诉清单各地市投诉率检查 " + day + " 账期文件时发生异常:" + msg);
|
|
|
|
+ // 重新抛出异常
|
|
|
|
+ throw new RuntimeException(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+ // 没有异常时直接返回结果
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 等待一段时间
|
|
|
|
+ *
|
|
|
|
+ * @param milliseconds 等待的毫秒数
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private void sleep(Long milliseconds) {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(milliseconds);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检查文件是否存在
|
|
|
|
+ *
|
|
|
|
+ * @param month
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private void checkRemoteDir(String month) {
|
|
|
|
+ SftpUtil sftpUtil = getSftpUtil();
|
|
|
|
+ String remotePath = remoteDir + month;
|
|
|
|
+ try {
|
|
|
|
+ // 连接到sftp服务器
|
|
|
|
+ sftpUtil.connect();
|
|
|
|
+ // ls如果路径不存在会触发RuntimeException,携带消息No such file
|
|
|
|
+ List<String> files = sftpUtil.ls(remotePath);
|
|
|
|
+ if (files.size() == 0) {
|
|
|
|
+ // 如果路径存在,但路径下没有文件,抛出RuntimeException,携带消息No such file
|
|
|
|
+ throw new RuntimeException("No such file");
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ sftpUtil.disconnect();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取Sftp连接工具SftpUtil
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private SftpUtil getSftpUtil() {
|
|
|
|
+ // 创建SftpUtil
|
|
|
|
+ return new SftpUtil()
|
|
|
|
+ .setHost(remoteHost)
|
|
|
|
+ .setPort(remotePort)
|
|
|
|
+ .setUser(remoteUser)
|
|
|
|
+ .setPassword(remotePassword);
|
|
|
|
+ }
|
|
|
|
+}
|