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

import java.util.List;
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.spec.domain.TStQuestionBank;
import com.ruoyi.project.training.spec.service.ITStQuestionBankService;
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 ruoyi
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/spec/bank")
public class TStQuestionBankController extends BaseController
{
    @Autowired
    private ITStQuestionBankService tStQuestionBankService;

    /**
     * 查询专项培训题库列表
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStQuestionBank tStQuestionBank)
    {
        startPage();
        List<TStQuestionBank> list = tStQuestionBankService.selectTStQuestionBankList(tStQuestionBank);
        return getDataTable(list);
    }

    /**
     * 导出专项培训题库列表
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:export')")
    @Log(title = "专项培训题库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TStQuestionBank tStQuestionBank)
    {
        List<TStQuestionBank> list = tStQuestionBankService.selectTStQuestionBankList(tStQuestionBank);
        ExcelUtil<TStQuestionBank> util = new ExcelUtil<TStQuestionBank>(TStQuestionBank.class);
        return util.exportExcel(list, "bank");
    }

    /**
     * 获取专项培训题库详细信息
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tStQuestionBankService.selectTStQuestionBankById(id));
    }

    /**
     * 新增专项培训题库
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:add')")
    @Log(title = "专项培训题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStQuestionBank tStQuestionBank)
    {
        return toAjax(tStQuestionBankService.insertTStQuestionBank(tStQuestionBank));
    }

    /**
     * 修改专项培训题库
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:edit')")
    @Log(title = "专项培训题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStQuestionBank tStQuestionBank)
    {
        return toAjax(tStQuestionBankService.updateTStQuestionBank(tStQuestionBank));
    }

    /**
     * 删除专项培训题库
     */
    @PreAuthorize("@ss.hasPermi('spec:bank:remove')")
    @Log(title = "专项培训题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tStQuestionBankService.deleteTStQuestionBankByIds(ids));
    }
}
