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.OaProjectScheduleVo;
import com.ruoyi.oa.domain.bo.OaProjectScheduleBo;
import com.ruoyi.oa.service.IOaProjectScheduleService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目进度
 *
 * @author haka
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/projectSchedule")
public class OaProjectScheduleController extends BaseController {

    private final IOaProjectScheduleService iOaProjectScheduleService;

    /**
     * 查询项目进度列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaProjectScheduleVo> list(OaProjectScheduleBo bo, PageQuery pageQuery) {
        return iOaProjectScheduleService.queryPageList(bo, pageQuery);
    }

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

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

    /**
     * 新增项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProjectScheduleBo bo) {
        return toAjax(iOaProjectScheduleService.insertByBo(bo));
    }

    /**
     * 修改项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProjectScheduleBo bo) {
        return toAjax(iOaProjectScheduleService.updateByBo(bo));
    }

    /**
     * 修改项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/complete")
    public R<Void> complete(@RequestBody OaProjectScheduleBo bo) {
        return toAjax(iOaProjectScheduleService.complete(bo));
    }

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