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 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.OaSalaryDetailVo;
import com.ruoyi.oa.domain.bo.OaSalaryDetailBo;
import com.ruoyi.oa.service.IOaSalaryDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工资发放明细
 *
 * @author Joshi
 * @date 2025-09-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/salaryDetail")
public class OaSalaryDetailController extends BaseController {

    private final IOaSalaryDetailService iOaSalaryDetailService;

    /**
     * 查询工资发放明细列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaSalaryDetailVo> list(OaSalaryDetailBo bo, PageQuery pageQuery) {
        return iOaSalaryDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工资发放明细列表
     */
    @Log(title = "工资发放明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSalaryDetailBo bo, HttpServletResponse response) {
        List<OaSalaryDetailVo> list = iOaSalaryDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "工资发放明细", OaSalaryDetailVo.class, response);
    }

    /**
     * 获取工资发放明细详细信息
     *
     * @param detailId 主键
     */
    @GetMapping("/{detailId}")
    public R<OaSalaryDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long detailId) {
        return R.ok(iOaSalaryDetailService.queryById(detailId));
    }

    /**
     * 新增工资发放明细
     */
    @Log(title = "工资发放明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaSalaryDetailBo bo) {
        return toAjax(iOaSalaryDetailService.insertByBo(bo));
    }

    /**
     * 修改工资发放明细
     */
    @Log(title = "工资发放明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaSalaryDetailBo bo) {
        return toAjax(iOaSalaryDetailService.updateByBo(bo));
    }

    /**
     * 删除工资发放明细
     *
     * @param detailIds 主键串
     */
    @Log(title = "工资发放明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] detailIds) {
        return toAjax(iOaSalaryDetailService.deleteWithValidByIds(Arrays.asList(detailIds), true));
    }
}
