package com.ruoyi.web.controller.learn;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.LearnExaminee;
import com.ruoyi.learn.service.ILearnExamineeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 答卷Controller
 * 
 * @author ruoyi
 * @date 2025-09-25
 */
@RestController
@RequestMapping("/learn/examinee")
public class LearnExamineeController extends BaseController
{
    @Autowired
    private ILearnExamineeService learnExamineeService;

    /**
     * 查询答卷列表
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:list')")
    @GetMapping("/list")
    public TableDataInfo list(LearnExaminee learnExaminee)
    {
        startPage();
        List<LearnExaminee> list = learnExamineeService.selectLearnExamineeList(learnExaminee);
        return getDataTable(list);
    }

    /**
     * 导出答卷列表
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:export')")
    @Log(title = "答卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LearnExaminee learnExaminee)
    {
        List<LearnExaminee> list = learnExamineeService.selectLearnExamineeList(learnExaminee);
        ExcelUtil<LearnExaminee> util = new ExcelUtil<LearnExaminee>(LearnExaminee.class);
        util.exportExcel(response, list, "答卷数据");
    }

    /**
     * 获取答卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:query')")
    @GetMapping(value = "/{examineeId}")
    public AjaxResult getInfo(@PathVariable("examineeId") Long examineeId)
    {
        return success(learnExamineeService.selectLearnExamineeByExamineeId(examineeId));
    }

    /**
     * 新增答卷
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:add')")
    @Log(title = "答卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LearnExaminee learnExaminee)
    {
        return toAjax(learnExamineeService.insertLearnExaminee(learnExaminee));
    }

    /**
     * 修改答卷
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:edit')")
    @Log(title = "答卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LearnExaminee learnExaminee)
    {
        return toAjax(learnExamineeService.updateLearnExaminee(learnExaminee));
    }

    /**
     * 删除答卷
     */
    @PreAuthorize("@ss.hasPermi('learn:examinee:remove')")
    @Log(title = "答卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examineeIds}")
    public AjaxResult remove(@PathVariable Long[] examineeIds)
    {
        return toAjax(learnExamineeService.deleteLearnExamineeByExamineeIds(examineeIds));
    }
}
