package com.zehong.web.controller.train;

import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.enums.BusinessType;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.train.TTrainCourseBank;
import com.zehong.system.service.train.ITTrainCourseBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * bankController
 * 题库管理
 * @author zehong
 * @date 2022-12-14
 */
@RestController
@RequestMapping("/train/bank")
public class TTrainCourseBankController extends BaseController
{
    @Autowired
    private ITTrainCourseBankService tTrainCourseBankService;

    /**
     * 查询题库列表
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTrainCourseBank tTrainCourseBank)
    {
        startPage();
        List<TTrainCourseBank> list = tTrainCourseBankService.selectTTrainCourseBankList(tTrainCourseBank);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:export')")
    @Log(title = "bank", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TTrainCourseBank tTrainCourseBank)
    {
        List<TTrainCourseBank> list = tTrainCourseBankService.selectTTrainCourseBankList(tTrainCourseBank);
        ExcelUtil<TTrainCourseBank> util = new ExcelUtil<TTrainCourseBank>(TTrainCourseBank.class);
        return util.exportExcel(list, "bank数据");
    }

    /**
     * 获取bank详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:query')")
    @GetMapping(value = "/{bankId}")
    public AjaxResult getInfo(@PathVariable("bankId") Long bankId)
    {
        return AjaxResult.success(tTrainCourseBankService.selectTTrainCourseBankById(bankId));
    }

    /**
     * 新增题库
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:add')")
    @Log(title = "bank", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody TTrainCourseBank tTrainCourseBank)
    {
        tTrainCourseBankService.insertTTrainCourseBank(tTrainCourseBank);
        return Math.toIntExact(tTrainCourseBank.getBankId());
    }

    /**
     * 修改bank
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:edit')")
    @Log(title = "bank", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTrainCourseBank tTrainCourseBank)
    {
        return toAjax(tTrainCourseBankService.updateTTrainCourseBank(tTrainCourseBank));
    }

    /**
     * 删除bank
     */
    //@PreAuthorize("@ss.hasPermi('system:bank:remove')")
    @Log(title = "bank", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankIds}")
    public AjaxResult remove(@PathVariable Long[] bankIds)
    {
        return toAjax(tTrainCourseBankService.deleteTTrainCourseBankByIds(bankIds));
    }
}
