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.TSafetyFiredoor;
import com.cpms.project.safety.service.ITSafetyFiredoorService;
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-05-31
 */
@RestController
@RequestMapping("/safety/firedoor")
public class TSafetyFiredoorController extends BaseController
{
    @Autowired
    private ITSafetyFiredoorService tSafetyFiredoorService;

    /**
     * 查询防火门列表
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSafetyFiredoor tSafetyFiredoor)
    {
        startPage();
        List<TSafetyFiredoor> list = tSafetyFiredoorService.selectTSafetyFiredoorList(tSafetyFiredoor);
        return getDataTable(list);
    }

    /**
     * 导出防火门列表
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:export')")
    @Log(title = "防火门", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSafetyFiredoor tSafetyFiredoor)
    {
        List<TSafetyFiredoor> list = tSafetyFiredoorService.selectTSafetyFiredoorList(tSafetyFiredoor);
        ExcelUtil<TSafetyFiredoor> util = new ExcelUtil<TSafetyFiredoor>(TSafetyFiredoor.class);
        return util.exportExcel( list, "防火门数据");
    }

    /**
     * 获取防火门详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tSafetyFiredoorService.selectTSafetyFiredoorById(id));
    }

    /**
     * 新增防火门
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:add')")
    @Log(title = "防火门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSafetyFiredoor tSafetyFiredoor)
    {
        return toAjax(tSafetyFiredoorService.insertTSafetyFiredoor(tSafetyFiredoor));
    }

    /**
     * 修改防火门
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:edit')")
    @Log(title = "防火门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSafetyFiredoor tSafetyFiredoor)
    {
        return toAjax(tSafetyFiredoorService.updateTSafetyFiredoor(tSafetyFiredoor));
    }

    /**
     * 删除防火门
     */
    @PreAuthorize("@ss.hasPermi('safety:firedoor:remove')")
    @Log(title = "防火门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSafetyFiredoorService.deleteTSafetyFiredoorByIds(ids));
    }
}
