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

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

import com.ruoyi.wgz.domain.WgzQuestionCategory;
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.WgzQuestionCategoryQueryBo;
import com.ruoyi.wgz.service.IWgzQuestionCategoryService;
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/category")
public class WgzQuestionCategoryController extends BaseController {

    private final IWgzQuestionCategoryService iWgzQuestionCategoryService;

    /**
     * 查询题库_题库类别列表
     */
    @ApiOperation("查询题库_题库类别列表")
    @PreAuthorize("@ss.hasPermi('wgz:category:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzQuestionCategory> list(@Validated WgzQuestionCategoryQueryBo bo) {
        return iWgzQuestionCategoryService.queryPageList(bo);
    }

    /**
     * 导出题库_题库类别列表
     */
    @ApiOperation("导出题库_题库类别列表")
    @PreAuthorize("@ss.hasPermi('wgz:category:export')")
    @Log(title = "题库_题库类别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzQuestionCategory> export(@Validated WgzQuestionCategoryQueryBo bo) {
        List<WgzQuestionCategory> list = iWgzQuestionCategoryService.queryList(bo);
        ExcelUtil<WgzQuestionCategory> util = new ExcelUtil<WgzQuestionCategory>(WgzQuestionCategory.class);
        return util.exportExcel(list, "题库_题库类别");
    }

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

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

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

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