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.OaReportSummaryVo;
import com.ruoyi.oa.domain.bo.OaReportSummaryBo;
import com.ruoyi.oa.service.IOaReportSummaryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设计项目汇报概述
 *
 * @author cpy
 * @date 2025-05-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/reportSummary")
public class OaReportSummaryController extends BaseController {

    private final IOaReportSummaryService iOaReportSummaryService;

    /**
     * 查询设计项目汇报概述列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaReportSummaryVo> list(OaReportSummaryBo bo, PageQuery pageQuery) {
        return iOaReportSummaryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出设计项目汇报概述列表
     */
    @Log(title = "设计项目汇报概述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaReportSummaryBo bo, HttpServletResponse response) {
        List<OaReportSummaryVo> list = iOaReportSummaryService.queryList(bo);
        ExcelUtil.exportExcel(list, "设计项目汇报概述", OaReportSummaryVo.class, response);
    }

    /**
     * 获取设计项目汇报概述详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<OaReportSummaryVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long id) {
        return R.ok(iOaReportSummaryService.queryById(id));
    }

    /**
     * 新增设计项目汇报概述
     */
    @Log(title = "设计项目汇报概述", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaReportSummaryBo bo) {
        return toAjax(iOaReportSummaryService.insertByBo(bo));
    }

    /**
     * 修改设计项目汇报概述
     */
    @Log(title = "设计项目汇报概述", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaReportSummaryBo bo) {
        return toAjax(iOaReportSummaryService.updateByBo(bo));
    }

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