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

/**
 * 测量批次Controller
 *
 * @author wgk
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meas/measBatch")
public class MeasBatchController extends BaseController {
    @Autowired
    private IMeasBatchService measBatchService;

    /**
     * 查询测量批次列表
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasBatch measBatch) {
        startPage();
        List<MeasBatch> list = measBatchService.selectMeasBatchList(measBatch);
        return getDataTable(list);
    }

    /**
     * 导出测量批次列表
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:export')")
    @Log(title = "测量批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasBatch measBatch) {
        List<MeasBatch> list = measBatchService.selectMeasBatchList(measBatch);
        ExcelUtil<MeasBatch> util = new ExcelUtil<MeasBatch>(MeasBatch.class);
        util.exportExcel(response, list, "测量批次数据");
    }

    /**
     * 获取测量批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measBatchService.selectMeasBatchById(id));
    }

    /**
     * 新增测量批次
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:add')")
    @Log(title = "测量批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasBatch measBatch) {
        return toAjax(measBatchService.insertMeasBatch(measBatch));
    }

    /**
     * 修改测量批次
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:edit')")
    @Log(title = "测量批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasBatch measBatch) {
        return toAjax(measBatchService.updateMeasBatch(measBatch));
    }

    /**
     * 删除测量批次
     */
    @PreAuthorize("@ss.hasPermi('meas:measBatch:remove')")
    @Log(title = "测量批次", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measBatchService.deleteMeasBatchByIds(ids));
    }

    @GetMapping("/getOption/{engineId}")
    public AjaxResult getOption(@PathVariable Long engineId){
        return success(measBatchService.getOption(engineId));
    }
}
