package com.meas.system.controller;

import com.meas.common.annotation.Log;
import com.meas.common.core.controller.BaseController;
import com.meas.common.core.domain.AjaxResult;
import com.meas.common.core.page.TableDataInfo;
import com.meas.common.enums.BusinessType;
import com.meas.common.utils.poi.ExcelUtil;
import com.meas.system.domain.MeasEngineModel;
import com.meas.system.service.IMeasEngineModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 发动机型号Controller
 *
 * @author km
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meas/engineModel")
public class MeasEngineModelController extends BaseController {
    @Autowired
    private IMeasEngineModelService measEngineModelService;

    /**
     * 查询发动机型号列表
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasEngineModel measEngineModel) {
        startPage();
        List<MeasEngineModel> list = measEngineModelService.selectMeasEngineModelList(measEngineModel);
        return getDataTable(list);
    }

    /**
     * 导出发动机型号列表
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:export')")
    @Log(title = "发动机型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasEngineModel measEngineModel) {
        List<MeasEngineModel> list = measEngineModelService.selectMeasEngineModelList(measEngineModel);
        ExcelUtil<MeasEngineModel> util = new ExcelUtil<MeasEngineModel>(MeasEngineModel.class);
        util.exportExcel(response, list, "发动机型号数据");
    }

    /**
     * 获取发动机型号详细信息
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measEngineModelService.selectMeasEngineModelById(id));
    }

    /**
     * 新增发动机型号
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:add')")
    @Log(title = "发动机型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasEngineModel measEngineModel) {
        return toAjax(measEngineModelService.insertMeasEngineModel(measEngineModel));
    }

    /**
     * 修改发动机型号
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:edit')")
    @Log(title = "发动机型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasEngineModel measEngineModel) {
        return toAjax(measEngineModelService.updateMeasEngineModel(measEngineModel));
    }

    /**
     * 删除发动机型号
     */
    @PreAuthorize("@ss.hasPermi('meas:engineModel:remove')")
    @Log(title = "发动机型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measEngineModelService.deleteMeasEngineModelByIds(ids));
    }

    @GetMapping("/getOption")
    public AjaxResult getOption(){
        return success(measEngineModelService.getOption());
    }
}
