package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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 com.ruoyi.bst.hardwareVersion.domain.HardwareVersion;
import com.ruoyi.bst.hardwareVersion.domain.HardwareVersionQuery;
import com.ruoyi.bst.hardwareVersion.domain.HardwareVersionVO;
import com.ruoyi.bst.hardwareVersion.service.HardwareVersionAssembler;
import com.ruoyi.bst.hardwareVersion.service.HardwareVersionService;
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.common.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 硬件版本Controller
 *
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/bst/hardwareVersion")
public class HardwareVersionController extends BaseController
{
    @Autowired
    private HardwareVersionService hardwareVersionService;

    @Autowired
    private HardwareVersionAssembler hardwareVersionAssembler;
    /**
     * 查询硬件版本列表
     */
    @PreAuthorize("@ss.hasPermi('bst:hardwareVersion:list')")
    @GetMapping("/list")
    public TableDataInfo list(HardwareVersionQuery query)
    {
        startPage();
        startOrderBy();
        List<HardwareVersionVO> list = hardwareVersionService.selectHardwareVersionList(query);
        hardwareVersionAssembler.assembleCount(list);
        return getDataTable(list);
    }

    /**
     * 查询全部硬件版本列表
     */
    @PreAuthorize("@ss.hasPermi('bst:hardwareVersion:list')")
    @GetMapping("/all")
    public AjaxResult all() {
        return success(hardwareVersionService.selectAllNames());
    }

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

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

    /**
     * 新增硬件版本
     */
    @PreAuthorize("@ss.hasPermi('bst:hardwareVersion:add')")
    @Log(title = "新增硬件版本", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.HARDWARE_VERSION)
    @PostMapping
    public AjaxResult add(@RequestBody HardwareVersion hardwareVersion)
    {
        return toAjax(hardwareVersionService.insertHardwareVersion(hardwareVersion));
    }

    /**
     * 修改硬件版本
     */
    @PreAuthorize("@ss.hasPermi('bst:hardwareVersion:edit')")
    @Log(title = "修改硬件版本", businessType = BusinessType.UPDATE, bizIdName = "arg0", bizType = LogBizType.HARDWARE_VERSION)
    @PutMapping
    public AjaxResult edit(@RequestBody HardwareVersion hardwareVersion)
    {
        return toAjax(hardwareVersionService.updateHardwareVersion(hardwareVersion));
    }

    /**
     * 删除硬件版本
     */
    @PreAuthorize("@ss.hasPermi('bst:hardwareVersion:remove')")
    @Log(title = "删除硬件版本", businessType = BusinessType.DELETE, bizIdName = "arg0", bizType = LogBizType.HARDWARE_VERSION)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hardwareVersionService.deleteHardwareVersionByIds(ids));
    }
}
