|
@@ -56,48 +56,8 @@ public class ScanPullDirectoryTask {
|
|
}
|
|
}
|
|
// 获取回执目录的所有文件名
|
|
// 获取回执目录的所有文件名
|
|
List<String> pullFilePaths = fileNames.parallelStream().map(fileName -> pullDir + "\\" + fileName).filter(fileName -> fileName.indexOf("xml") > 0 && fileName.contains("CEB622Message")).collect(Collectors.toList());
|
|
List<String> pullFilePaths = fileNames.parallelStream().map(fileName -> pullDir + "\\" + fileName).filter(fileName -> fileName.indexOf("xml") > 0 && fileName.contains("CEB622Message")).collect(Collectors.toList());
|
|
- if (CollectionUtils.isEmpty(pullFilePaths)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- log.info("----- 扫描报文目录, 开始扫描目录: {} -----", pullDir);
|
|
|
|
- pullFilePaths.forEach(pullFilePath -> {
|
|
|
|
- File file = FileUtil.file(pullFilePath);
|
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
|
- String fileName = file.getName();
|
|
|
|
- InputStream inputStream = null;
|
|
|
|
- try {
|
|
|
|
- if (file.exists()) {
|
|
|
|
- inputStream = new FileInputStream(file);
|
|
|
|
- Document document = XmlUtil.readXML(inputStream);
|
|
|
|
- boolean delete = file.delete();
|
|
|
|
- String content = XmlUtil.format(document);
|
|
|
|
- // 报文回执信息发送给csp
|
|
|
|
- map.put("fileName", fileName);
|
|
|
|
- map.put("fileContent", content);
|
|
|
|
- Object message = JSONUtil.toJsonStr(map);
|
|
|
|
- CorrelationData correlationData = new CorrelationData();
|
|
|
|
- correlationData.setId(fileName);
|
|
|
|
- receiptRabbitTemplate.convertAndSend(rabbitMQProperties.getK_normal_tunnel_to_csp_receipt(), message, correlationData);
|
|
|
|
- if (!delete) {
|
|
|
|
- log.error("----- 扫描报文目录, 文件: {}, 删除失败! -----", fileName);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (UtilException e) {
|
|
|
|
- log.error("----- 扫描报文目录, 解析该文件: {}, 出现错误: {} -----", fileName, e.getMessage());
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- log.error("----- 扫描报文目录, 文件【{}】不存在! -----", pullFilePath);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error(String.format("----- 扫描报文目录, 未知异常: %s -----", e));
|
|
|
|
- } finally {
|
|
|
|
- if (null != inputStream) {
|
|
|
|
- try {
|
|
|
|
- inputStream.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ writeMessageFile(pullFilePaths, pullDir);
|
|
|
|
|
|
int size = CollectionUtils.isEmpty(pullFilePaths) ? 0 : pullFilePaths.size();
|
|
int size = CollectionUtils.isEmpty(pullFilePaths) ? 0 : pullFilePaths.size();
|
|
log.info("----- 扫描报文目录, 扫描目录完成, 回执文件共 {} 个 -----", size);
|
|
log.info("----- 扫描报文目录, 扫描目录完成, 回执文件共 {} 个 -----", size);
|
|
@@ -106,6 +66,51 @@ public class ScanPullDirectoryTask {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void writeMessageFile (List<String> pullFilePaths, String pullDir) {
|
|
|
|
+ if (CollectionUtils.isEmpty(pullFilePaths)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log.info("----- 扫描报文目录, 开始扫描目录: {} -----", pullDir);
|
|
|
|
+ pullFilePaths.forEach(pullFilePath -> {
|
|
|
|
+ File file = FileUtil.file(pullFilePath);
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
+ String fileName = file.getName();
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ try {
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ inputStream = new FileInputStream(file);
|
|
|
|
+ Document document = XmlUtil.readXML(inputStream);
|
|
|
|
+ boolean delete = file.delete();
|
|
|
|
+ String content = XmlUtil.format(document);
|
|
|
|
+ // 报文回执信息发送给csp
|
|
|
|
+ map.put("fileName", fileName);
|
|
|
|
+ map.put("fileContent", content);
|
|
|
|
+ Object message = JSONUtil.toJsonStr(map);
|
|
|
|
+ CorrelationData correlationData = new CorrelationData();
|
|
|
|
+ correlationData.setId(fileName);
|
|
|
|
+ receiptRabbitTemplate.convertAndSend(rabbitMQProperties.getK_normal_tunnel_to_csp_receipt(), message, correlationData);
|
|
|
|
+ if (!delete) {
|
|
|
|
+ log.error("----- 扫描报文目录, 文件: {}, 删除失败! -----", fileName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (UtilException e) {
|
|
|
|
+ log.error("----- 扫描报文目录, 解析该文件: {}, 出现错误: {} -----", fileName, e.getMessage());
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ log.error("----- 扫描报文目录, 文件【{}】不存在! -----", pullFilePath);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(String.format("----- 扫描报文目录, 未知异常: %s -----", e));
|
|
|
|
+ } finally {
|
|
|
|
+ if (null != inputStream) {
|
|
|
|
+ try {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
// @Scheduled(fixedRate = 10000)
|
|
// @Scheduled(fixedRate = 10000)
|
|
public void sendCEB621 (int size) {
|
|
public void sendCEB621 (int size) {
|
|
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|