feat: 增加测试查看实时订阅Map

dev
huangfeng 8 months ago
parent c5e66d9e03
commit 15fc339dab

@ -1,5 +1,7 @@
package com.xydl.cac.controller; package com.xydl.cac.controller;
import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
import com.xydl.cac.service.IcdFileConfigService; import com.xydl.cac.service.IcdFileConfigService;
import com.xydl.cac.socket.WebSocketServer; import com.xydl.cac.socket.WebSocketServer;
@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List; import java.util.List;
@RestController @RestController
@ -23,6 +26,8 @@ public class TestController extends BasicController {
IcdFileConfigService configService; IcdFileConfigService configService;
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@Resource
RealTimeDataService realTimeDataService;
@GetMapping("compare61850") @GetMapping("compare61850")
@ApiOperation("比对61850的不同点") @ApiOperation("比对61850的不同点")
@ -36,4 +41,10 @@ public class TestController extends BasicController {
public void sendMsg(String msg, Integer warningId) { public void sendMsg(String msg, Integer warningId) {
webSocketServer.sendMessage(msg, warningId); webSocketServer.sendMessage(msg, warningId);
} }
@GetMapping("realTimeMap")
@ApiOperation("实时订阅Map")
public Response<HashMap<Integer, IecClient>> realTimeMap() {
return Response.success(realTimeDataService.clientMap);
}
} }

@ -19,16 +19,24 @@ import java.util.List;
@Slf4j @Slf4j
public class IecClient implements ClientEventListener { public class IecClient implements ClientEventListener {
IcdIed ied; public IcdIed ied;
int[] title; int[] title;
ClientSap clientSap = new ClientSap(); ClientSap clientSap = new ClientSap();
ClientAssociation clientAssociation = null; ClientAssociation clientAssociation = null;
ServerModel serverModel; ServerModel serverModel;
public boolean keep = false; public boolean keep = false;
public RealTimeDataService realTimeDataService; private RealTimeDataService realTimeDataService;
public WebSocketServer webSocketServer; private WebSocketServer webSocketServer;
int retry = 10; public int retry = 10;
public IecClient() {
}
public IecClient(RealTimeDataService _realTimeDataService, WebSocketServer _webSocketServer) {
realTimeDataService = _realTimeDataService;
webSocketServer = _webSocketServer;
}
public void connect(IcdIed _ied, String xml) throws Exception { public void connect(IcdIed _ied, String xml) throws Exception {
InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8); InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8);

@ -29,7 +29,7 @@ public class RealTimeDataService {
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
public static boolean inDoing = false; public static boolean inDoing = false;
HashMap<Integer, IecClient> clientMap = new HashMap<>(); public HashMap<Integer, IecClient> clientMap = new HashMap<>();
@PostConstruct @PostConstruct
private void init() { private void init() {
@ -57,12 +57,10 @@ public class RealTimeDataService {
inDoing = true; inDoing = true;
IcdFile icdFile = optionalFile.get(); IcdFile icdFile = optionalFile.get();
try { try {
IecClient iecClient = new IecClient(); IecClient iecClient = new IecClient(this, webSocketServer);
iecClient.connect(ied, icdFile.getXml()); iecClient.connect(ied, icdFile.getXml());
iecClient.enableReporting(); iecClient.enableReporting();
iecClient.keep = true; iecClient.keep = true;
iecClient.realTimeDataService = this;
iecClient.webSocketServer = webSocketServer;
ied.setStart(Constants.TRUE); ied.setStart(Constants.TRUE);
iedRepository.save(ied); iedRepository.save(ied);
clientMap.put(ied.getId(), iecClient); clientMap.put(ied.getId(), iecClient);
@ -90,8 +88,6 @@ public class RealTimeDataService {
IecClient iecClient = clientMap.get(iedId); IecClient iecClient = clientMap.get(iedId);
if (iecClient != null) { if (iecClient != null) {
iecClient.keep = false; iecClient.keep = false;
iecClient.realTimeDataService = null;
iecClient.webSocketServer = null;
iecClient.disableReporting(); iecClient.disableReporting();
iecClient.disconnect(); iecClient.disconnect();
clientMap.remove(iedId); clientMap.remove(iedId);

Loading…
Cancel
Save