package com.ruoyi.web.controller.learn;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.LearnTest;
import com.ruoyi.learn.service.ILearnTestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷批次Controller
 * 
 * @author ruoyi
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/learn/test")
@Api(tags = "后台-学习 - 批次")
public class LearnTestController extends BaseController
{
    @Autowired
    private ILearnTestService learnTestService;

    /**
     * 查询试卷批次列表
     */
    @PreAuthorize("@ss.hasPermi('learn:test:list')")
    @GetMapping("/list")
    @ApiOperation("列表")
    public AjaxResult list(LearnTest learnTest)
    {
        List<LearnTest> list = learnTestService.selectLearnTestList(learnTest);
        return AjaxResult.success(list);
    }

    /**
     * 导出试卷批次列表
     */
    @PreAuthorize("@ss.hasPermi('learn:test:export')")
    @Log(title = "试卷批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LearnTest learnTest)
    {
        List<LearnTest> list = learnTestService.selectLearnTestList(learnTest);
        ExcelUtil<LearnTest> util = new ExcelUtil<LearnTest>(LearnTest.class);
        util.exportExcel(response, list, "试卷批次数据");
    }

    /**
     * 获取试卷批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('learn:test:query')")
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Integer batchId)
    {
        return success(learnTestService.selectLearnTestByBatchId(batchId));
    }

    /**
     * 新增试卷批次
     */
    @PreAuthorize("@ss.hasPermi('learn:test:add')")
    @Log(title = "试卷批次", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody LearnTest learnTest)
    {
        learnTest.setCreatorId(getUserId());
        return toAjax(learnTestService.insertLearnTest(learnTest));
    }

    /**
     * 修改试卷批次
     */
    @PreAuthorize("@ss.hasPermi('learn:test:edit')")
    @Log(title = "试卷批次", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody LearnTest learnTest)
    {
        return toAjax(learnTestService.updateLearnTest(learnTest));
    }

    /**
     * 删除试卷批次
     */
    @PreAuthorize("@ss.hasPermi('learn:test:remove')")
    @Log(title = "试卷批次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{batchIds}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Integer[] batchIds)
    {
        return toAjax(learnTestService.deleteLearnTestByBatchIds(batchIds));
    }
}
