MessageRouterX22.java
4.9 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
package com.sy.service.router;
import com.alibaba.fastjson.JSON;
import com.sy.bwAnalysis.CommandInfoAnalysis;
import com.sy.bwAssist.Message;
import com.sy.model.G2Bean;
import com.sy.model.GatherInfo;
import com.sy.model.LandBusinessTypeList;
import com.sy.model.CommandInfoX22;
import com.sy.service.CommandLogService;
import com.sy.service.RedisService;
import com.sy.service.impl.GatherInfoHandle;
import com.sy.socket.CommandClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("X22")
@Slf4j
public class MessageRouterX22 implements MessageRouter {
/**
* 金二与本地认证兼容性开关
* Y 是金二业务必须走金二
* N 车辆扫二维码或本地和金二都可进出区验放
*/
@Autowired
private G2Bean g2Bean;
@Autowired
private RedisService redisService;
@Autowired
private CommandLogService commandLogService;
/**
* 放行的code标识
*/
private static String CODE_RELEASE_I = "00000000200000000000";
private static String CODE_RELEASE_E = "00000000100000000000";
/**
* 金二抬杆指令处理
* 1. 金二通道正常可以接收抬杆指令时,与本地联合验放
* 2. ERROR 或者 金二 TIME_OUT,金二通道异常 接收不到放行指令,使用金二开关,进行本地验放.
* @param message
*/
@Override
public void route(Message message) {
try {
log.info("[X22]-处理CommandInfo;\n[switch]-G2开关状态:[{}]",g2Bean.getOnoff());
CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis();
CommandInfoX22 commandInfoX22 = commandInfoAnalysis.toJavaBean(message);
/**
* 如果金二验放关闭,则不用再处理X22指令报文.
*/
if (g2Bean.getOnoff()) {
if (commandInfoX22!=null){
/**
* 根据SEQNO 读取缓存 确定是否金二指令
*/
GatherInfo gatherInfo = readCacheWithSeqno(commandInfoX22);
//是金二指令
if (gatherInfo!=null && gatherInfo.getChnlno().equals(commandInfoX22.getChnlNo())){
/**
* 1. 判断指令是否放行
*/
if (commandInfoX22.getCheckResult().equals(CODE_RELEASE_I) || commandInfoX22.getCheckResult().equals(CODE_RELEASE_E)) {
/**
* todo:第一种.收到G2指令直接放行.并记录过卡与流转申请的核销
*/
/**
* 第二种,结合本地指令进行放行.
*/
record(gatherInfo,true,commandInfoX22.getOpHint(),null);
GatherInfoHandle gatherInfoHandle = new GatherInfoHandle();
gatherInfoHandle.handel(gatherInfo);
return;
}else {
/**
* 是金二指令,但是是未放行指令
* 记录未放行原因.
* 通知卡口
*/
CommandClient.Client(gatherInfo,commandInfoX22.getOpHint());
record(gatherInfo,false,gatherInfo.getSeqno()+"-金二验放失败:"+commandInfoX22.getOpHint(),null);
}
}
else{
log.info("[X22-ERROR]:未找到对应的SEQNO:[{}]及通道的过卡缓存数据,不属于金二验放指令,不进行处理",commandInfoX22.getSeqNo());
}
}
}else{
log.info("[X22]-金二开关状态为{}关闭,本地验放不处理X22指令.",g2Bean.getOnoff());
}
}catch (Exception e){
log.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);
}
}