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.OaProgressDetailVo;
import com.ruoyi.oa.domain.bo.OaProgressDetailBo;
import com.ruoyi.oa.service.IOaProgressDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进度扩展
 *
 * @author hdka2
 * @date 2025-04-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/progressDetail")
public class OaProgressDetailController extends BaseController {

    private final IOaProgressDetailService iOaProgressDetailService;

    /**
     * 查询进度扩展列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaProgressDetailVo> list(OaProgressDetailBo bo, PageQuery pageQuery) {
        return iOaProgressDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出进度扩展列表
     */
    @Log(title = "进度扩展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaProgressDetailBo bo, HttpServletResponse response) {
        List<OaProgressDetailVo> list = iOaProgressDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "进度扩展", OaProgressDetailVo.class, response);
    }

    /**
     * 获取进度扩展详细信息
     *
     * @param detailId 主键
     */
    @GetMapping("/{detailId}")
    public R<OaProgressDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable Long detailId) {
        return R.ok(iOaProgressDetailService.queryById(detailId));
    }

    /**
     * 新增进度扩展
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProgressDetailBo bo) {
        return toAjax(iOaProgressDetailService.insertByBo(bo));
    }

    /**
     * 修改进度扩展
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProgressDetailBo bo) {
        return toAjax(iOaProgressDetailService.updateByBo(bo));
    }

    /**
     * 删除进度扩展
     *
     * @param detailIds 主键串
     */
    @DeleteMapping("/{detailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] detailIds) {
        return toAjax(iOaProgressDetailService.deleteWithValidByIds(Arrays.asList(detailIds), true));
    }
}
