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.OaRequirementsVo;
import com.ruoyi.oa.domain.bo.OaRequirementsBo;
import com.ruoyi.oa.service.IOaRequirementsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * OA 需求
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/requirements")
public class OaRequirementsController extends BaseController {

    private final IOaRequirementsService iOaRequirementsService;

    /**
     * 查询OA 需求列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaRequirementsVo> list(OaRequirementsBo bo, PageQuery pageQuery) {
        return iOaRequirementsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出OA 需求列表
     */
    @Log(title = "OA 需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaRequirementsBo bo, HttpServletResponse response) {
        List<OaRequirementsVo> list = iOaRequirementsService.queryList(bo);
        ExcelUtil.exportExcel(list, "OA 需求", OaRequirementsVo.class, response);
    }

    /**
     * 获取OA 需求详细信息
     *
     * @param requirementId 主键
     */
    @GetMapping("/{requirementId}")
    public R<OaRequirementsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long requirementId) {
        return R.ok(iOaRequirementsService.queryById(requirementId));
    }

    /**
     * 新增OA 需求
     */
    @Log(title = "OA 需求", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaRequirementsBo bo) {
        return toAjax(iOaRequirementsService.insertByBo(bo));
    }

    /**
     * 修改OA 需求
     */
    @Log(title = "OA 需求", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaRequirementsBo bo) {
        return toAjax(iOaRequirementsService.updateByBo(bo));
    }

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