package com.ruoyi.web.controller.learn;

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.learn.domain.LearnPaper;
import com.ruoyi.learn.service.ILearnPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷Controller
 * 
 * @author ruoyi
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/learn/paper")
@Api("后台-学习 - 卷")
public class LearnPaperController extends BaseController
{
    @Autowired
    private ILearnPaperService learnPaperService;

    /**
     * 查询试卷列表
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(LearnPaper learnPaper)
    {
        startPage();
        List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
        return getDataTable(list);
    }

    /**
     * 导出试卷列表
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:export')")
    @Log(title = "试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LearnPaper learnPaper)
    {
        List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
        ExcelUtil<LearnPaper> util = new ExcelUtil<LearnPaper>(LearnPaper.class);
        util.exportExcel(response, list, "试卷数据");
    }

    /**
     * 获取试卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(learnPaperService.selectLearnPaperById(id));
    }

    /**
     * 新增试卷
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:add')")
    @Log(title = "试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LearnPaper learnPaper)
    {
        return toAjax(learnPaperService.insertLearnPaper(learnPaper));
    }

    /**
     * 修改试卷
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:edit')")
    @Log(title = "试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LearnPaper learnPaper)
    {
        return toAjax(learnPaperService.updateLearnPaper(learnPaper));
    }

    /**
     * 删除试卷
     */
    @PreAuthorize("@ss.hasPermi('learn:paper:remove')")
    @Log(title = "试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(learnPaperService.deleteLearnPaperByIds(ids));
    }
}
