OPCUAController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.sckj.opc.controller;
  2. import com.sckj.common.aop.NotLogin;
  3. import com.sckj.common.core.AjaxResult;
  4. import com.sckj.opc.entity.OPCPoint;
  5. import com.sckj.opc.entity.OPCServer;
  6. import com.sckj.opc.dataservice.OPCUAServiceImpl;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import javax.annotation.Resource;
  14. /**
  15. * @Author feng
  16. * @Date 2024-11-21 上午 10:00
  17. * @Description TODO
  18. */
  19. @RestController
  20. @RequestMapping("api/opcua")
  21. @Api(tags = "OPC UA接口")
  22. public class OPCUAController {
  23. @Resource
  24. OPCUAServiceImpl opcuaService;
  25. /**
  26. * @return
  27. * @MethodName: connect
  28. * @Description: opcua连接
  29. */
  30. @PostMapping("/connect")
  31. @ResponseBody
  32. @NotLogin
  33. @ApiOperation(value = "连接")
  34. public AjaxResult connect(OPCServer opcServer) {
  35. try {
  36. opcuaService.createClient(opcServer);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. return AjaxResult.failed(e.getMessage());
  40. }
  41. return AjaxResult.success();
  42. }
  43. /**
  44. * @return
  45. * @MethodName: subscribe
  46. * @Description: 订阅所有可用的订阅点
  47. */
  48. @PostMapping("/subscribeAvailable")
  49. @ResponseBody
  50. @NotLogin
  51. @ApiOperation(value = "订阅可用的订阅点")
  52. public AjaxResult subscribeAvailable() {
  53. try {
  54. opcuaService.subscribeAvailable();
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. return AjaxResult.failed(e.getMessage());
  58. }
  59. return AjaxResult.success();
  60. }
  61. /**
  62. * @return
  63. * @MethodName: subscribe
  64. * @Description: 订阅所有可用的订阅点
  65. */
  66. @PostMapping("/unsubscribeAvailable")
  67. @ResponseBody
  68. @NotLogin
  69. @ApiOperation(value = "取消订阅可用订阅点")
  70. public AjaxResult unsubscribeAvailable() {
  71. try {
  72. opcuaService.unsubscribeAvailable();
  73. } catch (Exception e) {
  74. e.printStackTrace();
  75. return AjaxResult.failed(e.getMessage());
  76. }
  77. return AjaxResult.success();
  78. }
  79. /**
  80. * @return
  81. * @MethodName: subscribe
  82. * @Description: 订阅
  83. */
  84. @PostMapping("/subscribe")
  85. @ResponseBody
  86. @NotLogin
  87. @ApiOperation(value = "订阅")
  88. public AjaxResult subscribe(OPCPoint opcPoint) {
  89. try {
  90. opcuaService.subscribe(opcPoint);
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. return AjaxResult.failed(e.getMessage());
  94. }
  95. return AjaxResult.success();
  96. }
  97. /**
  98. * @return
  99. * @MethodName: unsubscribe
  100. * @Description: 取消订阅
  101. */
  102. @PostMapping("/unsubscribe")
  103. @ResponseBody
  104. @NotLogin
  105. @ApiOperation(value = "取消订阅")
  106. public AjaxResult unsubscribe(OPCPoint opcPoint) {
  107. try {
  108. opcuaService.unsubscribe(opcPoint);
  109. } catch (Exception e) {
  110. e.printStackTrace();
  111. return AjaxResult.failed(e.getMessage());
  112. }
  113. return AjaxResult.success();
  114. }
  115. /**
  116. * @return
  117. * @MethodName: subscribe
  118. * @Description: 读取节点数据
  119. */
  120. @PostMapping("/readNodeValue")
  121. @ResponseBody
  122. @NotLogin
  123. @ApiOperation(value = "读取节点数据")
  124. public AjaxResult readNodeValue(OPCPoint opcPoint) {
  125. try {
  126. return AjaxResult.success(opcuaService.readNodeValue(opcPoint));
  127. } catch (Exception e) {
  128. e.printStackTrace();
  129. return AjaxResult.failed(e.getMessage());
  130. }
  131. }
  132. }