package com.ruoyi.oa.controller;

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

import com.ruoyi.oa.domain.bo.OaSalaryBo;
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.OaSalaryItemVo;
import com.ruoyi.oa.domain.bo.OaSalaryItemBo;
import com.ruoyi.oa.service.IOaSalaryItemService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪水详情
 *
 * @author hdka
 * @date 2025-03-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/salaryItem")
public class OaSalaryItemController extends BaseController {

    private final IOaSalaryItemService iOaSalaryItemService;

    /**
     * 查询薪水详情列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaSalaryItemVo> list(OaSalaryItemBo bo, PageQuery pageQuery) {
        return iOaSalaryItemService.queryPageList(bo, pageQuery);
    }


    @GetMapping("/check-file")
    public R<Boolean> checkFile(OaSalaryItemBo bo, PageQuery pageQuery) {
        return R.ok(iOaSalaryItemService.checkFile(bo));
    }

    /**
     * 导出薪水详情列表
     */
    @Log(title = "薪水详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSalaryItemBo bo, HttpServletResponse response) {
        List<OaSalaryItemVo> list = iOaSalaryItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "薪水详情", OaSalaryItemVo.class, response);
    }

    /**
     * 获取薪水详情详细信息
     *
     * @param salaryItemId 主键
     */
    @GetMapping("/{salaryItemId}")
    public R<OaSalaryItemVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long salaryItemId) {
        return R.ok(iOaSalaryItemService.queryById(salaryItemId));
    }

    /**
     * 新增薪水详情
     */
    @Log(title = "薪水详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaSalaryItemBo bo) {
        return toAjax(iOaSalaryItemService.insertByBo(bo));
    }

    /**
     * 修改薪水详情
     */

    @Log(title = "薪水详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaSalaryItemBo bo) {
        return toAjax(iOaSalaryItemService.updateByBo(bo));
    }

    /**
     * 删除薪水详情
     *
     * @param salaryItemIds 主键串
     */
    @Log(title = "薪水详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{salaryItemIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] salaryItemIds) {
        return toAjax(iOaSalaryItemService.deleteWithValidByIds(Arrays.asList(salaryItemIds), true));
    }


}
