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.OaBonusAllocationVo;
import com.ruoyi.oa.domain.bo.OaBonusAllocationBo;
import com.ruoyi.oa.service.IOaBonusAllocationService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖金池分配（记录奖金池向用户的分配比例及金额）
 *
 * @author ruoyi
 * @date 2025-10-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/bonusAllocation")
public class OaBonusAllocationController extends BaseController {

    private final IOaBonusAllocationService iOaBonusAllocationService;

    /**
     * 查询奖金池分配（记录奖金池向用户的分配比例及金额）列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaBonusAllocationVo> list(OaBonusAllocationBo bo, PageQuery pageQuery) {
        return iOaBonusAllocationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出奖金池分配（记录奖金池向用户的分配比例及金额）列表
     */
    @Log(title = "奖金池分配（记录奖金池向用户的分配比例及金额）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaBonusAllocationBo bo, HttpServletResponse response) {
        List<OaBonusAllocationVo> list = iOaBonusAllocationService.queryList(bo);
        ExcelUtil.exportExcel(list, "奖金池分配（记录奖金池向用户的分配比例及金额）", OaBonusAllocationVo.class, response);
    }

    /**
     * 获取奖金池分配（记录奖金池向用户的分配比例及金额）详细信息
     *
     * @param allocationId 主键
     */
    @GetMapping("/{allocationId}")
    public R<OaBonusAllocationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long allocationId) {
        return R.ok(iOaBonusAllocationService.queryById(allocationId));
    }

    /**
     * 新增奖金池分配（记录奖金池向用户的分配比例及金额）
     */
    @Log(title = "奖金池分配（记录奖金池向用户的分配比例及金额）", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaBonusAllocationBo bo) {
        return toAjax(iOaBonusAllocationService.insertByBo(bo));
    }

    /**
     * 修改奖金池分配（记录奖金池向用户的分配比例及金额）
     */
    @Log(title = "奖金池分配（记录奖金池向用户的分配比例及金额）", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaBonusAllocationBo bo) {
        return toAjax(iOaBonusAllocationService.updateByBo(bo));
    }

    /**
     * 删除奖金池分配（记录奖金池向用户的分配比例及金额）
     *
     * @param allocationIds 主键串
     */
    @Log(title = "奖金池分配（记录奖金池向用户的分配比例及金额）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{allocationIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] allocationIds) {
        return toAjax(iOaBonusAllocationService.deleteWithValidByIds(Arrays.asList(allocationIds), true));
    }

    //新增一个接口用来传入nickname和allocation_id
}
