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

/**
 * 答卷答案Controller
 * 
 * @author ruoyi
 * @date 2025-09-25
 */
@RestController
@RequestMapping("/learn/answer")
public class LearnAnswerController extends BaseController
{
    @Autowired
    private ILearnAnswerService learnAnswerService;

    /**
     * 查询答卷答案列表
     */
    @PreAuthorize("@ss.hasPermi('learn:answer:list')")
    @GetMapping("/list")
    public TableDataInfo list(LearnAnswer learnAnswer)
    {
        startPage();
        List<LearnAnswer> list = learnAnswerService.selectLearnAnswerList(learnAnswer);
        return getDataTable(list);
    }

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

    /**
     * 获取答卷答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('learn:answer:query')")
    @GetMapping(value = "/{answerId}")
    public AjaxResult getInfo(@PathVariable("answerId") Long answerId)
    {
        return success(learnAnswerService.selectLearnAnswerByAnswerId(answerId));
    }

    /**
     * 新增答卷答案
     */
    @PreAuthorize("@ss.hasPermi('learn:answer:add')")
    @Log(title = "答卷答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LearnAnswer learnAnswer)
    {
        return toAjax(learnAnswerService.insertLearnAnswer(learnAnswer));
    }

    /**
     * 修改答卷答案
     */
    @PreAuthorize("@ss.hasPermi('learn:answer:edit')")
    @Log(title = "答卷答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LearnAnswer learnAnswer)
    {
        return toAjax(learnAnswerService.updateLearnAnswer(learnAnswer));
    }

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