package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
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.DeviceLedger;
import com.ruoyi.ems.service.IDeviceLedgerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备台账Controller
 * 
 * @author ruoyi
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/device/ledger")
@Api(value = "EmsDeviceLedgerController", description = "设备台账")
public class DeviceLedgerController extends BaseController
{
    @Autowired
    private IDeviceLedgerService deviceLedgerService;

    /**
     * 查询设备台账列表
     */
    @RequiresPermissions("ems:ledger:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceLedger Ledger)
    {
        startPage();
        List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(Ledger);
        return getDataTable(list);
    }

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

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

    /**
     * 新增设备台账
     */
    @RequiresPermissions("ems:ledger:add")
    @Log(title = "设备台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceLedger Ledger)
    {
        return toAjax(deviceLedgerService.insertDeviceLedger(Ledger));
    }

    /**
     * 修改设备台账
     */
    @RequiresPermissions("ems:ledger:edit")
    @Log(title = "设备台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceLedger Ledger)
    {
        return toAjax(deviceLedgerService.updateDeviceLedger(Ledger));
    }

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