package com.meas.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.meas.common.annotation.Log;
import com.meas.common.core.controller.BaseController;
import com.meas.common.core.domain.AjaxResult;
import com.meas.common.enums.BusinessType;
import com.meas.system.domain.MeasSpectralRadiation;
import com.meas.system.service.IMeasSpectralRadiationService;
import com.meas.common.utils.poi.ExcelUtil;
import com.meas.common.core.page.TableDataInfo;

/**
 * 光谱辐射Controller
 *
 * @author wgk
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meas/radiation")
public class MeasSpectralRadiationController extends BaseController {
    @Autowired
    private IMeasSpectralRadiationService measSpectralRadiationService;

    /**
     * 查询光谱辐射列表
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasSpectralRadiation measSpectralRadiation) {
        startPage();
        List<MeasSpectralRadiation> list = measSpectralRadiationService.selectMeasSpectralRadiationList(measSpectralRadiation);
        return getDataTable(list);
    }

    /**
     * 导出光谱辐射列表
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:export')")
    @Log(title = "光谱辐射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasSpectralRadiation measSpectralRadiation) {
        List<MeasSpectralRadiation> list = measSpectralRadiationService.selectMeasSpectralRadiationList(measSpectralRadiation);
        ExcelUtil<MeasSpectralRadiation> util = new ExcelUtil<MeasSpectralRadiation>(MeasSpectralRadiation.class);
        util.exportExcel(response, list, "光谱辐射数据");
    }

    /**
     * 获取光谱辐射详细信息
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measSpectralRadiationService.selectMeasSpectralRadiationById(id));
    }

    /**
     * 新增光谱辐射
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:add')")
    @Log(title = "光谱辐射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasSpectralRadiation measSpectralRadiation) {
        MeasSpectralRadiation returnValue = measSpectralRadiationService.insertMeasSpectralRadiation(measSpectralRadiation);
        if (returnValue == null) {
            return error();
        } else {
            return success(returnValue);
        }
    }

    /**
     * 修改光谱辐射
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:edit')")
    @Log(title = "光谱辐射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasSpectralRadiation measSpectralRadiation) {
        return toAjax(measSpectralRadiationService.updateMeasSpectralRadiation(measSpectralRadiation));
    }

    /**
     * 删除光谱辐射
     */
    @PreAuthorize("@ss.hasPermi('meas:radiation:remove')")
    @Log(title = "光谱辐射", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measSpectralRadiationService.deleteMeasSpectralRadiationByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('meas:radiation:query')")
    @GetMapping(value = "/getInfoByEnvDataId/{envDataId}")
    public AjaxResult selectResultsByEnvDataId(@PathVariable("envDataId") Long envDataId) {
        return success(measSpectralRadiationService.selectResultsByEnvDataId(envDataId));
    }
}
