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.OaOperationRuleVo;
import com.ruoyi.oa.domain.bo.OaOperationRuleBo;
import com.ruoyi.oa.service.IOaOperationRuleService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运营中心制度管理
 *
 * @author ruoyi
 * @date 2025-10-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/operationRule")
public class OaOperationRuleController extends BaseController {

    private final IOaOperationRuleService iOaOperationRuleService;

    /**
     * 查询运营中心制度管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaOperationRuleVo> list(OaOperationRuleBo bo, PageQuery pageQuery) {
        return iOaOperationRuleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出运营中心制度管理列表
     */
    @Log(title = "运营中心制度管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaOperationRuleBo bo, HttpServletResponse response) {
        List<OaOperationRuleVo> list = iOaOperationRuleService.queryList(bo);
        ExcelUtil.exportExcel(list, "运营中心制度管理", OaOperationRuleVo.class, response);
    }

    /**
     * 获取运营中心制度管理详细信息
     *
     * @param ruleId 主键
     */
    @GetMapping("/{ruleId}")
    public R<OaOperationRuleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ruleId) {
        return R.ok(iOaOperationRuleService.queryById(ruleId));
    }

    /**
     * 新增运营中心制度管理
     */
    @Log(title = "运营中心制度管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaOperationRuleBo bo) {
        return toAjax(iOaOperationRuleService.insertByBo(bo));
    }

    /**
     * 修改运营中心制度管理
     */
    @Log(title = "运营中心制度管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaOperationRuleBo bo) {
        return toAjax(iOaOperationRuleService.updateByBo(bo));
    }

    /**
     * 删除运营中心制度管理
     *
     * @param ruleIds 主键串
     */
    @Log(title = "运营中心制度管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ruleIds) {
        return toAjax(iOaOperationRuleService.deleteWithValidByIds(Arrays.asList(ruleIds), true));
    }
}
