yeg
2026-09-06 37600a85b79387ab6afa7bf342eedbf938331e1d
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.battery.business.web;
 
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.battery.business.domain.TCollector;
import com.battery.business.domain.vo.DiscoveredCollectorVo;
import com.battery.business.service.ICollectorDiscoveryService;
import com.battery.business.service.ITCollectorService;
 
/**
 * 采集器管理 Controller。
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/collector")
public class TCollectorController extends BaseController
{
    @Autowired
    private ITCollectorService collectorService;
 
    @Autowired
    private ICollectorDiscoveryService collectorDiscoveryService;
 
    /** 分页查询采集器列表。 */
    @PreAuthorize("@ss.hasPermi('system:collector:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCollector collector)
    {
        startPage();
        List<TCollector> list = collectorService.selectCollectorList(collector);
        return getDataTable(list);
    }
 
    /**
     * 查询当前可发现的采集器列表。
     *
     * @return 可发现采集器分页数据
     */
    @PreAuthorize("@ss.hasPermi('system:collector:list')")
    @GetMapping("/discovered/list")
    public TableDataInfo discoveredList()
    {
        List<DiscoveredCollectorVo> devices = collectorDiscoveryService.selectDiscoveredCollectorList();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        int pageNum = pageDomain.getPageNum() == null || pageDomain.getPageNum() < 1 ? 1 : pageDomain.getPageNum();
        int pageSize = pageDomain.getPageSize() == null || pageDomain.getPageSize() < 1 ? 10 : pageDomain.getPageSize();
        long offset = (long) (pageNum - 1) * pageSize;
        int fromIndex = (int) Math.min(offset, devices.size());
        int toIndex = (int) Math.min((long) fromIndex + pageSize, devices.size());
        List<DiscoveredCollectorVo> rows = fromIndex == toIndex
                ? Collections.emptyList()
                : devices.subList(fromIndex, toIndex);
        TableDataInfo result = new TableDataInfo(rows, devices.size());
        result.setCode(HttpStatus.SUCCESS);
        result.setMsg("查询成功");
        return result;
    }
 
    /** 查询采集器详情。 */
    @PreAuthorize("@ss.hasPermi('system:collector:query')")
    @GetMapping(value = "/{collectorId}")
    public AjaxResult getInfo(@PathVariable Long collectorId)
    {
        return success(collectorService.selectCollectorById(collectorId));
    }
 
    /** 新增采集器。 */
    @PreAuthorize("@ss.hasPermi('system:collector:add')")
    @Log(title = "采集器管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TCollector collector)
    {
        collector.setCreateBy(getUsername());
        return toAjax(collectorService.insertCollector(collector));
    }
 
    /** 编辑采集器基础资料。 */
    @PreAuthorize("@ss.hasPermi('system:collector:edit')")
    @Log(title = "采集器管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TCollector collector)
    {
        collector.setUpdateBy(getUsername());
        return toAjax(collectorService.updateCollector(collector));
    }
 
    /** 启用或禁用采集器。 */
    @PreAuthorize("@ss.hasPermi('system:collector:edit')")
    @Log(title = "采集器管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TCollector collector)
    {
        collector.setUpdateBy(getUsername());
        return toAjax(collectorService.updateCollectorStatus(collector));
    }
 
    /** 批量逻辑删除采集器。 */
    @PreAuthorize("@ss.hasPermi('system:collector:remove')")
    @Log(title = "采集器管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{collectorIds}")
    public AjaxResult remove(@PathVariable Long[] collectorIds)
    {
        return toAjax(collectorService.deleteCollectorByIds(collectorIds, getUsername()));
    }
}