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.OaScheduleTemplateStepVo;
import com.ruoyi.oa.domain.bo.OaScheduleTemplateStepBo;
import com.ruoyi.oa.service.IOaScheduleTemplateStepService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进度模板步骤
 *
 * @author hdka
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/scheduleTemplateStep")
public class OaScheduleTemplateStepController extends BaseController {

    private final IOaScheduleTemplateStepService iOaScheduleTemplateStepService;

    /**
     * 查询进度模板步骤列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaScheduleTemplateStepVo> list(OaScheduleTemplateStepBo bo, PageQuery pageQuery) {
        return iOaScheduleTemplateStepService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出进度模板步骤列表
     */
    @Log(title = "进度模板步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaScheduleTemplateStepBo bo, HttpServletResponse response) {
        List<OaScheduleTemplateStepVo> list = iOaScheduleTemplateStepService.queryList(bo);
        ExcelUtil.exportExcel(list, "进度模板步骤", OaScheduleTemplateStepVo.class, response);
    }

    /**
     * 获取进度模板步骤详细信息
     *
     * @param stepId 主键
     */
    @GetMapping("/{stepId}")
    public R<OaScheduleTemplateStepVo> getInfo(@NotNull(message = "主键不能为空")
                                               @PathVariable Long stepId) {
        return R.ok(iOaScheduleTemplateStepService.queryById(stepId));
    }

    /**
     * 新增进度模板步骤
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaScheduleTemplateStepBo bo) {
        return toAjax(iOaScheduleTemplateStepService.insertByBo(bo));
    }

    /**
     * 修改进度模板步骤
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaScheduleTemplateStepBo bo) {
        return toAjax(iOaScheduleTemplateStepService.updateByBo(bo));
    }

    /**
     * 删除进度模板步骤
     *
     * @param stepIds 主键串
     */
    @DeleteMapping("/{stepIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] stepIds) {
        return toAjax(iOaScheduleTemplateStepService.deleteWithValidByIds(Arrays.asList(stepIds), true));
    }
}
