yeg
2026-08-31 6c38637d89f346a660618558451f2dd7286dc7a5
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.ruoyi.web.controller.device;
 
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TDeviceAdapter;
import com.ruoyi.system.service.IDeviceAdapterService;
 
/** 设备适配器实例管理与发现 REST。 */
@RestController
@RequestMapping("/system/deviceAdapter")
public class DeviceAdapterController extends BaseController
{
    private final IDeviceAdapterService service;
 
    public DeviceAdapterController(IDeviceAdapterService service)
    {
        this.service = service;
    }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:list')")
    @GetMapping("/list")
    /** 分页查询适配器配置及其最近运行状态。 */
    public TableDataInfo list()
    {
        startPage();
        return getDataTable(service.selectList(new TDeviceAdapter()));
    }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:query')")
    @GetMapping("/{adapterId}")
    /** 查询指定适配器详情;适配器必须存在。 */
    public AjaxResult getInfo(@PathVariable Long adapterId) { return success(service.selectById(adapterId)); }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:add')")
    @Log(title = "设备适配器实例", businessType = BusinessType.INSERT)
    @PostMapping
    /** 新增默认禁用的只读适配器配置。 */
    public AjaxResult add(@Validated @RequestBody TDeviceAdapter adapter)
    {
        adapter.setCreateBy(getUsername());
        return toAjax(service.insert(adapter));
    }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:edit')")
    @Log(title = "设备适配器实例", businessType = BusinessType.UPDATE)
    @PutMapping
    /** 修改适配器配置;启用实例会同步替换运行时连接。 */
    public AjaxResult edit(@Validated @RequestBody TDeviceAdapter adapter)
    {
        adapter.setUpdateBy(getUsername());
        return toAjax(service.update(adapter));
    }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:changeStatus')")
    @Log(title = "设备适配器实例启停", businessType = BusinessType.UPDATE)
    @PutMapping("/{adapterId}/status")
    /** 启用或停用适配器;启用前配置必须通过只读校验。 */
    public AjaxResult changeStatus(@PathVariable Long adapterId, @RequestBody StatusCommand command)
    {
        return toAjax(service.changeStatus(adapterId, command.enabled(), getUsername()));
    }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:discover')")
    @Log(title = "设备适配器发现", businessType = BusinessType.OTHER)
    @PostMapping("/{adapterId}/discover")
    /** 执行一次 getdevinfo 与实时 inquire,并返回本轮发现摘要。 */
    public AjaxResult discover(@PathVariable Long adapterId) { return success(service.discover(adapterId)); }
 
    @PreAuthorize("@ss.hasPermi('system:deviceAdapter:list')")
    @GetMapping("/{adapterId}/channels")
    /** 查询适配器当前未过期的 Redis 发现通道。 */
    public AjaxResult channels(@PathVariable Long adapterId) { return success(service.selectChannels(adapterId)); }
 
    public record StatusCommand(boolean enabled) { }
}