X82ServiceImpl.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
package com.sy.service.impl;
import com.alibaba.fastjson.JSON;
import com.sy.model.DxpMsg;
import com.sy.model.GatherInfo;
import com.sy.model.X82Feedback;
import com.sy.service.CommandLogService;
import com.sy.service.RedisService;
import com.sy.service.X82Service;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Service
@Slf4j
public class X82ServiceImpl implements X82Service {
@Autowired
private RedisService redisService;
@Autowired
private CommandLogService commandLogService;
@Override
public DxpMsg analysis(String response) {
XStream xstream = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("_-", "_")));
xstream.processAnnotations(DxpMsg.class);
//对xstream对象设置默认的安全防护
XStream.setupDefaultSecurity(xstream);
//对xstream对象设置默认的安全防护时,允许设置类
xstream.allowTypes(new Class[]{DxpMsg.class});
return (DxpMsg) xstream.fromXML(response);
}
@Override
public X82Feedback x82Analysis(String xml) {
XStream xstream = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("_-", "_")));
xstream.processAnnotations(X82Feedback.class);
//对xstream对象设置默认的安全防护
XStream.setupDefaultSecurity(xstream);
//对xstream对象设置默认的安全防护时,允许设置类
xstream.allowTypes(new Class[]{X82Feedback.class});
return (X82Feedback) xstream.fromXML(xml);
}
@Override
public Boolean X82ReleaseCheck(X82Feedback var) {
log.info("[X82-Result]金二验放结果-{}-{}",var.getCheckResult(),var.getOpHint());
if ("Y".equals(var.getCheckResult().trim()) || "1".equals(var.getCheckResult().trim())) {
return true;
}
return false;
}
/**
* 根据seqno 获取缓存的X21信息
* @param seqno
* @return x21的gatherInfo
*/
@Override
public GatherInfo readCacheWithSeqno(String seqno){
if (StringUtils.isNotEmpty(seqno)) {
String X21_GatherInfo = redisService.get(seqno);
if (StringUtils.isNotEmpty(X21_GatherInfo)){
GatherInfo gatherInfo = JSON.parseObject(X21_GatherInfo, GatherInfo.class);
return gatherInfo;
}
}
return null;
}
@Override
public GatherInfo X82FeedBackToX21GatherInfo(X82Feedback var) {
GatherInfo gatherInfo = new GatherInfo();
gatherInfo.setAreaid(var.getAreaId());
gatherInfo.setChnlno(var.getChannelNo());
gatherInfo.setSeqno(var.getSessionId());
return gatherInfo;
}
public static class DateConverter implements Converter {
private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSXXX";
private final SimpleDateFormat dateFormat;
public DateConverter() {
this.dateFormat = new SimpleDateFormat(DATE_FORMAT);
}
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
// Not used for unmarshalling
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String dateString = reader.getValue();
try {
return dateFormat.parse(dateString);
} catch (ParseException e) {
throw new IllegalArgumentException("Error parsing date string: " + dateString, e);
}
}
@Override
public boolean canConvert(Class aClass) {
return aClass.equals(Date.class);
}
}
}