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.OaReportDetailVo;
import com.ruoyi.oa.domain.bo.OaReportDetailBo;
import com.ruoyi.oa.service.IOaReportDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设计项目汇报详情
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/reportDetail")
public class OaReportDetailController extends BaseController {

    private final IOaReportDetailService iOaReportDetailService;

    /**
     * 查询设计项目汇报详情列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaReportDetailVo> list(OaReportDetailBo bo, PageQuery pageQuery) {
        return iOaReportDetailService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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