123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.sckj.opc.controller;
- import com.sckj.common.aop.NotLogin;
- import com.sckj.common.core.AjaxResult;
- import com.sckj.opc.entity.OPCPoint;
- import com.sckj.opc.entity.OPCServer;
- import com.sckj.opc.dataservice.OPCUAServiceImpl;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- /**
- * @Author feng
- * @Date 2024-11-21 上午 10:00
- * @Description TODO
- */
- @RestController
- @RequestMapping("api/opcua")
- @Api(tags = "OPC UA接口")
- public class OPCUAController {
- @Resource
- OPCUAServiceImpl opcuaService;
- /**
- * @return
- * @MethodName: connect
- * @Description: opcua连接
- */
- @PostMapping("/connect")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "连接")
- public AjaxResult connect(OPCServer opcServer) {
- try {
- opcuaService.createClient(opcServer);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**
- * @return
- * @MethodName: subscribe
- * @Description: 订阅所有可用的订阅点
- */
- @PostMapping("/subscribeAvailable")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "订阅可用的订阅点")
- public AjaxResult subscribeAvailable() {
- try {
- opcuaService.subscribeAvailable();
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**
- * @return
- * @MethodName: subscribe
- * @Description: 订阅所有可用的订阅点
- */
- @PostMapping("/unsubscribeAvailable")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "取消订阅可用订阅点")
- public AjaxResult unsubscribeAvailable() {
- try {
- opcuaService.unsubscribeAvailable();
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**
- * @return
- * @MethodName: subscribe
- * @Description: 订阅
- */
- @PostMapping("/subscribe")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "订阅")
- public AjaxResult subscribe(OPCPoint opcPoint) {
- try {
- opcuaService.subscribe(opcPoint);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**
- * @return
- * @MethodName: unsubscribe
- * @Description: 取消订阅
- */
- @PostMapping("/unsubscribe")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "取消订阅")
- public AjaxResult unsubscribe(OPCPoint opcPoint) {
- try {
- opcuaService.unsubscribe(opcPoint);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**
- * @return
- * @MethodName: subscribe
- * @Description: 读取节点数据
- */
- @PostMapping("/readNodeValue")
- @ResponseBody
- @NotLogin
- @ApiOperation(value = "读取节点数据")
- public AjaxResult readNodeValue(OPCPoint opcPoint) {
- try {
- return AjaxResult.success(opcuaService.readNodeValue(opcPoint));
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.failed(e.getMessage());
- }
- }
- }
|