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.MeasTransmissionRate;
import com.meas.system.service.IMeasTransmissionRateService;
import com.meas.common.utils.poi.ExcelUtil;
import com.meas.common.core.page.TableDataInfo;

/**
 * 透过率Controller
 *
 * @author wgk
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meas/transmissionRate")
public class MeasTransmissionRateController extends BaseController {
    @Autowired
    private IMeasTransmissionRateService measTransmissionRateService;

    /**
     * 查询透过率列表
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasTransmissionRate measTransmissionRate) {
        startPage();
        List<MeasTransmissionRate> list = measTransmissionRateService.selectMeasTransmissionRateList(measTransmissionRate);
        return getDataTable(list);
    }

    /**
     * 导出透过率列表
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:export')")
    @Log(title = "透过率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasTransmissionRate measTransmissionRate) {
        List<MeasTransmissionRate> list = measTransmissionRateService.selectMeasTransmissionRateList(measTransmissionRate);
        ExcelUtil<MeasTransmissionRate> util = new ExcelUtil<MeasTransmissionRate>(MeasTransmissionRate.class);
        util.exportExcel(response, list, "透过率数据");
    }

    /**
     * 获取透过率详细信息
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measTransmissionRateService.selectMeasTransmissionRateById(id));
    }

    /**
     * 新增透过率
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:add')")
    @Log(title = "透过率", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasTransmissionRate measTransmissionRate) {
        MeasTransmissionRate returnValue = measTransmissionRateService.insertMeasTransmissionRate(measTransmissionRate);
        if (returnValue == null) {
            return error();
        } else {
            return success(returnValue);
        }
    }

    /**
     * 修改透过率
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:edit')")
    @Log(title = "透过率", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasTransmissionRate measTransmissionRate) {
        return toAjax(measTransmissionRateService.updateMeasTransmissionRate(measTransmissionRate));
    }

    /**
     * 删除透过率
     */
    @PreAuthorize("@ss.hasPermi('meas:transmissionRate:remove')")
    @Log(title = "透过率", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measTransmissionRateService.deleteMeasTransmissionRateByIds(ids));
    }

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