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

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

import com.ruoyi.wgz.domain.WgzQuestionSave;
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.WgzQuestionSaveQueryBo;
import com.ruoyi.wgz.service.IWgzQuestionSaveService;
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/save")
public class WgzQuestionSaveController extends BaseController {

    private final IWgzQuestionSaveService iWgzQuestionSaveService;

    /**
     * 查询用户试卷存储列表
     */
    @ApiOperation("查询用户试卷存储列表")
    @PreAuthorize("@ss.hasPermi('wgz:save:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzQuestionSave> list(@Validated WgzQuestionSaveQueryBo bo) {
        return iWgzQuestionSaveService.queryPageList(bo);
    }

    /**
     * 导出用户试卷存储列表
     */
    @ApiOperation("导出用户试卷存储列表")
    @PreAuthorize("@ss.hasPermi('wgz:save:export')")
    @Log(title = "用户试卷存储", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzQuestionSave> export(@Validated WgzQuestionSaveQueryBo bo) {
        List<WgzQuestionSave> list = iWgzQuestionSaveService.queryList(bo);
        ExcelUtil<WgzQuestionSave> util = new ExcelUtil<WgzQuestionSave>(WgzQuestionSave.class);
        return util.exportExcel(list, "用户试卷存储");
    }

    /**
     * 获取用户试卷存储详细信息
     */
    @ApiOperation("获取用户试卷存储详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:save:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzQuestionSave> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzQuestionSaveService.queryById(id));
    }

    /**
     * 新增用户试卷存储
     */
    @ApiOperation("新增用户试卷存储")
    @PreAuthorize("@ss.hasPermi('wgz:save:add')")
    @Log(title = "用户试卷存储", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzQuestionSave bo) {
        return toAjax(iWgzQuestionSaveService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改用户试卷存储
     */
    @ApiOperation("修改用户试卷存储")
    @PreAuthorize("@ss.hasPermi('wgz:save:edit')")
    @Log(title = "用户试卷存储", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzQuestionSave bo) {
        return toAjax(iWgzQuestionSaveService.update(bo) ? 1 : 0);
    }

    /**
     * 删除用户试卷存储
     */
    @ApiOperation("删除用户试卷存储")
    @PreAuthorize("@ss.hasPermi('wgz:save:remove')")
    @Log(title = "用户试卷存储" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iWgzQuestionSaveService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
