package com.ruoyi.oa.controller;

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

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.oa.domain.vo.OaEmployeeVo;
import com.ruoyi.oa.domain.bo.OaEmployeeBo;
import com.ruoyi.oa.service.IOaEmployeeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工基础信息
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/employee")
public class OaEmployeeController extends BaseController {

    private final IOaEmployeeService iOaEmployeeService;

    /**
     * 查询员工基础信息列表
     */

    @GetMapping("/list")
    public TableDataInfo<OaEmployeeVo> list(OaEmployeeBo bo, PageQuery pageQuery) {
        return iOaEmployeeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工基础信息列表
     */

    @Log(title = "员工基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaEmployeeBo bo, HttpServletResponse response) {
        List<OaEmployeeVo> list = iOaEmployeeService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工基础信息", OaEmployeeVo.class, response);
    }

    /**
     * 获取员工基础信息详细信息
     *
     * @param employeeId 主键
     */

    @GetMapping("/{employeeId}")
    public R<OaEmployeeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long employeeId) {
        return R.ok(iOaEmployeeService.queryById(employeeId));
    }

    /**
     * 新增员工基础信息
     */

    @Log(title = "员工基础信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaEmployeeBo bo) {
        return toAjax(iOaEmployeeService.insertByBo(bo));
    }

    /**
     * 修改员工基础信息
     */

    @Log(title = "员工基础信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaEmployeeBo bo) {
        return toAjax(iOaEmployeeService.updateByBo(bo));
    }

    /**
     * 删除员工基础信息
     *
     * @param employeeIds 主键串
     */

    @Log(title = "员工基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{employeeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] employeeIds) {
        return toAjax(iOaEmployeeService.deleteWithValidByIds(Arrays.asList(employeeIds), true));
    }
}
