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.OaProjectReportVo;
import com.ruoyi.oa.domain.bo.OaProjectReportBo;
import com.ruoyi.oa.service.IOaProjectReportService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目报工
 *
 * @author hdka
 * @date 2025-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/projectReport")
public class OaProjectReportController extends BaseController {

    private final IOaProjectReportService iOaProjectReportService;

    /**
     * 查询项目报工列表
     */
    @SaCheckPermission("oa:projectReport:list")
    @GetMapping("/list")
    public TableDataInfo<OaProjectReportVo> list(OaProjectReportBo bo, PageQuery pageQuery) {
        return iOaProjectReportService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目报工列表
     */
    @SaCheckPermission("oa:projectReport:export")
    @Log(title = "项目报工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaProjectReportBo bo, HttpServletResponse response) {
        List<OaProjectReportVo> list = iOaProjectReportService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目报工", OaProjectReportVo.class, response);
    }

    /**
     * 获取项目报工详细信息
     *
     * @param reportId 主键
     */
    @SaCheckPermission("oa:projectReport:query")
    @GetMapping("/{reportId}")
    public R<OaProjectReportVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long reportId) {
        return R.ok(iOaProjectReportService.queryById(reportId));
    }

    /**
     * 新增项目报工
     */
    @SaCheckPermission("oa:projectReport:add")
    @Log(title = "项目报工", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProjectReportBo bo) {
        return toAjax(iOaProjectReportService.insertByBo(bo));
    }

    /**
     * 修改项目报工
     */
    @SaCheckPermission("oa:projectReport:edit")
    @Log(title = "项目报工", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProjectReportBo bo) {
        return toAjax(iOaProjectReportService.updateByBo(bo));
    }

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