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.OaScheduleTemplateVo;
import com.ruoyi.oa.domain.bo.OaScheduleTemplateBo;
import com.ruoyi.oa.service.IOaScheduleTemplateService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进度模板主
 *
 * @author hdka
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/scheduleTemplate")
public class OaScheduleTemplateController extends BaseController {

    private final IOaScheduleTemplateService iOaScheduleTemplateService;

    /**
     * 查询进度模板主列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaScheduleTemplateVo> list(OaScheduleTemplateBo bo, PageQuery pageQuery) {
        return iOaScheduleTemplateService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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