package com.ruoyi.web.controller.document;

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

import com.ruoyi.system.domain.document.ExplainDocument;
import com.ruoyi.system.service.document.IExplainDocumentService;
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.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.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 说明文档Controller
 *
 * @author boman
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/document")
public class ExplainDocumentController extends BaseController
{
    @Autowired
    private IExplainDocumentService explainDocumentService;

/**
 * 查询说明文档列表
 */
@PreAuthorize("@ss.hasPermi('system:document:list')")
@GetMapping("/list")
    public TableDataInfo list(ExplainDocument explainDocument)
    {
        startPage();
        List<ExplainDocument> list = explainDocumentService.selectExplainDocumentList(explainDocument);
        return getDataTable(list);
    }

    /**
     * 导出说明文档列表
     */
    @PreAuthorize("@ss.hasPermi('system:document:export')")
    @Log(title = "说明文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExplainDocument explainDocument)
    {
        List<ExplainDocument> list = explainDocumentService.selectExplainDocumentList(explainDocument);
        ExcelUtil<ExplainDocument> util = new ExcelUtil<ExplainDocument>(ExplainDocument.class);
        util.exportExcel(response, list, "说明文档数据");
    }

    /**
     * 获取说明文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:document:query')")
    @GetMapping(value = "/{explainId}")
    public AjaxResult getInfo(@PathVariable("explainId") Integer explainId)
    {
        return success(explainDocumentService.selectExplainDocumentByExplainId(explainId));
    }

    /**
     * 新增说明文档
     */
    @PreAuthorize("@ss.hasPermi('system:document:add')")
    @Log(title = "说明文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExplainDocument explainDocument)
    {
        return toAjax(explainDocumentService.insertExplainDocument(explainDocument));
    }

    /**
     * 修改说明文档
     */
    @PreAuthorize("@ss.hasPermi('system:document:edit')")
    @Log(title = "说明文档", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ExplainDocument explainDocument)
    {
        return toAjax(explainDocumentService.updateExplainDocument(explainDocument));
    }

    /**
     * 删除说明文档
     */
    @PreAuthorize("@ss.hasPermi('system:document:remove')")
    @Log(title = "说明文档", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{explainIds}")
    public AjaxResult remove(@PathVariable Integer[] explainIds)
    {
        return toAjax(explainDocumentService.deleteExplainDocumentByExplainIds(explainIds));
    }
}
