|
@@ -5,8 +5,10 @@ import cn.hutool.core.exceptions.UtilException;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.XmlUtil;
|
|
import cn.hutool.core.util.XmlUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.emato.file.tunnel.common.constant.MessageTypeEnum;
|
|
import com.emato.file.tunnel.config.properties.CPortProperties;
|
|
import com.emato.file.tunnel.config.properties.CPortProperties;
|
|
import com.emato.file.tunnel.config.properties.RabbitMQProperties;
|
|
import com.emato.file.tunnel.config.properties.RabbitMQProperties;
|
|
|
|
+import com.emato.file.tunnel.router.ReceiptMessageRouter;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
@@ -19,6 +21,7 @@ import org.w3c.dom.Document;
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -37,10 +40,9 @@ public class ScanPullDirectoryTask {
|
|
private CPortProperties cPortProperties;
|
|
private CPortProperties cPortProperties;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private RabbitTemplate receiptRabbitTemplate;
|
|
|
|
|
|
+ private ReceiptMessageRouter receiptMessageRouter;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private RabbitMQProperties rabbitMQProperties;
|
|
|
|
|
|
+ private List<String> messageTypeList = Arrays.stream(MessageTypeEnum.values()).map(MessageTypeEnum::getType).collect(Collectors.toList());
|
|
|
|
|
|
@Scheduled(fixedRate = 3000)
|
|
@Scheduled(fixedRate = 3000)
|
|
public void scanDirectory() {
|
|
public void scanDirectory() {
|
|
@@ -57,10 +59,23 @@ public class ScanPullDirectoryTask {
|
|
// 获取回执目录里特定报文的文件名
|
|
// 获取回执目录里特定报文的文件名
|
|
List<String> pullFilePaths = fileNames.parallelStream()
|
|
List<String> pullFilePaths = fileNames.parallelStream()
|
|
.map(fileName -> pullDir + "\\" + fileName)
|
|
.map(fileName -> pullDir + "\\" + fileName)
|
|
- // 过滤出xml格式的和对应回执类型的文件, 回执类型在application.properties可配置
|
|
|
|
- .filter(fileName -> fileName.indexOf("xml") > 0 && fileName.contains(cPortProperties.getReceiptType()))
|
|
|
|
|
|
+ // 过滤出xml格式的
|
|
|
|
+ .filter(fileName -> fileName.indexOf("xml") > 0)
|
|
|
|
+ // 过滤出对应回执类型的文件
|
|
|
|
+ .filter(fileName -> {
|
|
|
|
+ for (String s : messageTypeList) {
|
|
|
|
+ boolean b = fileName.contains(s);
|
|
|
|
+ if (b) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ })
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(pullFilePaths)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
readMessageFile(pullFilePaths, pullDir);
|
|
readMessageFile(pullFilePaths, pullDir);
|
|
|
|
|
|
int size = CollectionUtils.isEmpty(pullFilePaths) ? 0 : pullFilePaths.size();
|
|
int size = CollectionUtils.isEmpty(pullFilePaths) ? 0 : pullFilePaths.size();
|
|
@@ -87,7 +102,7 @@ public class ScanPullDirectoryTask {
|
|
if (file.exists()) {
|
|
if (file.exists()) {
|
|
try (InputStream inputStream = new FileInputStream(file)) {
|
|
try (InputStream inputStream = new FileInputStream(file)) {
|
|
Document document = XmlUtil.readXML(inputStream);
|
|
Document document = XmlUtil.readXML(inputStream);
|
|
- boolean delete = file.delete();
|
|
|
|
|
|
+ boolean deleted;
|
|
String content = XmlUtil.format(document);
|
|
String content = XmlUtil.format(document);
|
|
// 报文回执信息发送给csp
|
|
// 报文回执信息发送给csp
|
|
map.put("fileName", fileName);
|
|
map.put("fileName", fileName);
|
|
@@ -95,10 +110,20 @@ public class ScanPullDirectoryTask {
|
|
Object message = JSONUtil.toJsonStr(map);
|
|
Object message = JSONUtil.toJsonStr(map);
|
|
CorrelationData correlationData = new CorrelationData();
|
|
CorrelationData correlationData = new CorrelationData();
|
|
correlationData.setId(fileName);
|
|
correlationData.setId(fileName);
|
|
- receiptRabbitTemplate.convertAndSend(rabbitMQProperties.getK_normal_tunnel_to_csp_receipt(), message, correlationData);
|
|
|
|
- if (!delete) {
|
|
|
|
- log.error("----- 扫描报文目录, 文件: {}, 删除失败! -----", fileName);
|
|
|
|
|
|
+
|
|
|
|
+ MessageTypeEnum messageTypeEnum = matchType(fileName);
|
|
|
|
+ // 根据回执文件名发送不同队列
|
|
|
|
+ Boolean bool = receiptMessageRouter.router(messageTypeEnum, message, correlationData);
|
|
|
|
+ // 未知的文件类型将不会进行删除
|
|
|
|
+ if (!bool) {
|
|
|
|
+ log.error("----- 未知的回执消息文件类型, 文件名: {}, 文件内容: {} -----", fileName, content);
|
|
|
|
+ } else {
|
|
|
|
+ deleted = file.delete();
|
|
|
|
+ if (!deleted) {
|
|
|
|
+ log.error("----- 扫描报文目录, 文件: {}, 删除失败! -----", fileName);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
} catch (UtilException e) {
|
|
} catch (UtilException e) {
|
|
log.error("----- 扫描报文目录, 解析该文件: {}, 出现错误: {} -----", fileName, e.getMessage());
|
|
log.error("----- 扫描报文目录, 解析该文件: {}, 出现错误: {} -----", fileName, e.getMessage());
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
@@ -110,7 +135,31 @@ public class ScanPullDirectoryTask {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-// @Scheduled(fixedRate = 10000)
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据回执文件名匹配消息类型
|
|
|
|
+ * @param fileName 回执文件名
|
|
|
|
+ * @return 消息类型
|
|
|
|
+ */
|
|
|
|
+ private MessageTypeEnum matchType(String fileName) {
|
|
|
|
+
|
|
|
|
+ if (fileName.contains(MessageTypeEnum.CEB312.getType())) {
|
|
|
|
+ return MessageTypeEnum.CEB312;
|
|
|
|
+ } else if (fileName.contains(MessageTypeEnum.CEB622.getType())) {
|
|
|
|
+ return MessageTypeEnum.CEB622;
|
|
|
|
+ } else if (fileName.contains(MessageTypeEnum.CEB624.getType())) {
|
|
|
|
+ return MessageTypeEnum.CEB624;
|
|
|
|
+ } else if (fileName.contains(MessageTypeEnum.CEB626.getType())) {
|
|
|
|
+ return MessageTypeEnum.CEB626;
|
|
|
|
+ } else if (fileName.contains(MessageTypeEnum.CEB816.getType())) {
|
|
|
|
+ return MessageTypeEnum.CEB816;
|
|
|
|
+ } else {
|
|
|
|
+ log.error("----- 未匹配到【{}】文件的消息类型 -----", fileName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return MessageTypeEnum.UNKNOWN;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // @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" +
|
|
"<configuration>\n" +
|
|
"<configuration>\n" +
|