IMFSaveHandle.java
2.5 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
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 {
Document document = DocumentHelper.parseText(xmlmessage);
T_ETL_MESSAGE message = new T_ETL_MESSAGE();
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.setSndr(XMLXPath.getSingleValueByPath(document,SNDR));
message.setRcvr(XMLXPath.getSingleValueByPath(document,RCVR));
message.setType(XMLXPath.getSingleValueByPath(document,TYPE));
message.setStyp(XMLXPath.getSingleValueByPath(document,STYP));
message.setSeqn(XMLXPath.getSingleValueByPath(document,SEQN));
message.setContent(xmlmessage);
int i = saveHandle.messageService.insertSelective(message);
}catch (Exception e){
FileTool.writeFile("err",xmlmessage,false);
logger.warn("*报文入库失败已存储成备份文件*");
logger.error(e);
logger.warn(e);
}
}
}