package org.dromara.controller.staffTrainTime;

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.staffTrainTime.bo.StaffTrainTimeBo;
import org.dromara.domain.staffTrainTime.vo.StaffTrainTimeVo;
import org.dromara.service.IStaffTrainTimeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工培训时长
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/staffTrainTime")
public class StaffTrainTimeController extends BaseController {

    private final IStaffTrainTimeService staffTrainTimeService;

    /**
     * 查询员工培训时长列表
     */
    @SaCheckPermission("wuYe:staffTrainTime:list")
    @GetMapping("/list")
    public TableDataInfo<StaffTrainTimeVo> list(StaffTrainTimeBo bo, PageQuery pageQuery) {
        return staffTrainTimeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工培训时长列表
     */
    @SaCheckPermission("wuYe:staffTrainTime:export")
    @Log(title = "员工培训时长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StaffTrainTimeBo bo, HttpServletResponse response) {
        List<StaffTrainTimeVo> list = staffTrainTimeService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工培训时长", StaffTrainTimeVo.class, response);
    }

    /**
     * 获取员工培训时长详细信息
     *
     * @param trainTimeId 主键
     */
    @SaCheckPermission("wuYe:staffTrainTime:query")
    @GetMapping("/{trainTimeId}")
    public R<StaffTrainTimeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long trainTimeId) {
        return R.ok(staffTrainTimeService.queryById(trainTimeId));
    }

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

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

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