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.OaBonusProjectRelVo;
import com.ruoyi.oa.domain.bo.OaBonusProjectRelBo;
import com.ruoyi.oa.service.IOaBonusProjectRelService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖金池与项目关联
 *
 * @author ruoyi
 * @date 2025-10-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/bonusProjectRel")
public class OaBonusProjectRelController extends BaseController {

    private final IOaBonusProjectRelService iOaBonusProjectRelService;

    /**
     * 查询奖金池与项目关联列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaBonusProjectRelVo> list(OaBonusProjectRelBo bo, PageQuery pageQuery) {
        return iOaBonusProjectRelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出奖金池与项目关联列表
     */
    @Log(title = "奖金池与项目关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaBonusProjectRelBo bo, HttpServletResponse response) {
        List<OaBonusProjectRelVo> list = iOaBonusProjectRelService.queryList(bo);
        ExcelUtil.exportExcel(list, "奖金池与项目关联", OaBonusProjectRelVo.class, response);
    }

    /**
     * 获取奖金池与项目关联详细信息
     *
     * @param relId 主键
     */
    @GetMapping("/{relId}")
    public R<OaBonusProjectRelVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long relId) {
        return R.ok(iOaBonusProjectRelService.queryById(relId));
    }

    /**
     * 新增奖金池与项目关联
     */
    @Log(title = "奖金池与项目关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaBonusProjectRelBo bo) {
        return toAjax(iOaBonusProjectRelService.insertByBo(bo));
    }

    /**
     * 修改奖金池与项目关联
     */
    @Log(title = "奖金池与项目关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaBonusProjectRelBo bo) {
        return toAjax(iOaBonusProjectRelService.updateByBo(bo));
    }

    /**
     * 删除奖金池与项目关联
     *
     * @param relIds 主键串
     */
    @Log(title = "奖金池与项目关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{relIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] relIds) {
        return toAjax(iOaBonusProjectRelService.deleteWithValidByIds(Arrays.asList(relIds), true));
    }


}
