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

/**
 * 状态Controller
 *
 * @author Allen
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/meas/status")
public class MeasStatusController extends BaseController {
    @Autowired
    private IMeasStatusService measStatusService;

/**
 * 查询状态列表
 */
@PreAuthorize("@ss.hasPermi('system:status:list')")
@GetMapping("/list")
    public TableDataInfo list(MeasStatus measStatus) {
        startPage();
        List<MeasStatus> list = measStatusService.selectMeasStatusList(measStatus);
        return getDataTable(list);
    }

    /**
     * 导出状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:status:export')")
    @Log(title = "状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasStatus measStatus) {
        List<MeasStatus> list = measStatusService.selectMeasStatusList(measStatus);
        ExcelUtil<MeasStatus> util = new ExcelUtil<MeasStatus>(MeasStatus. class);
        util.exportExcel(response, list, "状态数据");
    }

    /**
     * 获取状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:status:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(measStatusService.selectMeasStatusById(id));
    }

    /**
     * 新增状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:add')")
    @Log(title = "状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeasStatus measStatus) {
        return toAjax(measStatusService.insertMeasStatus(measStatus));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:edit')")
    @Log(title = "状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeasStatus measStatus) {
        return toAjax(measStatusService.updateMeasStatus(measStatus));
    }

    /**
     * 删除状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:remove')")
    @Log(title = "状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(measStatusService.deleteMeasStatusByIds(ids));
    }

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