package com.ruoyi.zongzhi.controller;

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

import io.swagger.annotations.Api;
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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zongzhi.domain.TcSafetyDetection;
import com.ruoyi.zongzhi.service.ITcSafetyDetectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全检测Controller
 * 
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/zongzhi/detection")
@Api(tags = "安全检测")
public class TcSafetyDetectionController extends BaseController
{
    @Autowired
    private ITcSafetyDetectionService tcSafetyDetectionService;

    /**
     * 查询安全检测列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcSafetyDetection tcSafetyDetection)
    {
        startPage();
        List<TcSafetyDetection> list = tcSafetyDetectionService.selectTcSafetyDetectionList(tcSafetyDetection);
        return getDataTable(list);
    }

    /**
     * 导出安全检测列表
     */


    @PostMapping("/export")
    public void export(HttpServletResponse response, TcSafetyDetection tcSafetyDetection)
    {
        List<TcSafetyDetection> list = tcSafetyDetectionService.selectTcSafetyDetectionList(tcSafetyDetection);
        ExcelUtil<TcSafetyDetection> util = new ExcelUtil<TcSafetyDetection>(TcSafetyDetection.class);
        util.exportExcel(response, list, "安全检测数据");
    }

    /**
     * 获取安全检测详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcSafetyDetectionService.selectTcSafetyDetectionById(id));
    }

    /**
     * 新增安全检测
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcSafetyDetection tcSafetyDetection)
    {
        tcSafetyDetection.setIsStatus(true);
        return toAjax(tcSafetyDetectionService.insertTcSafetyDetection(tcSafetyDetection));
    }

    /**
     * 修改安全检测
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcSafetyDetection tcSafetyDetection)
    {
        return toAjax(tcSafetyDetectionService.updateTcSafetyDetection(tcSafetyDetection));
    }

    /**
     * 删除安全检测
     */

	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcSafetyDetectionService.deleteTcSafetyDetectionByIds(ids));
    }
}
