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")
|
public AjaxResult discover(@PathVariable Long adapterId) { return success(service.discover(adapterId)); }
|
|
@PreAuthorize("@ss.hasPermi('system:deviceAdapter:list')")
|
@GetMapping("/{adapterId}/channels")
|
public AjaxResult channels(@PathVariable Long adapterId) { return success(service.selectChannels(adapterId)); }
|
|
public record StatusCommand(boolean enabled) { }
|
}
|