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.OaSalaryVo;
import com.ruoyi.oa.domain.bo.OaSalaryBo;
import com.ruoyi.oa.service.IOaSalaryService;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 薪资管理
 *
 * @author hdka
 * @date 2025-03-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/salary")
public class OaSalaryController extends BaseController {

    private final IOaSalaryService iOaSalaryService;

    /**
     * 查询薪资管理列表
     */
    @GetMapping("/list-staff")
    public TableDataInfo<OaSalaryVo> list(OaSalaryBo bo, PageQuery pageQuery) {
        return iOaSalaryService.queryPageList(bo, pageQuery);
    }
    /**
     * 查询薪资管理列表
     */
    @GetMapping("/list-worker")
    public TableDataInfo<OaSalaryVo> listWorker(OaSalaryBo bo, PageQuery pageQuery) {
        return iOaSalaryService.listWorker(bo, pageQuery);
    }

    /**
     * 导出薪资管理列表
     */
    @Log(title = "薪资管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSalaryBo bo, HttpServletResponse response) {
        List<OaSalaryVo> list = iOaSalaryService.queryList(bo);
        ExcelUtil.exportExcel(list, "薪资管理", OaSalaryVo.class, response);
    }

    /**
     * 获取薪资管理详细信息
     *
     */
    @GetMapping("/detail")
    public R<OaSalaryVo> getInfo(@RequestBody OaSalaryBo bo) {
        return R.ok(iOaSalaryService.queryById(bo.getSalaryId(),bo.getPayTime()));
    }

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

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

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


    @PostMapping("/calc")
    public R<Void> calc(@RequestBody OaSalaryBo bo) {
        return R.ok(iOaSalaryService.calcSalary(bo));
    }


}
