package com.yanzhu.manage.controller;

import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.manage.domain.BusExamQuestion;
import com.yanzhu.manage.service.IBusExamQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 基础题库Controller
 * 
 * @author JiangYuQi
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/busExamQuestion")
public class BusExamQuestionController extends BaseController
{
    @Autowired
    private IBusExamQuestionService busExamQuestionService;

    /**
     * 查询基础题库列表
     */
    @RequiresPermissions("manage:busExamQuestion:list")
    @GetMapping("/list")
    public TableDataInfo list(BusExamQuestion busExamQuestion)
    {
        startPage();
        List<BusExamQuestion> list = busExamQuestionService.selectBusExamQuestionList(busExamQuestion);
        return getDataTable(list);
    }

    /**
     * 导出基础题库列表
     */
    @RequiresPermissions("manage:busExamQuestion:export")
    @Log(title = "基础题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusExamQuestion busExamQuestion)
    {
        List<BusExamQuestion> list = busExamQuestionService.selectBusExamQuestionList(busExamQuestion);
        ExcelUtil<BusExamQuestion> util = new ExcelUtil<BusExamQuestion>(BusExamQuestion.class);
        util.exportExcel(response, list, "基础题库数据");
    }

    /**
     * 获取基础题库详细信息
     */
    @RequiresPermissions("manage:busExamQuestion:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busExamQuestionService.selectBusExamQuestionById(id));
    }

    /**
     * 新增基础题库
     */
    @RequiresPermissions("manage:busExamQuestion:add")
    @Log(title = "基础题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusExamQuestion busExamQuestion)
    {
        return toAjax(busExamQuestionService.insertBusExamQuestion(busExamQuestion));
    }

    /**
     * 修改基础题库
     */
    @RequiresPermissions("manage:busExamQuestion:edit")
    @Log(title = "基础题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusExamQuestion busExamQuestion)
    {
        return toAjax(busExamQuestionService.updateBusExamQuestion(busExamQuestion));
    }

    /**
     * 删除基础题库
     */
    @RequiresPermissions("manage:busExamQuestion:remove")
    @Log(title = "基础题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busExamQuestionService.deleteBusExamQuestionByIds(ids));
    }
}
