package com.ruoyi.project.check.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.check.domain.TCheckStandardgases;
import com.ruoyi.project.check.service.ITCheckStandardgasesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 标准气体Controller
 *
 * @author ruoyi
 * @date 2022-11-22
 */
@RestController
@RequestMapping("/check/standardgases")
public class TCheckStandardgasesController extends BaseController {
    @Autowired
    private ITCheckStandardgasesService tCheckStandardgasesService;

    /**
     * 查询标准气体列表
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCheckStandardgases tCheckStandardgases) {
        startPage();
        List<TCheckStandardgases> list = tCheckStandardgasesService.selectTCheckStandardgasesList(tCheckStandardgases);
        return getDataTable(list);
    }

    @GetMapping("/allStandardgases")
    public AjaxResult allStandardgases() {
        return AjaxResult.success(tCheckStandardgasesService.selectAllStandardgases());
    }

    /**
     * 导出标准气体列表
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:export')")
    @Log(title = "标准气体导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCheckStandardgases tCheckStandardgases) {
        List<TCheckStandardgases> list = tCheckStandardgasesService.selectTCheckStandardgasesList(tCheckStandardgases);
        ExcelUtil<TCheckStandardgases> util = new ExcelUtil<TCheckStandardgases>(TCheckStandardgases.class);
        util.exportExcel(response, list, "标准气体数据");
    }

    /**
     * 获取标准气体详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tCheckStandardgasesService.selectTCheckStandardgasesById(id));
    }

    /**
     * 新增标准气体
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:add')")
    @Log(title = "标准气体新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCheckStandardgases tCheckStandardgases) {
        tCheckStandardgases.setUpdatedate(new Date());
        tCheckStandardgases.setUpdaterCode(getUserId());
        tCheckStandardgases.setCreaterCode(getUserId());
        return toAjax(tCheckStandardgasesService.insertTCheckStandardgases(tCheckStandardgases));
    }

    /**
     * 修改标准气体
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:edit')")
    @Log(title = "标准气体修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCheckStandardgases tCheckStandardgases) {
        tCheckStandardgases.setUpdatedate(new Date());
        tCheckStandardgases.setUpdaterCode(getUserId());
        return toAjax(tCheckStandardgasesService.updateTCheckStandardgases(tCheckStandardgases));
    }

    /**
     * 删除标准气体
     */
    @PreAuthorize("@ss.hasPermi('check:standardgases:remove')")
    @Log(title = "标准气体删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tCheckStandardgasesService.deleteTCheckStandardgasesByIds(ids));
    }
}
