package com.xunmei.system.controller;

import java.util.List;

import com.xunmei.common.security.annotation.InnerAuth;
import com.xunmei.system.api.domain.SysDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xunmei.common.log.annotation.Log;
import com.xunmei.common.log.enums.BusinessType;
import com.xunmei.common.security.annotation.RequiresPermissions;
import com.xunmei.system.service.ISysDeviceService;
import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.xunmei.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author xunmei
 * @date 2023-08-22
 */
@Api(tags = {"SysDevice"})
@RestController
@RequestMapping("/device")
public class SysDeviceController extends BaseController {
    @Autowired
    private ISysDeviceService sysDeviceService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation(value = "查询SysDevice列表")
    @RequiresPermissions("system:device:list")
    @GetMapping("/list")
    public TableDataInfo<SysDevice> list(SysDevice sysDevice) {
        return sysDeviceService.selectPage(sysDevice);
    }


    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation(value = "获取SysDevice详细信息")
    @RequiresPermissions("system:device:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysDeviceService.selectSysDeviceById(id));
    }

    /**
     * 通过机构id获取主机列表
     */
    @ApiOperation(value = "通过机构id获取主机列表")
    @RequiresPermissions("system:device:query")
    @GetMapping(value = "/getHostByOrgId/{orgId}")
    public AjaxResult getHostByOrgId(@PathVariable(value = "orgId", required = false) Long orgId) {
        return success(sysDeviceService.getHostByOrgId(orgId));
    }

    /**
     * 通过机构id查询主机
     */
    @ApiOperation(value = "通过机构id查询主机")
    @RequiresPermissions("system:device:query")
    @GetMapping(value = "/getSysDeviceByOrgId/{orgId}")
    public AjaxResult getSysDeviceByOrgId(@PathVariable(value = "orgId", required = false)Long orgId) {
        return success(sysDeviceService.getHostByOrgId(orgId));
    }

    @ApiOperation(value = "通过主机查询视频监控")
    @GetMapping(value = "/getSysDeviceByHostId/{hostId}")
    public AjaxResult getSysDeviceByHostId(@PathVariable(value = "hostId", required = false)Long hostId) {
        return success(sysDeviceService.getSysDeviceByHostId(hostId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation(value = "新增SysDevice")
    @RequiresPermissions("system:device:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDevice sysDevice) {
        return toAjax(sysDeviceService.insertSysDevice(sysDevice));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation(value = "修改SysDevice")
    @RequiresPermissions("system:device:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDevice sysDevice) {
        return toAjax(sysDeviceService.updateSysDevice(sysDevice));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation(value = "删除SysDevice")
    @RequiresPermissions("system:device:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysDeviceService.deleteSysDeviceByIds(ids));
    }
}
