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

/**
 * 学生错题本Controller
 * 
 * @author ruoyi
 * @date 2025-09-25
 */
@RestController
@RequestMapping("/learn/WrongBook")
public class LearnWrongBookController extends BaseController
{
    @Autowired
    private ILearnWrongBookService learnWrongBookService;

    /**
     * 查询学生错题本列表
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:list')")
    @GetMapping("/list")
    public TableDataInfo list(LearnWrongBook learnWrongBook)
    {
        startPage();
        List<LearnWrongBook> list = learnWrongBookService.selectLearnWrongBookList(learnWrongBook);
        return getDataTable(list);
    }

    /**
     * 导出学生错题本列表
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:export')")
    @Log(title = "学生错题本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LearnWrongBook learnWrongBook)
    {
        List<LearnWrongBook> list = learnWrongBookService.selectLearnWrongBookList(learnWrongBook);
        ExcelUtil<LearnWrongBook> util = new ExcelUtil<LearnWrongBook>(LearnWrongBook.class);
        util.exportExcel(response, list, "学生错题本数据");
    }

    /**
     * 获取学生错题本详细信息
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:query')")
    @GetMapping(value = "/{wrongId}")
    public AjaxResult getInfo(@PathVariable("wrongId") Long wrongId)
    {
        return success(learnWrongBookService.selectLearnWrongBookByWrongId(wrongId));
    }

    /**
     * 新增学生错题本
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:add')")
    @Log(title = "学生错题本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LearnWrongBook learnWrongBook)
    {
        return toAjax(learnWrongBookService.insertLearnWrongBook(learnWrongBook));
    }

    /**
     * 修改学生错题本
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:edit')")
    @Log(title = "学生错题本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LearnWrongBook learnWrongBook)
    {
        return toAjax(learnWrongBookService.updateLearnWrongBook(learnWrongBook));
    }

    /**
     * 删除学生错题本
     */
    @PreAuthorize("@ss.hasPermi('learn:WrongBook:remove')")
    @Log(title = "学生错题本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wrongIds}")
    public AjaxResult remove(@PathVariable Long[] wrongIds)
    {
        return toAjax(learnWrongBookService.deleteLearnWrongBookByWrongIds(wrongIds));
    }
}
