package com.fms.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.fms.common.annotation.Log;
import com.fms.common.core.controller.BaseController;
import com.fms.common.core.domain.AjaxResult;
import com.fms.common.enums.BusinessType;
import com.fms.system.domain.Brand;
import com.fms.system.service.IBrandService;
import com.fms.common.utils.poi.ExcelUtil;
import com.fms.common.core.page.TableDataInfo;

/**
 * 机型系列Controller
 *
 * @author Allen
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/system/brand")
public class BrandController extends BaseController
{
    @Autowired
    private IBrandService brandService;

    /**
     * 查询机型系列列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(Brand brand)
    {
        startPage();
        List<Brand> list = brandService.selectBrandList(brand);
        return getDataTable(list);
    }

    /**
     * 导出机型系列列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:export')")
    @Log(title = "机型系列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Brand brand)
    {
        List<Brand> list = brandService.selectBrandList(brand);
        ExcelUtil<Brand> util = new ExcelUtil<Brand>(Brand.class);
        util.exportExcel(response, list, "机型系列数据");
    }

    /**
     * 获取机型系列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:brand:query')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return success(brandService.selectBrandByBrandId(brandId));
    }

    /**
     * 新增机型系列
     */
    @PreAuthorize("@ss.hasPermi('system:brand:add')")
    @Log(title = "机型系列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Brand brand)
    {
        return toAjax(brandService.insertBrand(brand));
    }

    /**
     * 修改机型系列
     */
    @PreAuthorize("@ss.hasPermi('system:brand:edit')")
    @Log(title = "机型系列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Brand brand)
    {
        return toAjax(brandService.updateBrand(brand));
    }

    /**
     * 删除机型系列
     */
    @PreAuthorize("@ss.hasPermi('system:brand:remove')")
    @Log(title = "机型系列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Long[] brandIds)
    {
        return toAjax(brandService.deleteBrandByBrandIds(brandIds));
    }
}
