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.OaSalaryTemplateVo;
import com.ruoyi.oa.domain.bo.OaSalaryTemplateBo;
import com.ruoyi.oa.service.IOaSalaryTemplateService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪资模板主
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/salaryTemplate")
public class OaSalaryTemplateController extends BaseController {

    private final IOaSalaryTemplateService iOaSalaryTemplateService;

    /**
     * 查询薪资模板主列表
     */

    @GetMapping("/list")
    public TableDataInfo<OaSalaryTemplateVo> list(OaSalaryTemplateBo bo, PageQuery pageQuery) {
        return iOaSalaryTemplateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出薪资模板主列表
     */

    @Log(title = "薪资模板主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSalaryTemplateBo bo, HttpServletResponse response) {
        List<OaSalaryTemplateVo> list = iOaSalaryTemplateService.queryList(bo);
        ExcelUtil.exportExcel(list, "薪资模板主", OaSalaryTemplateVo.class, response);
    }

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

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

    /**
     * 新增薪资模板主
     */

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

    /**
     * 修改薪资模板主
     */

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

    /**
     * 删除薪资模板主
     *
     * @param salaryTemplateIds 主键串
     */

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