package com.ruoyi.project.patrol.patrol.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.patrol.patrol.domain.TPatrolIssues;
import com.ruoyi.project.patrol.patrol.service.ITPatrolIssuesService;
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.List;

/**
 * 检查问题记录Controller
 *
 * @author ruoyi
 * @date 2023-09-25
 */
@RestController
@RequestMapping("/patrol/issues")
public class TPatrolIssuesController extends BaseController
{
    @Autowired
    private ITPatrolIssuesService tPatrolIssuesService;

    /**
     * 查询检查问题记录列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:issues:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPatrolIssues tPatrolIssues)
    {
        startPage();
        List<TPatrolIssues> list = tPatrolIssuesService.selectTPatrolIssuesList(tPatrolIssues);
        return getDataTable(list);
    }

    /**
     * 导出检查问题记录列表
     */
    
    @Log(title = "检查问题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TPatrolIssues tPatrolIssues)
    {
        List<TPatrolIssues> list = tPatrolIssuesService.selectTPatrolIssuesList(tPatrolIssues);
        ExcelUtil<TPatrolIssues> util = new ExcelUtil<TPatrolIssues>(TPatrolIssues.class);
        return util.exportExcel(list,  "检查问题记录数据");
    }

    /**
     * 获取检查问题记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:issues:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tPatrolIssuesService.selectTPatrolIssuesById(id));
    }

    /**
     * 新增检查问题记录
     */
    @PreAuthorize("@ss.hasPermi('patrol:issues:add')")
    @Log(title = "检查问题记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPatrolIssues tPatrolIssues)
    {
        return toAjax(tPatrolIssuesService.insertTPatrolIssues(tPatrolIssues));
    }

    /**
     * 修改检查问题记录
     */
    @PreAuthorize("@ss.hasPermi('patrol:issues:edit')")
    @Log(title = "检查问题记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPatrolIssues tPatrolIssues)
    {
        return toAjax(tPatrolIssuesService.updateTPatrolIssues(tPatrolIssues));
    }

    /**
     * 删除检查问题记录
     */
    @PreAuthorize("@ss.hasPermi('patrol:issues:remove')")
    @Log(title = "检查问题记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPatrolIssuesService.deleteTPatrolIssuesByIds(ids));
    }
}
