RadioMsgController.java
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.tianbo.analysis.controller;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
/**
* 在线报文导入管理
*/
@RestController
@RequestMapping("/Rmsg")
@Slf4j
public class RadioMsgController {
//备份目录
@Value("${custom.extRedioMsgDir}")
private String extRedioMsgDir;
//系统类型
@Value("${custom.operationSystemType}")
private String operationSystemType;
private final static String FFM_HEADER = "<MSG>\n" +
"<META>\r\n" +
"<SNDR>TXD</SNDR>\n" +
"<DDTM>20200113050339</DDTM>\n" +
"<TYPE>IATA</TYPE>\n" +
"<STYP>FFM</STYP>\n" +
"<SEQN>95205940</SEQN>\n" +
"</META>\n" +
"<FFM>\n";
private final static String FFM_FOOTER = "\n</FFM>\n" +
"</MSG>";
private final static String FWB_HEADER="<MSG>\n" +
"<META>\n" +
"<SNDR>TXD</SNDR>\n" +
"<DDTM>20200113004608</DDTM>\n" +
"<TYPE>IATA</TYPE>\n" +
"<STYP>IFWB</STYP>\n" +
"<SEQN>95203026</SEQN>\n" +
"</META>\n" +
"<FWB>\n";
private final static String FWB_FOOTER="\n</FWB>\n" +
"</MSG>";
private final static String FHL_HEADER="<MSG>\n" +
"<META>\n" +
"<SNDR>TXD</SNDR>\n" +
"<DDTM>20200113003006</DDTM>\n" +
"<TYPE>IATA</TYPE>\n" +
"<STYP>IFHL</STYP>\n" +
"<SEQN>95202782</SEQN>\n" +
"</META>\n" +
"<FHL>\n";
private final static String FHL_FOOTER="\n</FHL>\n" +
"</MSG>";
@GetMapping("ffm")
public int extFFM(String ffmmsg){
if (ffmmsg!=null){
ffmmsg = FFM_HEADER + ffmmsg;
ffmmsg = ffmmsg + FFM_FOOTER;
File file = new File(extRedioMsgDir+UUID.randomUUID()+".txt");
try {
ffmmsg = redioStrFilter(ffmmsg);
FileUtils.writeStringToFile(file,ffmmsg,"UTF-8");
log.info("FFM报文导入成功");
return 1;
}catch (IOException e){
e.printStackTrace();
}
}
return 0;
}
@GetMapping("fwb")
public int extFWB(String ffmmsg){
if (ffmmsg!=null) {
ffmmsg = FWB_HEADER + ffmmsg;
ffmmsg = ffmmsg + FWB_FOOTER;
File file = new File(extRedioMsgDir + UUID.randomUUID() + ".txt");
try {
ffmmsg = redioStrFilter(ffmmsg);
FileUtils.writeStringToFile(file, ffmmsg, "UTF-8");
log.info("FWB报文导入成功");
return 1;
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
@GetMapping("fhl")
public int extFHL(String ffmmsg){
if (ffmmsg!=null) {
ffmmsg = FHL_HEADER + ffmmsg;
ffmmsg = ffmmsg + FHL_FOOTER;
File file = new File(extRedioMsgDir + UUID.randomUUID() + ".txt");
try {
ffmmsg = redioStrFilter(ffmmsg);
FileUtils.writeStringToFile(file, ffmmsg, "UTF-8");
log.info("FHL报文导入成功");
return 1;
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
/**
* 过滤处理不同操作系统的换行符
* @param content
* @return
*/
private String redioStrFilter(String content){
if ("windows".equals(operationSystemType)){
/**
* 如果用户端的操作系统是windows,那么传过来的报文内容的换行符是\r\n,
* 先删除文本中过来的\r,再统一替换成\r\n.
* 如果用户端的操作系统是linux,则无所谓
*/
content = content.replaceAll("\\r?\\n","\r\n");
}
return content;
}
}