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.OaReportScheduleVo;
import com.ruoyi.oa.domain.bo.OaReportScheduleBo;
import com.ruoyi.oa.service.IOaReportScheduleService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目排产
 *
 * @author ruoyi
 * @date 2025-07-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/reportSchedule")
public class OaReportScheduleController extends BaseController {

    private final IOaReportScheduleService iOaReportScheduleService;

    /**
     * 查询项目排产列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaReportScheduleVo> list(OaReportScheduleBo bo, PageQuery pageQuery) {
        return iOaReportScheduleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目排产列表
     */
    @Log(title = "项目排产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaReportScheduleBo bo, HttpServletResponse response) {
        List<OaReportScheduleVo> list = iOaReportScheduleService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目排产", OaReportScheduleVo.class, response);
    }

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

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

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

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