MessageRouterX22.java
4.1 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
package com.sy.service.router;
import com.alibaba.fastjson.JSON;
import com.sy.bwAnalysis.CommandInfoAnalysis;
import com.sy.bwAssist.Message;
import com.sy.mapper.LandRouterConfigDao;
import com.sy.model.GatherInfo;
import com.sy.model.LandBusinessTypeList;
import com.sy.model.LandRouterConfig;
import com.sy.model.CommandInfoX22;
import com.sy.service.CommandLogService;
import com.sy.service.LandBusListService;
import com.sy.service.RedisService;
import com.sy.service.impl.GatherInfoHandle;
import com.sy.socket.CommandClient;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service("X22")
public class MessageRouterX22 implements MessageRouter {
private static final Logger logger = LoggerFactory.getLogger(MessageRouterX22.class);
@Value("${g2.switch}")
private boolean g2Switch;
@Autowired
private RedisService redisService;
@Autowired
private CommandLogService commandLogService;
/**
* 放行的code标识
*/
private static String CODE_RELEASE = "00000000200000000000";
/**
* 金二抬杆指令处理
* 1. 金二通道正常可以接收抬杆指令时,与本地联合验放
* 2. ERROR 或者 金二 TIME_OUT,金二通道异常 接收不到放行指令,使用金二开关,进行本地验放.
* @param message
*/
@Override
public void route(Message message) {
try {
logger.info("处理X22:CommandInfo");
CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis();
CommandInfoX22 commandInfoX22 = commandInfoAnalysis.toJavaBean(message);
if (commandInfoX22!=null){
/**
* 根据SEQNO 读取缓存 确定是否金二指令
*/
GatherInfo gatherInfo = readCacheWithSeqno(commandInfoX22);
//是金二指令
if (gatherInfo!=null){
/**
* 1. 判断指令是否放行
*/
if (commandInfoX22.getCheckResult().equals(CODE_RELEASE)) {
/**
* todo:第一种.收到G2指令直接放行.并记录过卡与流转申请的核销
*/
/**
* 第二种,结合本地指令进行放行.
*/
GatherInfoHandle gatherInfoHandle = new GatherInfoHandle();
gatherInfoHandle.handel(gatherInfo);
}else {
/**
* 是金二指令,但是是未放行指令
* 记录未放行原因.
* 通知卡口
*/
CommandClient.Client(gatherInfo,commandInfoX22.getOpHint());
record(gatherInfo,false,gatherInfo.getSeqno()+"金二验放失败:"+commandInfoX22.getOpHint(),null);
}
}
}
}catch (Exception e){
logger.error("[X22-ERROR]:",e);
}
}
/**
* 读取X21信息,如果走金二,KEY 为SEQN_NO
* @param info X22实体
* @return X21实体.
*/
private GatherInfo readCacheWithSeqno(CommandInfoX22 info){
if (info!=null && StringUtils.isNotEmpty(info.getSeqNo())) {
String X21_GatherInfo = redisService.get(info.getSeqNo());
if (StringUtils.isNotEmpty(X21_GatherInfo)){
GatherInfo gatherInfo = JSON.parseObject(X21_GatherInfo, GatherInfo.class);
return gatherInfo;
}
}
return null;
}
/**
* 车辆过卡指令日志记录
*/
private void record(GatherInfo info,boolean result,String reason,LandBusinessTypeList landBusinessTypeList){
commandLogService.commandlog(info,result,reason,landBusinessTypeList,null,0.0,0.0,0.0,0.0);
}
}