From eb2d3ef0e4fa144d5a76823709a1ab2bc27a2ae9 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 22 七月 2025 17:42:34 +0800 Subject: [PATCH] 1、通信中间件去除上报消息测试类(去除注解) ; 2、remote模块,webSocket模块修改完善,增加机构orgTag控制; 3、从SSO模块获取当前用户信息部分进行集成完善,以供其他部分共享应用。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoAspect.java | 46 ------- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/comResult/CommandResultDeal.java | 4 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java | 2 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java | 86 ++++++++----- pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java | 10 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/contant/Constant.java | 4 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/UserTokenFilter.java | 2 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java | 2 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java | 10 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoPowerAspect.java | 53 -------- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/webRequest/WebRequestDeal.java | 2 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoCheck.java | 100 ++++++++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketHeartBeat.java | 2 13 files changed, 176 insertions(+), 147 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoAspect.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoAspect.java index 5180006..ebd9d33 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoAspect.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoAspect.java @@ -14,10 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.annotation.Order; -import org.springframework.http.*; import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; import java.lang.reflect.Method; import java.util.Objects; @@ -31,15 +28,8 @@ @Value("${pipIrr.global.dev}") public String isDevStage ;//鏄惁涓哄紑鍙戦樁娈� - @Value("${pipIrr.sso.checkUrl}") - public String ssoCheckUrl; - - private RestTemplate restTemplate; - @Autowired - public void setRestTemplate(RestTemplate restTemplate){ - this.restTemplate = restTemplate ; - } + private SsoCheck ssoCheck ; @Pointcut("@annotation(com.dy.common.aop.SsoAop)") public void ssoPointCut() { @@ -55,7 +45,7 @@ SsoAop aop = method.getAnnotation(SsoAop.class) ; if (Objects.nonNull(aop)){ String token = UserTokenContext.get() ; - Object rObj = this.check(token); + Object rObj = this.ssoCheck.check(token); if(rObj != null){ if(rObj instanceof SsoVo ssoVo){ if(ssoVo.logined){ @@ -90,37 +80,5 @@ } } - /** - * 璋冪敤SSO绯荤粺杩涜楠岃瘉 - * @param token Header涓殑鐢ㄦ埛token - * @return 杩斿洖瀵硅薄 - */ - private Object check(String token){ - if(!StringUtils.isNullOrEmpty(ssoCheckUrl)){ - String url = UriComponentsBuilder.fromUriString(ssoCheckUrl) - .queryParam("token", token) - .build() - .toUriString(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - - HttpEntity<?> httpEntity = new HttpEntity<>(headers); - ResponseEntity<SsoVo> response = null; - try { - // 閫氳繃Get鏂瑰紡璋冪敤鎺ュ彛 - response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, SsoVo.class); - } catch (Exception e) { - e.printStackTrace(); - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); - } - if(response == null){ - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); - }else{ - return response.getBody(); - } - }else { - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛屾湭寰楀埌SsoCheckUrl"); - } - } } diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoCheck.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoCheck.java new file mode 100644 index 0000000..0496e69 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoCheck.java @@ -0,0 +1,100 @@ +package com.dy.common.aop; + +import com.dy.common.webUtil.BaseResponseUtils; +import com.mysql.cj.util.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +/** + * @Author: liurunyu + * @Date: 2025/7/22 17:09 + * @Description + */ +@Component +public class SsoCheck { + + @Value("${pipIrr.sso.checkUrl}") + private String ssoCheckUrl; + + private RestTemplate restTemplate; + + @Autowired + public void setRestTemplate(RestTemplate restTemplate){ + this.restTemplate = restTemplate ; + } + + /** + * 璋冪敤SSO绯荤粺杩涜楠岃瘉 + * @param token Header涓殑鐢ㄦ埛token + * @return 杩斿洖瀵硅薄 + */ + public Object check(String token){ + if(!StringUtils.isNullOrEmpty(ssoCheckUrl)){ + String url = UriComponentsBuilder.fromUriString(ssoCheckUrl) + .queryParam("token", token) + .build() + .toUriString(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); + + HttpEntity<?> httpEntity = new HttpEntity<>(headers); + ResponseEntity<SsoVo> response = null; + try { + // 閫氳繃Get鏂瑰紡璋冪敤鎺ュ彛 + response = this.restTemplate.exchange(url, HttpMethod.GET, httpEntity, SsoVo.class); + } catch (Exception e) { + e.printStackTrace(); + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); + } + if(response == null){ + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); + }else{ + return response.getBody(); + } + }else { + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛屾湭寰楀埌SsoCheckUrl"); + } + } + + + /** + * 璋冪敤SSO绯荤粺杩涜楠岃瘉 + * @param token Header涓殑鐢ㄦ埛token + * @param power 涓�涓潈闄� + * @param allPower 澶氫釜鏉冮檺 + * @param anyPower 澶氫釜鏉冮檺 + * @return 杩斿洖瀵硅薄 + */ + public Object check(String token, String power, String[] allPower, String[] anyPower){ + if(!StringUtils.isNullOrEmpty(ssoCheckUrl)){ + String url = UriComponentsBuilder.fromUriString(ssoCheckUrl) + .queryParam("token", token) + .queryParam("power", power) + .queryParam("allPower", (Object) allPower) + .queryParam("anyPower", (Object) anyPower) + .build() + .toUriString(); + HttpHeaders headers = new HttpHeaders(); + HttpEntity<?> httpEntity = new HttpEntity<>(headers); + ResponseEntity<SsoVo> response = null; + try { + // 閫氳繃Get鏂瑰紡璋冪敤鎺ュ彛 + response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, SsoVo.class); + } catch (Exception e) { + e.printStackTrace(); + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); + } + if(response == null){ + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); + }else{ + return response.getBody(); + } + }else { + return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛屾湭寰楀埌SsoCheckUrl"); + } + } +} diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoPowerAspect.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoPowerAspect.java index 0458c3f..c559b5c 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoPowerAspect.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/aop/SsoPowerAspect.java @@ -14,13 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.annotation.Order; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; import java.lang.reflect.Method; import java.util.Objects; @@ -34,15 +28,8 @@ @Value("${pipIrr.global.dev}") public String isDevStage ;//鏄惁涓哄紑鍙戦樁娈� - @Value("${pipIrr.sso.checkUrl}") - public String SsoCheckUrl ; - - private RestTemplate restTemplate; - @Autowired - public void setRestTemplate(RestTemplate restTemplate){ - this.restTemplate = restTemplate ; - } + private SsoCheck ssoCheck ; @Pointcut("@annotation(com.dy.common.aop.SsoPowerAop)") public void ssoPowerPointCut() { @@ -68,7 +55,7 @@ String[] allPower = aop.ifAllPower() ; String[] anyPower = aop.ifAnyPower() ; String token = UserTokenContext.get() ; - Object rObj = this.check(token, power, allPower, anyPower); + Object rObj = this.ssoCheck.check(token, power, allPower, anyPower); if(rObj != null){ if(rObj instanceof SsoVo ssoVo){ if(ssoVo.logined){ @@ -104,41 +91,5 @@ } } - /** - * 璋冪敤SSO绯荤粺杩涜楠岃瘉 - * @param token Header涓殑鐢ㄦ埛token - * @param power 涓�涓潈闄� - * @param allPower 澶氫釜鏉冮檺 - * @param anyPower 澶氫釜鏉冮檺 - * @return 杩斿洖瀵硅薄 - */ - private Object check(String token, String power, String[] allPower, String[] anyPower){ - if(!StringUtils.isNullOrEmpty(SsoCheckUrl)){ - String url = UriComponentsBuilder.fromUriString(SsoCheckUrl) - .queryParam("token", token) - .queryParam("power", power) - .queryParam("allPower", (Object) allPower) - .queryParam("anyPower", (Object) anyPower) - .build() - .toUriString(); - HttpHeaders headers = new HttpHeaders(); - HttpEntity<?> httpEntity = new HttpEntity<>(headers); - ResponseEntity<SsoVo> response = null; - try { - // 閫氳繃Get鏂瑰紡璋冪敤鎺ュ彛 - response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, SsoVo.class); - } catch (Exception e) { - e.printStackTrace(); - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); - } - if(response == null){ - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛岃闂崟鐐圭櫥褰曠郴缁熷紓甯�"); - }else{ - return response.getBody(); - } - }else { - return BaseResponseUtils.buildError("鍚庣绯荤粺鍑洪敊锛屾湭寰楀埌SsoCheckUrl"); - } - } } diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/contant/Constant.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/contant/Constant.java index d2ecc04..d175605 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/contant/Constant.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/contant/Constant.java @@ -7,6 +7,6 @@ public static final int AspectOrderDataSource = 1 ; - //public static final String UserTokenKeyInHeader = "token" ; - public static final String UserTokenKeyInHeader = "Token" ; + //public static final String TokenKeyInHeader = "token" ; + public static final String TokenKeyInHeader = "Token" ; } diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/UserTokenFilter.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/UserTokenFilter.java index 164f7f5..52caa04 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/UserTokenFilter.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/UserTokenFilter.java @@ -32,7 +32,7 @@ // 濡傛灉涓嶆槸闈炶繃婊ら」锛屾墽琛岃繃婊ら�昏緫 HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; - String token = request.getHeader(Constant.UserTokenKeyInHeader); + String token = request.getHeader(Constant.TokenKeyInHeader); if(!StringUtils.isNullOrEmpty(token)){ UserTokenContext.set(token); filterChain.doFilter(servletRequest, servletResponse); diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java index 8af9b06..9532ec4 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java @@ -10,7 +10,7 @@ import org.springframework.context.annotation.FilterType; import org.springframework.scheduling.annotation.EnableScheduling; -@EnableScheduling +//@EnableScheduling @SpringBootApplication @EnableAspectJAutoProxy @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.rtuMw"}, diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java index 75e513f..452eeff 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java @@ -10,11 +10,11 @@ * @Description */ //浣胯捣浣滅敤锛屾湰绫绘敞瑙Component锛屽苟鍦≒ipIrrMwRtuApplication娉ㄨВ@EnableScheduling -@Component +//@Component public class TestMsResource { // 璁剧疆瀹氭椂N绉掍竴娆� - @Scheduled(cron = "0/4 * * * * ?") + //@Scheduled(cron = "0/4 * * * * ?") public void test1() throws Exception { MsObj msObj = new MsObj() ; setAttr4OpenCloseValve("寮�闃�", msObj) ; @@ -22,7 +22,7 @@ } // 璁剧疆瀹氭椂N绉掍竴娆� - @Scheduled(cron = "0/6 * * * * ?") + //@Scheduled(cron = "0/6 * * * * ?") public void test2() throws Exception { MsObj msObj = new MsObj() ; setAttr4OpenCloseValve("鍏抽榾", msObj) ; @@ -30,7 +30,7 @@ } // 璁剧疆瀹氭椂N绉掍竴娆� - @Scheduled(cron = "0/10 * * * * ?") + //@Scheduled(cron = "0/10 * * * * ?") public void test4() throws Exception { MsObj msObj = new MsObj() ; setAttr4StateAlarm("闃�鎬�", msObj) ; @@ -40,7 +40,7 @@ } // 璁剧疆瀹氭椂N绉掍竴娆� - @Scheduled(cron = "0/15 * * * * ?") + //@Scheduled(cron = "0/15 * * * * ?") public void test3() throws Exception { MsObj msObj = new MsObj() ; setAttr4StateAlarm("闃�鎬�", msObj) ; diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/comResult/CommandResultDeal.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/comResult/CommandResultDeal.java index 658e68e..d95f452 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/comResult/CommandResultDeal.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/comResult/CommandResultDeal.java @@ -48,7 +48,7 @@ restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - headers.set(Constant.UserTokenKeyInHeader, ServerProperties.orgTag); + headers.set(Constant.TokenKeyInHeader, ServerProperties.orgTag); HttpEntity<?> httpEntity = new HttpEntity<>(data, headers); ResponseEntity<WebResponseVo> response = null; try { @@ -78,7 +78,7 @@ restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - headers.set(Constant.UserTokenKeyInHeader, ServerProperties.orgTag); + headers.set(Constant.TokenKeyInHeader, ServerProperties.orgTag); HttpEntity<?> httpEntity = new HttpEntity<>(subMsg, headers); ResponseEntity<WebResponseVo> response = null; try { diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/webRequest/WebRequestDeal.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/webRequest/WebRequestDeal.java index e07ad00..46a01f7 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/webRequest/WebRequestDeal.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/webRequest/WebRequestDeal.java @@ -47,7 +47,7 @@ restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - headers.set(Constant.UserTokenKeyInHeader, ServerProperties.orgTag); + headers.set(Constant.TokenKeyInHeader, ServerProperties.orgTag); HttpEntity<?> httpEntity = new HttpEntity<>(obj, headers); ResponseEntity<BaseResponse> response = null; try { diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketHeartBeat.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketHeartBeat.java index ef881b4..4183392 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketHeartBeat.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketHeartBeat.java @@ -18,7 +18,7 @@ // 璁剧疆瀹氭椂鍗佺涓�娆� @Scheduled(cron = "0/10 * * * * ?") public void WsHeartBeat() throws Exception { - WebSocketServer.sendMessage2AllClient(getHeartBeatMessage()); + WebSocketServer.sendMessage2AllClient(null, getHeartBeatMessage()); } public static String getHeartBeatMessage() { diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java index f2c0041..03b1c12 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java @@ -1,6 +1,9 @@ package com.dy.pipIrrRemote.largeScreen; +import com.dy.common.aop.SsoCheck; +import com.dy.common.aop.SsoVo; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -18,7 +21,7 @@ * 绠$悊浜嗭紙鍦ㄥ祵鍏ュ紡web Servlet鐜涓級 */ @Slf4j -@ServerEndpoint("/websocket/ls/{id}") +@ServerEndpoint("/websocket/ls/{token}") @Component @Scope("prototype") // 闈炲崟渚嬶紝姣忔璇锋眰閮戒細鍒涘缓鏂扮殑瀹炰緥 public class WebSocketServer { @@ -31,32 +34,43 @@ // 瀹㈡埛绔繛鎺ヤ細璇濓紝閫氳繃瀹冪粰瀹㈡埛绔彂閫佹暟鎹� private Session session; + + private String orgTag; + // 瀹㈡埛绔笂绾挎椂鍒� //private String onLineDt ; - // 瀹㈡埛绔痠d - private String id = ""; + // 瀹㈡埛绔� + private String token = ""; + + @Autowired + private SsoCheck ssoCheck ; /** * 杩炴帴寤虹珛鎴愬姛璋冪敤鐨勬柟娉� * @param session websocket浼氳瘽瀵硅薄 - * @param id 瀹㈡埛绔痠d + * @param token 瀹㈡埛绔痠d */ @OnOpen - public void onOpen(Session session, @PathParam("id") String id) { - this.session = session; - //this.onLineDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; - this.id = id; - if(this.id == null || this.id.length() == 0){ - this.id = "" + System.nanoTime() ; - } - this.sendMessage(WebSocketHeartBeat.getHeartBeatMessage()); + public void onOpen(Session session, @PathParam("token") String token) { + if(this.token == null || this.token.length() == 0){ + this.session = session; + //this.onLineDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; + this.token = token; + this.sendMessage(WebSocketHeartBeat.getHeartBeatMessage()); - if (webSocketMap.containsKey(id)) { - webSocketMap.remove(id); - webSocketMap.put(id, this); - } else { - webSocketMap.put(id, this); - WebSocketServer.addOnlineCount(); + if (webSocketMap.containsKey(token)) { + webSocketMap.remove(token); + webSocketMap.put(token, this); + } else { + webSocketMap.put(token, this); + WebSocketServer.addOnlineCount(); + } + Object rObj = this.ssoCheck.check(token); + if(rObj != null) { + if (rObj instanceof SsoVo ssoVo) { + this.orgTag = ssoVo.dataSourceName ; + } + } } } @@ -65,12 +79,12 @@ */ @OnClose public void onClose() { - if (webSocketMap.containsKey(id)) { - webSocketMap.remove(id); + if (webSocketMap.containsKey(token)) { + webSocketMap.remove(token); //浠巗et涓垹闄� WebSocketServer.subOnlineCount(); } - log.info("瀹㈡埛绔�:" + id + "锛屽叧闂簡websocket"); + log.info("瀹㈡埛绔�:" + token + "锛屽叧闂簡websocket"); } /** @@ -80,7 +94,7 @@ */ @OnMessage public void onMessage(String message, Session session) { - log.info("瀹㈡埛绔�:" + id + "锛寃ebsocket鎶ユ枃:" + message); + log.info("瀹㈡埛绔�:" + token + "锛寃ebsocket鎶ユ枃:" + message); } /** @@ -90,7 +104,7 @@ */ @OnError public void onError(Session session, Throwable error) { - log.error("瀹㈡埛绔�:" + this.id + "锛寃ebsocket浼氳瘽寮傚父锛屽師鍥�:" + error.getMessage()); + log.error("瀹㈡埛绔�:" + this.token + "锛寃ebsocket浼氳瘽寮傚父锛屽師鍥�:" + error.getMessage()); } /** @@ -100,29 +114,35 @@ try{ this.session.getBasicRemote().sendText(message); }catch (Exception e){ - log.error("瀹㈡埛绔�:" + id + "锛寃ebsocket缃戠粶鍙戦�佹暟鎹紓甯�", e); + log.error("瀹㈡埛绔�:" + token + "锛寃ebsocket缃戠粶鍙戦�佹暟鎹紓甯�", e); } } /** * 鏈嶅姟鍣ㄤ富鍔ㄧ兢鎺ㄩ�佹秷鎭� */ - public static void sendMessage2AllClient(String message) throws IOException { - ConcurrentHashMap.KeySetView<String, WebSocketServer> ids = webSocketMap.keySet(); - for (String id : ids) { - WebSocketServer webSocketServer = webSocketMap.get(id); - webSocketServer.sendMessage(message); + public static void sendMessage2AllClient(String orgTag, String message) throws IOException { + ConcurrentHashMap.KeySetView<String, WebSocketServer> tokens = webSocketMap.keySet(); + for (String token : tokens) { + WebSocketServer webSocketServer = webSocketMap.get(token); + if(orgTag == null){ + webSocketServer.sendMessage(message); + }else{ + if(webSocketServer.orgTag != null && webSocketServer.orgTag.equals(orgTag)){ + webSocketServer.sendMessage(message); + } + } } } /** * 鏈嶅姟鍣ㄦ寚瀹氬鎴风鎺ㄩ�佹秷鎭� */ - public static void sendMessage2OneClient(String message, String id) throws IOException { - if (message != null && message.length() != 0 && webSocketMap.containsKey(id)) { - webSocketMap.get(id).sendMessage(message); + public static void sendMessage2OneClient(String message, String token) throws IOException { + if (message != null && message.length() != 0 && webSocketMap.containsKey(token)) { + webSocketMap.get(token).sendMessage(message); } else { - log.error("瀹㈡埛绔�" + id + "锛屼笉鍦ㄧ嚎锛�"); + log.error("瀹㈡埛绔�" + token + "锛屼笉鍦ㄧ嚎锛�"); } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java index 0678465..a40d3ff 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java @@ -46,8 +46,8 @@ @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) public BaseResponse<Boolean> receive(@RequestBody List<JSONObject> list, HttpServletRequest req, HttpServletResponse rep) { //閫氫俊涓棿浠朵紶杩囨潵鐨勬満鏋則ag锛屼互鐢ㄤ簬鏌ユ壘鏁版嵁婧� - String token = req.getHeader(Constant.UserTokenKeyInHeader); - DataSourceContext.set(token); + String orgTag = req.getHeader(Constant.TokenKeyInHeader); + DataSourceContext.set(orgTag); if(list != null && list.size() > 0){ for (JSONObject jo : list) { @@ -69,7 +69,7 @@ } } } - sendByWebSocket(list) ; + sendByWebSocket(orgTag, list) ; } return null ; } @@ -78,12 +78,12 @@ * 閫氳繃websocket鎶婃秷鎭帹閫佸嚭鍘伙紝褰撳墠鎺ユ敹鏂规槸鍓嶇鐨勫ぇ灞忓睍绀烘ā鍧� * @param list */ - private void sendByWebSocket(List<JSONObject> list){ + private void sendByWebSocket(String orgTag, List<JSONObject> list){ WebSocketMessage vo = new WebSocketMessage() ; vo.type = WebSocketMessage.TYPE_JSON ; vo.content = list ; try { - WebSocketServer.sendMessage2AllClient(JSON.toJSONString(vo)); + WebSocketServer.sendMessage2AllClient(orgTag, JSON.toJSONString(vo)); }catch (Exception e){ log.error("鎺ㄩ�佹秷鎭け璐�", e) ; } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java index a31da14..bf7f008 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java @@ -72,7 +72,7 @@ info.ugRtuStateList = info.ugRtuStateList.stream().sorted(comparator).collect(Collectors.toList()); //閫氫俊涓棿浠朵紶杩囨潵鐨勬満鏋則ag锛屼互鐢ㄤ簬鏌ユ壘鏁版嵁婧� - String token = req.getHeader(Constant.UserTokenKeyInHeader); + String token = req.getHeader(Constant.TokenKeyInHeader); DataSourceContext.set(token); if(cache == null){ -- Gitblit v1.8.0