package com.ruoyi.project.training.elearn.controller;

import java.util.List;

import com.ruoyi.project.training.elearn.domain.TElUserQu;
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.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.training.elearn.domain.TElRepo;
import com.ruoyi.project.training.elearn.service.ITElRepoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 题库Controller
 *
 * @author ssy
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/elearn/repo")
public class TElRepoController extends BaseController
{
    @Autowired
    private ITElRepoService tElRepoService;

    /**
     * 查询题库列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TElRepo tElRepo)
    {
        startPage();
        List<TElRepo> list = tElRepoService.selectTElRepoList(tElRepo);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TElRepo tElRepo)
    {
        List<TElRepo> list = tElRepoService.selectTElRepoList(tElRepo);
        ExcelUtil<TElRepo> util = new ExcelUtil<TElRepo>(TElRepo.class);
        return util.exportExcel(list, "repo");
    }

    /**
     * 获取题库详细信息
     */
    @GetMapping(value = "/{repoId}")
    public AjaxResult getInfo(@PathVariable("repoId") Long repoId)
    {
        return AjaxResult.success(tElRepoService.selectTElRepoById(repoId));
    }

    /**
     * 新增题库
     */
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TElRepo tElRepo)
    {
        return toAjax(tElRepoService.insertTElRepo(tElRepo));
    }

    /**
     * 修改题库
     */
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TElRepo tElRepo)
    {
        return toAjax(tElRepoService.updateTElRepo(tElRepo));
    }

    /**
     * 删除题库
     */
    @Log(title = "题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repoIds}")
    public AjaxResult remove(@PathVariable Long[] repoIds)
    {
        return toAjax(tElRepoService.deleteTElRepoByIds(repoIds));
    }
}
