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.OaSalaryTemplateDetailVo;
import com.ruoyi.oa.domain.bo.OaSalaryTemplateDetailBo;
import com.ruoyi.oa.service.IOaSalaryTemplateDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪资模板明细
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/salaryTemplateDetail")
public class OaSalaryTemplateDetailController extends BaseController {

    private final IOaSalaryTemplateDetailService iOaSalaryTemplateDetailService;

    /**
     * 查询薪资模板明细列表
     */

    @GetMapping("/list")
    public TableDataInfo<OaSalaryTemplateDetailVo> list(OaSalaryTemplateDetailBo bo, PageQuery pageQuery) {
        return iOaSalaryTemplateDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出薪资模板明细列表
     */

    @Log(title = "薪资模板明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSalaryTemplateDetailBo bo, HttpServletResponse response) {
        List<OaSalaryTemplateDetailVo> list = iOaSalaryTemplateDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "薪资模板明细", OaSalaryTemplateDetailVo.class, response);
    }

    /**
     * 获取薪资模板明细详细信息
     *
     * @param salaryDetailId 主键
     */

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

    /**
     * 新增薪资模板明细
     */

    @Log(title = "薪资模板明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaSalaryTemplateDetailBo bo) {
        return toAjax(iOaSalaryTemplateDetailService.insertByBo(bo));
    }

    /**
     * 修改薪资模板明细
     */

    @Log(title = "薪资模板明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaSalaryTemplateDetailBo bo) {
        return toAjax(iOaSalaryTemplateDetailService.updateByBo(bo));
    }

    /**
     * 删除薪资模板明细
     *
     * @param salaryDetailIds 主键串
     */

    @Log(title = "薪资模板明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{salaryDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] salaryDetailIds) {
        return toAjax(iOaSalaryTemplateDetailService.deleteWithValidByIds(Arrays.asList(salaryDetailIds), true));
    }
}
