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()));
|
}
|
}
|