package org.dromara.controller.staffTrain;

import cn.dev33.satoken.annotation.SaCheckPermission;
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.dromara.domain.staffTrain.StaffTrainManual;
import org.dromara.domain.staffTrain.bo.StaffTrainManualBo;
import org.dromara.domain.staffTrain.vo.StaffTrainManualVo;
import org.dromara.service.IStaffTrainManualService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 员工培训手册
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/manual")
public class StaffTrainManualController extends BaseController {

    private final IStaffTrainManualService staffTrainManualService;

    /**
     * 查询员工培训手册列表
     */
    @SaCheckPermission("wuYe:manual:list")
    @GetMapping("/list")
    public TableDataInfo<StaffTrainManualVo> list(StaffTrainManualBo bo, PageQuery pageQuery) {
        return staffTrainManualService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工培训手册列表
     */
    @SaCheckPermission("wuYe:manual:export")
    @Log(title = "员工培训手册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StaffTrainManualBo bo, HttpServletResponse response) {
        List<StaffTrainManualVo> list = staffTrainManualService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工培训手册", StaffTrainManualVo.class, response);
    }

    /**
     * 获取员工培训手册详细信息
     *
     * @param manualId 主键
     */
    @SaCheckPermission("wuYe:manual:query")
    @GetMapping("/{manualId}")
    public R<StaffTrainManualVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long manualId) {
        return R.ok(staffTrainManualService.queryById(manualId));
    }

    /**
     * 获取已读人员名单
     */
    @SaCheckPermission("wuYe:manual:getRead")
    @PostMapping(value = "/getRead")
    public R<List<Map<String, String>>> getRead(@RequestBody StaffTrainManual staffTrainManual) {
        return R.ok(staffTrainManualService.getRead(staffTrainManual));
    }

    /**
     * 新增员工培训手册
     */
    @SaCheckPermission("wuYe:manual:add")
    @Log(title = "员工培训手册", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StaffTrainManualBo bo) {
        return toAjax(staffTrainManualService.insertByBo(bo));
    }

    /**
     * 修改员工培训手册
     */
    @SaCheckPermission("wuYe:manual:edit")
    @Log(title = "员工培训手册", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StaffTrainManualBo bo) {
        return toAjax(staffTrainManualService.updateByBo(bo));
    }

    /**
     * 删除员工培训手册
     *
     * @param manualIds 主键串
     */
    @SaCheckPermission("wuYe:manual:remove")
    @Log(title = "员工培训手册", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{manualIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] manualIds) {
        return toAjax(staffTrainManualService.deleteWithValidByIds(List.of(manualIds), true));
    }
}
