package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.hardwareVersion.domain.HardwareVersion;
import com.ruoyi.ss.hardwareVersion.service.IHardwareVersionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 硬件版本Controller
 *
 * @author qiuzhenzhao
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/system/hardwareVersion")
public class HardwareVersionController extends BaseController
{
    @Autowired
    private IHardwareVersionService eHardwareVersionService;

    /**
     * 查询硬件版本列表
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:list')")
    @GetMapping("/list")
    public TableDataInfo list(HardwareVersion eHardwareVersion)
    {
        startPage();
        List<HardwareVersion> list = eHardwareVersionService.selectEHardwareVersionList(eHardwareVersion);
        return getDataTable(list);
    }

    /**
     * 导出硬件版本列表
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:export')")
    @Log(title = "硬件版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HardwareVersion hardwareVersion)
    {
        List<HardwareVersion> list = eHardwareVersionService.selectEHardwareVersionList(hardwareVersion);
        ExcelUtil<HardwareVersion> util = new ExcelUtil<HardwareVersion>(HardwareVersion.class);
        util.exportExcel(response, list, "硬件版本数据");
    }

    /**
     * 获取硬件版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eHardwareVersionService.selectEHardwareVersionById(id));
    }

    /**
     * 新增硬件版本
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:add')")
    @Log(title = "硬件版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HardwareVersion EHardwareVersion)
    {
        return toAjax(eHardwareVersionService.insertEHardwareVersion(EHardwareVersion));
    }

    /**
     * 修改硬件版本
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:edit')")
    @Log(title = "硬件版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HardwareVersion EHardwareVersion)
    {
        return toAjax(eHardwareVersionService.updateEHardwareVersion(EHardwareVersion));
    }

    /**
     * 删除硬件版本
     */
    @PreAuthorize("@ss.hasPermi('system:hardwareVersion:remove')")
    @Log(title = "硬件版本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eHardwareVersionService.deleteEHardwareVersionByIds(ids));
    }
}
