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

import com.hotwj.platform.securityManagement.trainingCourseRecord.domain.bo.HotTrainingCourseRecordBo;
import com.hotwj.platform.securityManagement.trainingCourseRecord.domain.vo.HotTrainingCourseRecordVo;
import com.hotwj.platform.securityManagement.trainingCourseRecord.service.IHotTrainingCourseRecordService;
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 2026-02-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/trainingCourseRecord")
@Tag(name = "培训人员课程学习记录", description = "培训人员课程学习记录管理")
public class HotTrainingCourseRecordController extends BaseController {

    private final IHotTrainingCourseRecordService hotTrainingCourseRecordService;

    /**
     * 查询培训人员课程学习记录列表
     */
    //@SaCheckPermission("securityManagement:trainingCourseRecord:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询培训人员课程学习记录列表")
    public TableDataInfo<HotTrainingCourseRecordVo> list(HotTrainingCourseRecordBo bo, PageQuery pageQuery) {
        return hotTrainingCourseRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出培训人员课程学习记录列表
     */
    //@SaCheckPermission("securityManagement:trainingCourseRecord:export")
    @Log(title = "培训人员课程学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出培训人员课程学习记录列表")
    public void export(HotTrainingCourseRecordBo bo, HttpServletResponse response) {
        List<HotTrainingCourseRecordVo> list = hotTrainingCourseRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "培训人员课程学习记录", HotTrainingCourseRecordVo.class, response);
    }

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

    /**
     * 新增培训人员课程学习记录
     */
    //@SaCheckPermission("securityManagement:trainingCourseRecord:add")
    @Log(title = "培训人员课程学习记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增培训人员课程学习记录")
    public R<Long> add(@Validated(AddGroup.class) @RequestBody HotTrainingCourseRecordBo bo) {
        Long id = hotTrainingCourseRecordService.insertByBo(bo);
        return R.ok(id);
    }

    /**
     * 修改培训人员课程学习记录
     */
    //@SaCheckPermission("securityManagement:trainingCourseRecord:edit")
    @Log(title = "培训人员课程学习记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改培训人员课程学习记录")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotTrainingCourseRecordBo bo) {
        return toAjax(hotTrainingCourseRecordService.updateByBo(bo));
    }

    /**
     * 显式扣减学习记录对应的学时套餐
     *
     * @param id 学习记录ID
     */
    @Log(title = "培训人员课程学习记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/{id}/deductHourPackage")
    @Operation(summary = "显式扣减学习记录对应的学时套餐")
    public R<Void> deductHourPackage(@NotNull(message = "主键不能为空")
                                     @Parameter(name = "id", description = "学习记录ID", required = true, example = "1")
                                     @PathVariable Long id) {
        return toAjax(hotTrainingCourseRecordService.deductHourPackage(id));
    }

    /**
     * 删除培训人员课程学习记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:trainingCourseRecord: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(hotTrainingCourseRecordService.deleteWithValidByIds(List.of(ids), true));
    }
}
