package com.ruoyi.ems.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
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.ElecEqptType;
import com.ruoyi.ems.service.IElecEqptTypeService;
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-08-20
 */
@RestController
@RequestMapping("/elecEqpt/type")
@Api(value = "ElecEqptTypeController", description = "维表-动力柜电气设备类型")
public class ElecEqptTypeController extends BaseController
{
    @Autowired
    private IElecEqptTypeService elecEqptTypeService;

    /**
     * 查询动力柜电器设备类型列表
     */
    @RequiresPermissions("ems:eqptType:list")
    @GetMapping("/list")
    public TableDataInfo list(ElecEqptType eleceqptType)
    {
        startPage();
        List<ElecEqptType> list = elecEqptTypeService.selectElecEqptTypeList(eleceqptType);
        return getDataTable(list);
    }

    /**
     * 导出动力柜电器设备类型列表
     */
    @RequiresPermissions("ems:eqptType:export")
    @Log(title = "动力柜电器设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecEqptType eleceqptType)
    {
        List<ElecEqptType> list = elecEqptTypeService.selectElecEqptTypeList(eleceqptType);
        ExcelUtil<ElecEqptType> util = new ExcelUtil<ElecEqptType>(ElecEqptType.class);
        util.exportExcel(response, list, "动力柜电器设备类型数据");
    }

    /**
     * 获取动力柜电器设备类型详细信息
     */
    @RequiresPermissions("ems:eqptType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elecEqptTypeService.selectElecEqptTypeById(id));
    }

    /**
     * 新增动力柜电器设备类型
     */
    @RequiresPermissions("ems:eqptType:add")
    @Log(title = "动力柜电器设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecEqptType eleceqptType)
    {
        return toAjax(elecEqptTypeService.insertElecEqptType(eleceqptType));
    }

    /**
     * 修改动力柜电器设备类型
     */
    @RequiresPermissions("ems:eqptType:edit")
    @Log(title = "动力柜电器设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecEqptType eleceqptType)
    {
        return toAjax(elecEqptTypeService.updateElecEqptType(eleceqptType));
    }

    /**
     * 删除动力柜电器设备类型
     */
    @RequiresPermissions("ems:eqptType:remove")
    @Log(title = "动力柜电器设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elecEqptTypeService.deleteElecEqptTypeByIds(ids));
    }
}
