消息推送——ATS消息构建调整

This commit is contained in:
walker-sheng 2021-04-23 18:12:20 +08:00
parent a261c9e3e9
commit d6c5cfaecf
3 changed files with 36 additions and 38 deletions

View File

@ -12,7 +12,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
/** /**
* 权限验证拦截器 * 权限验证拦截器
@ -33,15 +32,10 @@ public class AuthenticateInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
// String host = request.getHeader("Host");
// String forwardedHost = request.getHeader("X-Forwarded-Host");
// String forwardedFor = request.getHeader("X-Forwarded-For");
// log.debug(String.format("host:[%s], forwardedHost:[%s], forwardedFor:[%s]", host, forwardedHost, forwardedFor));
String realIp = request.getHeader("X-Real-IP");
log.debug(String.format("request[Method: '%s', RealIp: [%s], RemoteAddr: '%s', RequestURI: '%s']",
request.getMethod(), realIp, request.getRemoteAddr(), request.getRequestURI()));
// 登陆权限验证 // 登陆权限验证
if(RequestMethod.OPTIONS.name().equals(request.getMethod())) return true; if(RequestMethod.OPTIONS.name().equals(request.getMethod())) return true;
log.debug(String.format("request[Method: '%s', RequestURI: '%s']",
request.getMethod(), request.getRequestURI()));
String token = request.getHeader("X-Token"); String token = request.getHeader("X-Token");
BusinessExceptionAssertEnum.NOT_LOGIN.assertTrue(StringUtils.hasText(token)); BusinessExceptionAssertEnum.NOT_LOGIN.assertTrue(StringUtils.hasText(token));
LoginUserInfoVO loginUserInfoVO = null; LoginUserInfoVO loginUserInfoVO = null;

View File

@ -60,6 +60,14 @@ public class SimulationCommonController {
return this.simulationOperationDispatcher.doDispatch(id, memberId, type, params); return this.simulationOperationDispatcher.doDispatch(id, memberId, type, params);
} }
/**
* 故障注入
*/
@PutMapping("/{id}/injectFault")
public void injectFault(@PathVariable String id) {
}
@PutMapping("/{id}/member/{memberId}/playby/{userId}") @PutMapping("/{id}/member/{memberId}/playby/{userId}")
public void memberPlay(@PathVariable String id, @PathVariable String memberId, @PathVariable String userId) { public void memberPlay(@PathVariable String id, @PathVariable String memberId, @PathVariable String userId) {
this.simulationManager.memberPlayedByUser(id, memberId, userId); this.simulationManager.memberPlayedByUser(id, memberId, userId);

View File

@ -16,6 +16,7 @@ import java.util.stream.Collectors;
public class AtsMessagePublisher extends SimulationMessagePublisher { public class AtsMessagePublisher extends SimulationMessagePublisher {
public static final String NAME = "AMP"; public static final String NAME = "AMP";
public static final int RATE = 1000; public static final int RATE = 1000;
Map<String, List<List<Object>>> deviceStatesMap = new HashMap<>();
AtsRepository atsRepository; AtsRepository atsRepository;
Map<String, List<Object>> switchMap = new ConcurrentHashMap<>(); Map<String, List<Object>> switchMap = new ConcurrentHashMap<>();
Map<String, List<Object>> sectionMap = new ConcurrentHashMap<>(); Map<String, List<Object>> sectionMap = new ConcurrentHashMap<>();
@ -25,54 +26,49 @@ public class AtsMessagePublisher extends SimulationMessagePublisher {
public AtsMessagePublisher(AtsRepository atsRepository) { public AtsMessagePublisher(AtsRepository atsRepository) {
super(NAME, RATE, RtSimulationSubscribeTopic.ATS.getDestPattern()); super(NAME, RATE, RtSimulationSubscribeTopic.ATS.getDestPattern());
this.atsRepository = atsRepository; this.atsRepository = atsRepository;
this.buildMessage(atsRepository);
} }
public void handleSwitch(AtsSwitch atsSwitch) { public void handleSwitch(AtsSwitch atsSwitch) {
if (!this.switchMap.containsKey(atsSwitch.getId())) { this.switchMap.putIfAbsent(atsSwitch.getId(), atsSwitch.getStateList());
this.switchMap.put(atsSwitch.getId(), atsSwitch.getStateList());
}
}
public void handleSection(AtsSection atsSection) {
if (!this.sectionMap.containsKey(atsSection.getId())) {
this.sectionMap.put(atsSection.getId(), atsSection.getStateList());
}
}
public void handleSignal(AtsSignal atsSignal) {
if (!this.signalMap.containsKey(atsSignal.getId())) {
this.signalMap.put(atsSignal.getId(), atsSignal.getStateList());
}
}
public void handleRoute(AtsRoute atsRoute) {
if (!this.routeMap.containsKey(atsRoute.getId())) {
this.routeMap.put(atsRoute.getId(), atsRoute.getStateList());
}
} }
public void handleSection(AtsSection atsSection) {
this.sectionMap.putIfAbsent(atsSection.getId(), atsSection.getStateList());
}
public void handleSignal(AtsSignal atsSignal) {
this.signalMap.putIfAbsent(atsSignal.getId(), atsSignal.getStateList());
}
public void handleRoute(AtsRoute atsRoute) {
this.routeMap.putIfAbsent(atsRoute.getId(), atsRoute.getStateList());
}
@Override @Override
public boolean acceptedSubscribePath(String destination) { public boolean acceptedSubscribePath(String destination) {
return RtSimulationSubscribeTopic.ATS.isMatch(destination); return RtSimulationSubscribeTopic.ATS.isMatch(destination);
} }
@Override private void buildMessage(AtsRepository atsRepository) {
public Object buildMessageOfSubscribe(String destination) { List<List<Object>> switchStateList = atsRepository.getSwitchMap().values().stream()
HashMap<Object, Object> message = new HashMap<>();
List<List<Object>> switchStateList = this.atsRepository.getSwitchMap().values().stream()
.map(AtsSwitch::getStateList) .map(AtsSwitch::getStateList)
.collect(Collectors.toList()); .collect(Collectors.toList());
List<List<Object>> sectionStateList = this.atsRepository.getSectionMap().values().stream() List<List<Object>> sectionStateList = atsRepository.getSectionMap().values().stream()
.map(AtsSection::getStateList) .map(AtsSection::getStateList)
.collect(Collectors.toList()); .collect(Collectors.toList());
List<List<Object>> signalStateList = this.atsRepository.getSignalMap().values().stream() List<List<Object>> signalStateList = atsRepository.getSignalMap().values().stream()
.map(AtsSignal::getStateList) .map(AtsSignal::getStateList)
.collect(Collectors.toList()); .collect(Collectors.toList());
List<List<Object>> routeStateList = this.atsRepository.getRouteMap().values().stream() List<List<Object>> routeStateList = atsRepository.getRouteMap().values().stream()
.map(AtsRoute::getStateList) .map(AtsRoute::getStateList)
.collect(Collectors.toList()); .collect(Collectors.toList());
message.put("switch", switchStateList); this.deviceStatesMap.put("switch", switchStateList);
message.put("section", sectionStateList); this.deviceStatesMap.put("section", sectionStateList);
message.put("signal", signalStateList); this.deviceStatesMap.put("signal", signalStateList);
message.put("route", routeStateList); this.deviceStatesMap.put("route", routeStateList);
return message; }
@Override
public Object buildMessageOfSubscribe(String destination) {
return this.deviceStatesMap;
} }
@Override @Override