IMFSaveHandle.java
3.6 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
package com.tianbo.warehouse.handle;
import com.tianbo.warehouse.model.T_ETL_MESSAGE;
import com.tianbo.warehouse.service.T_ETL_MESSAGEService;
import com.tianbo.warehouse.util.Date.DateUtil;
import com.tianbo.warehouse.util.IO.FileTool;
import com.tianbo.warehouse.util.XML.XMLXPath;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Date;
/**
* 存储IMF过来的原始报文到数据仓库T_ELT_MESSAGE原始报文表中
*/
@Component
public class IMFSaveHandle {
@Autowired
protected T_ETL_MESSAGEService messageService;
private static IMFSaveHandle saveHandle;
public final static String SNDR = "//MSG/META/SNDR";
public final static String RCVR = "//MSG/META/RCVR";
public final static String DDTM = "//MSG/META/DDTM";
public final static String TYPE = "//MSG/META/TYPE";
public final static String STYP = "//MSG/META/STYP";
public final static String SEQN = "//MSG/META/SEQN";
protected static final Logger logger = Logger.getLogger(IMFSaveHandle.class);
@PostConstruct
public void init(){
saveHandle = this;
saveHandle.messageService = this.messageService;
}
public void handle(String xmlmessage){
try {
//有人发报文头部不按规范发
xmlmessage = xmlmessage.replace("<Msg>","<MSG>")
.replace("<msg>","<MSG>")
.replace("</Msg>","</MSG>")
.replace("</msg>","</MSG>");
Document document = DocumentHelper.parseText(xmlmessage);
T_ETL_MESSAGE message = new T_ETL_MESSAGE();
String sndrm = XMLXPath.getSingleValueByPath(document,SNDR);
String typem = XMLXPath.getSingleValueByPath(document,TYPE);
String stypm = XMLXPath.getSingleValueByPath(document,STYP);
if ("TXD".equals(sndrm)){
if("EDEP".equals(stypm)
|| "EFOH".equals(stypm)
|| "ERCF".equals(stypm)
|| "PFFM".equals(stypm)
|| "UDEP".equals(stypm)
|| "UFOH".equals(stypm)
|| "URCF".equals(stypm)
|| "FFM".equals(stypm)
|| "IFWB".equals(stypm)
|| "IFHL".equals(stypm)){
//存储至备份目录
FileTool.writeFileToBak(xmlmessage);
}
}
message.setSndr(sndrm);
message.setRcvr(XMLXPath.getSingleValueByPath(document,RCVR));
message.setType(typem);
message.setStyp(stypm);
message.setSeqn(XMLXPath.getSingleValueByPath(document,SEQN));
String ddtm = XMLXPath.getSingleValueByPath(document,DDTM);
Date ddtmDate = DateUtil.formatByyyyyMMddHHmmss(ddtm);
message.setDdtm(ddtmDate);
message.setSntm(ddtmDate);
message.setOper("ALL");
message.setAppid("W");
message.setEtltim(new Date());
message.setContent(xmlmessage);
int i = saveHandle.messageService.insertSelective(message);
}catch (Exception e){
FileTool.writeFile("err",e.toString()+"\n"+xmlmessage,false);
logger.warn("*报文入库失败已存储成备份文件*");
logger.error(e);
logger.warn(e);
}
}
}