package com.ruoyi.web.controller.wgz.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.wgz.domain.WgzQuestionsConfiguration;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
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.wgz.bo.WgzQuestionsConfigurationQueryBo;
import com.ruoyi.wgz.service.IWgzQuestionsConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 题库配置Controller
 *
 * @author ruoyi
 * @date 2025-02-17
 */
@Api(value = "题库配置控制器", tags = {"题库配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/configuration")
public class WgzQuestionsConfigurationController extends BaseController {

    private final IWgzQuestionsConfigurationService iWgzQuestionsConfigurationService;

    /**
     * 查询题库配置列表
     */
    @ApiOperation("查询题库配置列表")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzQuestionsConfiguration> list(@Validated WgzQuestionsConfigurationQueryBo bo) {
        return iWgzQuestionsConfigurationService.queryPageList(bo);
    }

    /**
     * 导出题库配置列表
     */
    @ApiOperation("导出题库配置列表")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:export')")
    @Log(title = "题库配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzQuestionsConfiguration> export(@Validated WgzQuestionsConfigurationQueryBo bo) {
        List<WgzQuestionsConfiguration> list = iWgzQuestionsConfigurationService.queryList(bo);
        ExcelUtil<WgzQuestionsConfiguration> util = new ExcelUtil<WgzQuestionsConfiguration>(WgzQuestionsConfiguration.class);
        return util.exportExcel(list, "题库配置");
    }

    /**
     * 获取题库配置详细信息
     */
    @ApiOperation("获取题库配置详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzQuestionsConfiguration> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzQuestionsConfigurationService.queryById(id));
    }

    /**
     * 新增题库配置
     */
    @ApiOperation("新增题库配置")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:add')")
    @Log(title = "题库配置", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzQuestionsConfiguration bo) {
        return toAjax(iWgzQuestionsConfigurationService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改题库配置
     */
    @ApiOperation("修改题库配置")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:edit')")
    @Log(title = "题库配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzQuestionsConfiguration bo) {
        return toAjax(iWgzQuestionsConfigurationService.update(bo) ? 1 : 0);
    }

    /**
     * 删除题库配置
     */
    @ApiOperation("删除题库配置")
    @PreAuthorize("@ss.hasPermi('wgz:configuration:remove')")
    @Log(title = "题库配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iWgzQuestionsConfigurationService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
