package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.SysScreeningAssessmentQuestionVo;
import org.dromara.system.domain.bo.SysScreeningAssessmentQuestionBo;
import org.dromara.system.service.ISysScreeningAssessmentQuestionService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 题目
 *
 * @author Lion Li
 * @date 2025-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/screeningAssessmentQuestion")
public class SysScreeningAssessmentQuestionController extends BaseController {

    private final ISysScreeningAssessmentQuestionService sysScreeningAssessmentQuestionService;

    /**
     * 查询题目列表
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:list")
    @GetMapping("/list")
    public TableDataInfo<SysScreeningAssessmentQuestionVo> list(SysScreeningAssessmentQuestionBo bo, PageQuery pageQuery) {
        return sysScreeningAssessmentQuestionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出题目列表
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:export")
    @Log(title = "题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysScreeningAssessmentQuestionBo bo, HttpServletResponse response) {
        List<SysScreeningAssessmentQuestionVo> list = sysScreeningAssessmentQuestionService.queryList(bo);
        ExcelUtil.exportExcel(list, "题目", SysScreeningAssessmentQuestionVo.class, response);
    }

    /**
     * 获取题目详细信息
     *
     * @param questionId 主键
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:query")
    @GetMapping("/{questionId}")
    public R<SysScreeningAssessmentQuestionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long questionId) {
        return R.ok(sysScreeningAssessmentQuestionService.queryById(questionId));
    }

    /**
     * 新增题目
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:add")
    @Log(title = "题目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysScreeningAssessmentQuestionBo bo) {
        return toAjax(sysScreeningAssessmentQuestionService.insertByBo(bo));
    }

    /**
     * 修改题目
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:edit")
    @Log(title = "题目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysScreeningAssessmentQuestionBo bo) {
        return toAjax(sysScreeningAssessmentQuestionService.updateByBo(bo));
    }

    /**
     * 删除题目
     *
     * @param questionIds 主键串
     */
    @SaCheckPermission("system:screeningAssessmentQuestion:remove")
    @Log(title = "题目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{questionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] questionIds) {
        return toAjax(sysScreeningAssessmentQuestionService.deleteWithValidByIds(List.of(questionIds), true));
    }
}
