1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.zhitan.controller;
 
import com.zhitan.model.entity.OpcData;
import com.zhitan.service.IOpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * OPC UA控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/opc")
public class OpcController {
 
    private final IOpcService opcService;
 
    @Autowired
    public OpcController(IOpcService opcService) {
        this.opcService = opcService;
    }
 
    /**
     * 获取OPC UA连接状态
     */
    @GetMapping("/status")
    public boolean getConnectionStatus() {
        return opcService.isConnected();
    }
 
    /**
     * 手动连接OPC UA服务器
     */
    @PostMapping("/connect")
    public boolean connect() {
        return opcService.connect();
    }
 
    /**
     * 断开OPC UA连接
     */
    @PostMapping("/disconnect")
    public void disconnect() {
        opcService.disconnect();
    }
 
    /**
     * 启动数据采集
     */
    @PostMapping("/start")
    public void startCollection() {
        opcService.startDataCollection();
    }
 
    /**
     * 停止数据采集
     */
    @PostMapping("/stop")
    public void stopCollection() {
        opcService.stopDataCollection();
    }
 
    /**
     * 读取所有节点数据
     */
    @GetMapping("/data")
    public List<OpcData> readAllData() {
        return opcService.readAllNodes();
    }
}