package com.cpms.project.safety.controller;

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

import java.util.List;

/**
 * 灭火器Controller
 *
 * @author ruoyi
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/safety/extinguisher")
public class TSafetyFireExtinguisherController extends BaseController {
    @Autowired
    private ITSafetyFireExtinguisherService tSafetyFireExtinguisherService;

    /**
     * 查询灭火器列表
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSafetyFireExtinguisher tSafetyFireExtinguisher) {
        startPage();
        List<TSafetyFireExtinguisher> list = tSafetyFireExtinguisherService.selectTSafetyFireExtinguisherList(tSafetyFireExtinguisher);
        return getDataTable(list);
    }

    /**
     * 导出灭火器列表
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:export')")
    @Log(title = "灭火器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSafetyFireExtinguisher tSafetyFireExtinguisher) {
        List<TSafetyFireExtinguisher> list = tSafetyFireExtinguisherService.selectTSafetyFireExtinguisherList(tSafetyFireExtinguisher);
        ExcelUtil<TSafetyFireExtinguisher> util = new ExcelUtil<TSafetyFireExtinguisher>(TSafetyFireExtinguisher.class);
        return util.exportExcel(list, "灭火器数据");
    }

    /**
     * 获取灭火器详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tSafetyFireExtinguisherService.selectTSafetyFireExtinguisherById(id));
    }

    /**
     * 新增灭火器
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:add')")
    @Log(title = "灭火器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSafetyFireExtinguisher tSafetyFireExtinguisher) {
        return toAjax(tSafetyFireExtinguisherService.insertTSafetyFireExtinguisher(tSafetyFireExtinguisher));
    }

    /**
     * 修改灭火器
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:edit')")
    @Log(title = "灭火器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSafetyFireExtinguisher tSafetyFireExtinguisher) {
        return toAjax(tSafetyFireExtinguisherService.updateTSafetyFireExtinguisher(tSafetyFireExtinguisher));
    }

    /**
     * 删除灭火器
     */
    @PreAuthorize("@ss.hasPermi('safety:extinguisher:remove')")
    @Log(title = "灭火器", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tSafetyFireExtinguisherService.deleteTSafetyFireExtinguisherByIds(ids));
    }
}
