package com.mirs.biz.controller;

import com.mirs.biz.domain.BrdfData;
import com.mirs.biz.service.IBrdfDataService;
import com.mirs.common.annotation.Log;
import com.mirs.common.core.controller.BaseController;
import com.mirs.common.core.domain.AjaxResult;
import com.mirs.common.core.page.TableDataInfo;
import com.mirs.common.enums.BusinessType;
import com.mirs.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 org.springframework.web.multipart.MultipartFile;

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

/**
 * BRDF数据Controller
 * 
 * @author kk
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/manage/BRDF")
public class BrdfDataController extends BaseController
{
    @Autowired
    private IBrdfDataService brdfDataService;

    /**
     * 查询BRDF数据列表
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:list')")
    @GetMapping("/list")
    public TableDataInfo list(BrdfData brdfData)
    {
        startPage();
        List<BrdfData> list = brdfDataService.selectBrdfDataList(brdfData);
        return getDataTable(list);
    }

    /**
     * 查询BRDF数据列表
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:list')")
    @GetMapping("/getList")
    public List<BrdfData> getList(BrdfData brdfData)
    {
        List<BrdfData> list = brdfDataService.selectBrdfDataList(brdfData);
        return list;
    }

    /**
     * 导出BRDF数据列表
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:export')")
    @Log(title = "BRDF数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BrdfData brdfData)
    {
        List<BrdfData> list = brdfDataService.selectBrdfDataList(brdfData);
        ExcelUtil<BrdfData> util = new ExcelUtil<BrdfData>(BrdfData.class);
        util.exportExcel(response, list, "BRDF数据数据");
    }

    /**
     * 获取BRDF数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(brdfDataService.selectBrdfDataById(id));
    }

    /**
     * 新增BRDF数据
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:add')")
    @Log(title = "BRDF数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrdfData brdfData)
    {
        return toAjax(brdfDataService.insertBrdfData(brdfData));
    }

    /**
     * 修改BRDF数据
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:edit')")
    @Log(title = "BRDF数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrdfData brdfData)
    {
        return toAjax(brdfDataService.updateBrdfData(brdfData));
    }

    /**
     * 删除BRDF数据
     */
    @PreAuthorize("@ss.hasPermi('manage:BRDF:remove')")
    @Log(title = "BRDF数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(brdfDataService.deleteBrdfDataByIds(ids));
    }

    @Log(title = "BRDF数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('manage:BRDF:add')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BrdfData> util = new ExcelUtil<>(BrdfData.class);
        List<BrdfData> brdfDataList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = brdfDataService.importBrdfData(brdfDataList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<BrdfData> util = new ExcelUtil<>(BrdfData.class);
        util.importTemplateExcel(response, "BRDF数据");
    }
}
