package com.ruoyi.project.sems.controller;

import java.util.List;

import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
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.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.sems.domain.TSpecReport;
import com.ruoyi.project.sems.service.ITSpecReportService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 特种设备报告Controller
 *
 * @author Ly
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/sems/specReport")
public class TSpecReportController extends BaseController
{
    @Autowired
    private ITSpecReportService tSpecReportService;

    /**
     * 查询特种设备报告列表
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSpecReport tSpecReport , HttpServletResponse response)
    {
        startPage();
        List<TSpecReport> list = tSpecReportService.selectTSpecReportList(tSpecReport);
        return getDataTable(list);
    }

    /**
     * 导出特种设备报告列表
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:export')")
    @Log(title = "特种设备报告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSpecReport tSpecReport)
    {
        List<TSpecReport> list = tSpecReportService.selectTSpecReportList(tSpecReport);
        ExcelUtil<TSpecReport> util = new ExcelUtil<TSpecReport>(TSpecReport.class);
        return util.exportExcel(list, "specReport");
    }

    /**
     * 获取特种设备报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tSpecReportService.selectTSpecReportById(id));
    }

    /**
     * 新增特种设备报告
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:add')")
    @Log(title = "特种设备报告", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TSpecReport tSpecReport, HttpServletResponse response)
    {
        return toAjax(tSpecReportService.insertTSpecReport(tSpecReport,response));
    }

    /**
     * 修改特种设备报告
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:edit')")
    @Log(title = "特种设备报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSpecReport tSpecReport)
    {
        return toAjax(tSpecReportService.updateTSpecReport(tSpecReport));
    }

    /**
     * 删除特种设备报告
     */
    @PreAuthorize("@ss.hasPermi('sems:specReport:remove')")
    @Log(title = "特种设备报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSpecReportService.deleteTSpecReportByIds(ids));
    }
}
