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.EmployeeOffboardingVo;
import com.ruoyi.oa.domain.bo.EmployeeOffboardingBo;
import com.ruoyi.oa.service.IEmployeeOffboardingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 离职管理
 *
 * @author hdka
 * @date 2025-02-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/offboarding")
public class EmployeeOffboardingController extends BaseController {

    private final IEmployeeOffboardingService iEmployeeOffboardingService;

    /**
     * 查询离职管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<EmployeeOffboardingVo> list(EmployeeOffboardingBo bo, PageQuery pageQuery) {
        return iEmployeeOffboardingService.queryPageList(bo, pageQuery);
    }

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

    /**
     * 获取离职管理详细信息
     *
     * @param offboardingId 主键
     */
    @GetMapping("/{offboardingId}")
    public R<EmployeeOffboardingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long offboardingId) {
        return R.ok(iEmployeeOffboardingService.queryById(offboardingId));
    }

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

    /**
     * 修改离职管理
     */
    @Log(title = "离职管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmployeeOffboardingBo bo) {
        return toAjax(iEmployeeOffboardingService.updateByBo(bo));
    }

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