package com.ruoyi.ems.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
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.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ems.domain.AdmEmsDeviceRbook;
import com.ruoyi.ems.service.IAdmEmsDeviceRbookService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备台账Controller
 * 
 * @author ruoyi
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/device/rbook")
@Api(value = "AdmEmsDeviceRbookController", description = "设备台账")
public class AdmEmsDeviceRbookController extends BaseController
{
    @Autowired
    private IAdmEmsDeviceRbookService emsDeviceRbookService;

    /**
     * 查询设备台账列表
     */
    //@RequiresPermissions("ems:rbook:list")
    @GetMapping("/list")
    public TableDataInfo list(AdmEmsDeviceRbook admEmsDeviceRbook)
    {
        startPage();
        List<AdmEmsDeviceRbook> list = emsDeviceRbookService.selectAdmEmsDeviceRbookList(admEmsDeviceRbook);
        return getDataTable(list);
    }

    /**
     * 导出设备台账列表
     */
    @RequiresPermissions("ems:rbook:export")
    @Log(title = "设备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdmEmsDeviceRbook admEmsDeviceRbook)
    {
        List<AdmEmsDeviceRbook> list = emsDeviceRbookService.selectAdmEmsDeviceRbookList(admEmsDeviceRbook);
        ExcelUtil<AdmEmsDeviceRbook> util = new ExcelUtil<AdmEmsDeviceRbook>(AdmEmsDeviceRbook.class);
        util.exportExcel(response, list, "设备台账数据");
    }

    /**
     * 获取设备台账详细信息
     */
    @RequiresPermissions("ems:rbook:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsDeviceRbookService.selectAdmEmsDeviceRbookById(id));
    }

    /**
     * 新增设备台账
     */
    @RequiresPermissions("ems:rbook:add")
    @Log(title = "设备台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdmEmsDeviceRbook admEmsDeviceRbook)
    {
        return toAjax(emsDeviceRbookService.insertAdmEmsDeviceRbook(admEmsDeviceRbook));
    }

    /**
     * 修改设备台账
     */
    @RequiresPermissions("ems:rbook:edit")
    @Log(title = "设备台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdmEmsDeviceRbook admEmsDeviceRbook)
    {
        return toAjax(emsDeviceRbookService.updateAdmEmsDeviceRbook(admEmsDeviceRbook));
    }

    /**
     * 删除设备台账
     */
    @RequiresPermissions("ems:rbook:remove")
    @Log(title = "设备台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsDeviceRbookService.deleteAdmEmsDeviceRbookByIds(ids));
    }
}
