package com.dcsoft.system.camera.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.camera.domain.TbCamera;
import com.dcsoft.system.camera.service.ITbCameraService;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 视频配置Controller
 *
 * @author nichun
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/camera")
public class TbCameraController extends BaseController
{
    @Autowired
    private ITbCameraService tbCameraService;

    /**
     * 查询视频配置列表
     */
    @RequiresPermissions("system:camera:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCamera tbCamera)
    {
        startPage();
        List<TbCamera> list = tbCameraService.selectTbCameraList(tbCamera);
        return getDataTable(list);
    }

    /**
     * 导出视频配置列表
     */
    @RequiresPermissions("system:camera:export")
    @Log(title = "视频配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCamera tbCamera)
    {
        List<TbCamera> list = tbCameraService.selectTbCameraList(tbCamera);
        ExcelUtil<TbCamera> util = new ExcelUtil<TbCamera>(TbCamera.class);
        util.exportExcel(response, list, "视频配置数据");
    }

    /**
     * 获取视频配置详细信息
     */
    @RequiresPermissions("system:camera:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCameraService.selectTbCameraById(id));
    }

    /**
     * 新增视频配置
     */
    @RequiresPermissions("system:camera:add")
    @Log(title = "视频配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCamera tbCamera)
    {
        return toAjax(tbCameraService.insertTbCamera(tbCamera));
    }

    /**
     * 修改视频配置
     */
    @RequiresPermissions("system:camera:edit")
    @Log(title = "视频配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCamera tbCamera)
    {
        return toAjax(tbCameraService.updateTbCamera(tbCamera));
    }

    /**
     * 删除视频配置
     */
    @RequiresPermissions("system:camera:remove")
    @Log(title = "视频配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCameraService.deleteTbCameraByIds(ids));
    }


    /**
     * 获取企业模块|菜单权限树
     */
    @GetMapping(value = "/tree")
    public AjaxResult tree() {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("depts", tbCameraService.selectTree());
        return ajax;
    }


}
