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

/**
 * 测量环境数据Controller
 *
 * @author wgk
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meas/envData")
public class MeasEnvDataController extends BaseController {
    @Autowired
    private IMeasEnvDataService measEnvDataService;

    /**
     * 查询测量环境数据列表
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasEnvData measEnvData) {
        startPage();
        List<MeasEnvData> list = measEnvDataService.selectMeasEnvDataList(measEnvData);
        return getDataTable(list);
    }

    /**
     * 导出测量环境数据列表
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:export')")
    @Log(title = "测量环境数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasEnvData measEnvData) {
        List<MeasEnvData> list = measEnvDataService.selectMeasEnvDataList(measEnvData);
        ExcelUtil<MeasEnvData> util = new ExcelUtil<MeasEnvData>(MeasEnvData.class);
        util.exportExcel(response, list, "测量环境数据数据");
    }

    /**
     * 获取测量环境数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measEnvDataService.selectMeasEnvDataById(id));
    }

    /**
     * 新增测量环境数据
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:add')")
    @Log(title = "测量环境数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasEnvData measEnvData) {
        MeasEnvData returnValue = measEnvDataService.insertMeasEnvData(measEnvData);
        if(returnValue == null){
            return error();
        } else {
            return success(returnValue);
        }
    }

    /**
     * 修改测量环境数据
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:edit')")
    @Log(title = "测量环境数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasEnvData measEnvData) {
        return toAjax(measEnvDataService.updateMeasEnvData(measEnvData));
    }

    /**
     * 删除测量环境数据
     */
    @PreAuthorize("@ss.hasPermi('meas:envData:remove')")
    @Log(title = "测量环境数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measEnvDataService.deleteMeasEnvDataByIds(ids));
    }
}
