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

import com.hotwj.platform.securityManagement.trainingParticipant.domain.bo.HotTrainingParticipantBo;
import com.hotwj.platform.securityManagement.trainingParticipant.domain.vo.DriverLearningRecordVo;
import com.hotwj.platform.securityManagement.trainingParticipant.domain.vo.HotTrainingParticipantVo;
import com.hotwj.platform.securityManagement.trainingParticipant.service.IHotTrainingParticipantPrintService;
import com.hotwj.platform.securityManagement.trainingParticipant.service.IHotTrainingParticipantService;
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-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/trainingParticipant")
@Tag(name = "培训参与人员", description = "培训参与人员管理")
public class HotTrainingParticipantController extends BaseController {

    private final IHotTrainingParticipantService hotTrainingParticipantService;
    private final IHotTrainingParticipantPrintService printService;

    /**
     * 查询培训参与人员列表
     */
    //@SaCheckPermission("securityManagement:trainingParticipant:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询培训参与人员列表")
    public TableDataInfo<HotTrainingParticipantVo> list(HotTrainingParticipantBo bo, PageQuery pageQuery) {
        return hotTrainingParticipantService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/listWithPlan")
    //@SaCheckPermission("securityManagement:trainingParticipant:list")
    @Operation(summary = "驾驶员学习记录列表（参与培训计划+计划信息）")
    public TableDataInfo<DriverLearningRecordVo> listWithPlan(
            @RequestParam Long companyId,
            @RequestParam String userId,
            PageQuery pageQuery
    ) {
        return hotTrainingParticipantService.queryDriverLearningRecordPage(companyId, userId, pageQuery);
    }

    /**
     * 导出培训参与人员列表
     */
    //@SaCheckPermission("securityManagement:trainingParticipant:export")
    @Log(title = "培训参与人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出培训参与人员列表")
    public void export(HotTrainingParticipantBo bo, HttpServletResponse response) {
        List<HotTrainingParticipantVo> list = hotTrainingParticipantService.queryList(bo);
        ExcelUtil.exportExcel(list, "培训参与人员", HotTrainingParticipantVo.class, response);
    }

    /**
     * 导出培训参与人员列表PDF
     */
    //@SaCheckPermission("securityManagement:trainingParticipant:query")
    @Log(title = "培训参与人员打印", businessType = BusinessType.EXPORT)
    @PostMapping("/exportPdf")
    @Operation(summary = "导出培训参与人员列表PDF")
    public void exportPdf(HotTrainingParticipantBo bo, HttpServletResponse response) {
        printService.exportPdf(bo, response);
    }

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

    /**
     * 新增培训参与人员
     */
    //@SaCheckPermission("securityManagement:trainingParticipant:add")
    @Log(title = "培训参与人员", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增培训参与人员")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotTrainingParticipantBo bo) {
        return toAjax(hotTrainingParticipantService.insertByBo(bo));
    }

    /**
     * 修改培训参与人员
     */
    //@SaCheckPermission("securityManagement:trainingParticipant:edit")
    @Log(title = "培训参与人员", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改培训参与人员")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotTrainingParticipantBo bo) {
        return toAjax(hotTrainingParticipantService.updateByBo(bo));
    }

    /**
     * 删除培训参与人员
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:trainingParticipant: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(hotTrainingParticipantService.deleteWithValidByIds(List.of(ids), true));
    }
}
