package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.oa.domain.bo.EmployeeOnboardingBo;
import com.ruoyi.oa.domain.vo.EmployeeOnboardingVo;
import com.ruoyi.oa.service.IEmployeeOnboardingService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入职管理
 *
 * @author hdka
 * @date 2025-02-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/onboarding")
public class EmployeeOnboardingController extends BaseController {

    private final IEmployeeOnboardingService iEmployeeOnboardingService;

    /**
     * 查询入职管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<EmployeeOnboardingVo> list(EmployeeOnboardingBo bo, PageQuery pageQuery) {
        return iEmployeeOnboardingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出入职管理列表
     */
    @Log(title = "入职管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmployeeOnboardingBo bo, HttpServletResponse response) {
        List<EmployeeOnboardingVo> list = iEmployeeOnboardingService.queryList(bo);
        ExcelUtil.exportExcel(list, "入职管理", EmployeeOnboardingVo.class, response);
    }

    /**
     * 获取入职管理详细信息
     *
     * @param userId 主键
     */
    @GetMapping("/{userId}")
    public R<EmployeeOnboardingVo> getInfo(@NotNull(message = "主键不能为空")
                                           @PathVariable Long userId) {
        return R.ok(iEmployeeOnboardingService.queryByUserId(userId));
    }

    /**
     * 新增入职管理
     */
    @Log(title = "入职管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmployeeOnboardingBo bo) {
        return toAjax(iEmployeeOnboardingService.insertByBo(bo));
    }

    /**
     * 修改入职管理
     */
    @Log(title = "入职管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@RequestBody EmployeeOnboardingBo bo) {
        return toAjax(iEmployeeOnboardingService.updateByBo(bo));
    }

    /**
     * 删除入职管理
     *
     * @param onboardingIds 主键串
     */
    @Log(title = "入职管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{onboardingIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] onboardingIds) {
        return toAjax(iEmployeeOnboardingService.deleteWithValidByIds(Arrays.asList(onboardingIds), true));
    }
}
