package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

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

/**
 * 奖金池
 *
 * @author ruoyi
 * @date 2025-10-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/bonusPool")
public class OaBonusPoolController extends BaseController {

    private final IOaBonusPoolService iOaBonusPoolService;

    /**
     * 查询奖金池列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaBonusPoolVo> list(OaBonusPoolBo bo, PageQuery pageQuery) {
        return iOaBonusPoolService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出奖金池列表
     */
    @Log(title = "奖金池", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaBonusPoolBo bo, HttpServletResponse response) {
        List<OaBonusPoolVo> list = iOaBonusPoolService.queryList(bo);
        ExcelUtil.exportExcel(list, "奖金池", OaBonusPoolVo.class, response);
    }

    /**
     * 获取奖金池详细信息
     *
     * @param poolId 主键
     */
    @GetMapping("/{poolId}")
    public R<OaBonusPoolVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long poolId) {
        return R.ok(iOaBonusPoolService.queryById(poolId));
    }

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

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

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

    //使用这个方法批量绑定奖金池id和项目id
    @Log(title = "奖金池与项目关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/batchAdd")
    public R<Void> batchAdd(@Validated(AddGroup.class) @RequestBody OaBonusPoolBo bo) {
        return toAjax(iOaBonusPoolService.batchAdd(bo));
    }


}
