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.OaBindingItemDetailVo;
import com.ruoyi.oa.domain.bo.OaBindingItemDetailBo;
import com.ruoyi.oa.service.IOaBindingItemDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 绑定记录明细
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/bindingItemDetail")
public class OaBindingItemDetailController extends BaseController {

    private final IOaBindingItemDetailService iOaBindingItemDetailService;

    /**
     * 查询绑定记录明细列表
     */

    @GetMapping("/list")
    public TableDataInfo<OaBindingItemDetailVo> list(OaBindingItemDetailBo bo, PageQuery pageQuery) {
        return iOaBindingItemDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出绑定记录明细列表
     */

    @Log(title = "绑定记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaBindingItemDetailBo bo, HttpServletResponse response) {
        List<OaBindingItemDetailVo> list = iOaBindingItemDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "绑定记录明细", OaBindingItemDetailVo.class, response);
    }

    /**
     * 获取绑定记录明细详细信息
     *
     * @param bindingItemId 主键
     */

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

    /**
     * 新增绑定记录明细
     */

    @Log(title = "绑定记录明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaBindingItemDetailBo bo) {
        return toAjax(iOaBindingItemDetailService.insertByBo(bo));
    }

    /**
     * 修改绑定记录明细
     */

    @Log(title = "绑定记录明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaBindingItemDetailBo bo) {
        return toAjax(iOaBindingItemDetailService.updateByBo(bo));
    }

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

}
