消息推送——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.HttpServletResponse;
import java.util.Objects;
/**
* 权限验证拦截器
@ -33,15 +32,10 @@ public class AuthenticateInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
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;
log.debug(String.format("request[Method: '%s', RequestURI: '%s']",
request.getMethod(), request.getRequestURI()));
String token = request.getHeader("X-Token");
BusinessExceptionAssertEnum.NOT_LOGIN.assertTrue(StringUtils.hasText(token));
LoginUserInfoVO loginUserInfoVO = null;

View File

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

View File

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