package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.oa.domain.bo.BatchBo;
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.OaProjectScheduleStepVo;
import com.ruoyi.oa.domain.bo.OaProjectScheduleStepBo;
import com.ruoyi.oa.service.IOaProjectScheduleStepService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目进度步骤跟踪
 *
 * @author hdka
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/projectScheduleStep")
public class OaProjectScheduleStepController extends BaseController {

    private final IOaProjectScheduleStepService iOaProjectScheduleStepService;

    /**
     * 查询项目进度步骤跟踪列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaProjectScheduleStepVo> list(OaProjectScheduleStepBo bo, PageQuery pageQuery) {
        return iOaProjectScheduleStepService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目进度步骤跟踪列表
     */
    @Log(title = "项目进度步骤跟踪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaProjectScheduleStepBo bo, HttpServletResponse response) {
        List<OaProjectScheduleStepVo> list = iOaProjectScheduleStepService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目进度步骤跟踪", OaProjectScheduleStepVo.class, response);
    }

    /**
     * 获取项目进度步骤跟踪详细信息
     *
     * @param trackId 主键
     */
    @GetMapping("/{trackId}")
    public R<OaProjectScheduleStepVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long trackId) {
        return R.ok(iOaProjectScheduleStepService.queryById(trackId));
    }

    /**
     * 新增项目进度步骤跟踪
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProjectScheduleStepBo bo) {
        return toAjax(iOaProjectScheduleStepService.insertByBo(bo));
    }

    /**
     * 修改项目进度步骤跟踪
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProjectScheduleStepBo bo) {
        return toAjax(iOaProjectScheduleStepService.updateByBo(bo));
    }


    /**
     * 修改项目进度步骤跟踪
     */
    @RepeatSubmit()
    @PutMapping("/change-batch")
    public R<Void> changeBatch(@Validated(EditGroup.class) @RequestBody BatchBo batchBo) {
        return toAjax(iOaProjectScheduleStepService.changeBatch(batchBo));
    }

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