package com.hotwj.platform.securityManagement.trainingAudit.controller;

import com.hotwj.platform.securityManagement.trainingAudit.domain.bo.HotTrainingAuditBatchBo;
import com.hotwj.platform.securityManagement.trainingAudit.domain.bo.HotTrainingAuditBo;
import com.hotwj.platform.securityManagement.trainingAudit.domain.vo.HotTrainingAuditVo;
import com.hotwj.platform.securityManagement.trainingAudit.service.IHotTrainingAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 培训审核
 *
 * @author shihongwei
 * @date 2025-12-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/trainingAudit")
@Tag(name = "培训审核", description = "培训审核管理")
public class HotTrainingAuditController extends BaseController {

    private final IHotTrainingAuditService hotTrainingAuditService;

    /**
     * 查询培训审核列表
     */
    //@SaCheckPermission("securityManagement:trainingAudit:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询培训审核列表")
    public TableDataInfo<HotTrainingAuditVo> list(HotTrainingAuditBo bo, PageQuery pageQuery) {
        return hotTrainingAuditService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出培训审核列表
     */
    //@SaCheckPermission("securityManagement:trainingAudit:export")
    @Log(title = "培训审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出培训审核列表")
    public void export(HotTrainingAuditBo bo, HttpServletResponse response) {
        List<HotTrainingAuditVo> list = hotTrainingAuditService.queryList(bo);
        ExcelUtil.exportExcel(list, "培训审核", HotTrainingAuditVo.class, response);
    }

    /**
     * 获取培训审核详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("securityManagement:trainingAudit:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取培训审核详细信息")
    public R<HotTrainingAuditVo> getInfo(@NotNull(message = "主键不能为空")
                                         @Parameter(name = "id", description = "主键", required = true, example = "1")
                                         @PathVariable Long id) {
        return R.ok(hotTrainingAuditService.queryById(id));
    }

    /**
     * 新增培训审核
     */
    //@SaCheckPermission("securityManagement:trainingAudit:add")
    @Log(title = "培训审核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增培训审核")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotTrainingAuditBo bo) {
        return toAjax(hotTrainingAuditService.insertByBo(bo));
    }

    /**
     * 修改培训审核
     */
    //@SaCheckPermission("securityManagement:trainingAudit:edit")
    @Log(title = "培训审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改培训审核")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotTrainingAuditBo bo) {
        return toAjax(hotTrainingAuditService.updateByBo(bo));
    }

    /**
     * 批量审核培训参与人员
     */
    @Log(title = "培训审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/batchAudit")
    @Operation(summary = "批量审核培训参与人员")
    public R<Void> batchAudit(@Validated @RequestBody HotTrainingAuditBatchBo bo) {
        return toAjax(hotTrainingAuditService.batchAudit(bo));
    }

    /**
     * 删除培训审核
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:trainingAudit:remove")
    @Log(title = "培训审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除培训审核")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotTrainingAuditService.deleteWithValidByIds(List.of(ids), true));
    }
}
