package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.oa.domain.OaProgressDetail;
import com.ruoyi.oa.domain.bo.OaProgressDetailBo;
import com.ruoyi.oa.domain.bo.SysOaProjectBo;
import com.ruoyi.oa.domain.vo.OaProgressDetailVo;
import com.ruoyi.oa.domain.vo.SysOaProjectVo;
import com.ruoyi.oa.service.IOaProgressDetailService;
import com.ruoyi.oa.service.ISysOaProjectService;
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.OaProgressVo;
import com.ruoyi.oa.domain.bo.OaProgressBo;
import com.ruoyi.oa.service.IOaProgressService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进度管理
 *
 * @author hdka
 * @date 2025-04-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/progress")
public class OaProgressController extends BaseController {

    private final IOaProgressService iOaProgressService;

    private final ISysOaProjectService projectService;

    private final IOaProgressDetailService detailService;
    /**
     * 查询进度管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaProgressVo> list(OaProgressBo bo, PageQuery pageQuery) {
        return iOaProgressService.queryPageList(bo, pageQuery);
    }


    /**
     * 查询进度管理列表
     */
    @GetMapping("/one-list")
    public TableDataInfo<SysOaProjectVo> oneList(SysOaProjectBo bo, PageQuery pageQuery) {
        bo.setTradeType(1L);
        return projectService.queryPageList2(bo, pageQuery);
    }

    /**
     * 查询进度管理列表
     */
    @GetMapping("/two-list")
    public TableDataInfo<OaProgressVo> twoList(OaProgressBo bo,  PageQuery pageQuery) {
        bo.setParentId(0L);
        return iOaProgressService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询进度管理列表
     */
    @GetMapping("/three-list")
    public TableDataInfo<OaProgressVo> threeList(OaProgressBo bo,  PageQuery pageQuery) {
        return iOaProgressService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询进度管理列表
     */
    @GetMapping("/four-list")
    public TableDataInfo<OaProgressDetailVo> fourList(OaProgressDetailBo bo, PageQuery pageQuery) {
        return detailService.queryPageList(bo, pageQuery);
    }


    /**
     * 导出进度管理列表
     */
    @Log(title = "进度管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaProgressBo bo, HttpServletResponse response) {
        List<OaProgressVo> list = iOaProgressService.queryList(bo);
        ExcelUtil.exportExcel(list, "进度管理", OaProgressVo.class, response);
    }

    /**
     * 新增进度管理
     */
    @Log(title = "进度管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProgressBo bo) {
        return toAjax(iOaProgressService.insertByBo(bo));
    }

    /**
     * 修改进度管理
     */
    @Log(title = "进度管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProgressBo bo) {
        return toAjax(iOaProgressService.updateByBo(bo));
    }

    /**
     * 删除进度管理
     *
     * @param progressIds 主键串
     */
    @Log(title = "进度管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{progressIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] progressIds) {
        return toAjax(iOaProgressService.deleteWithValidByIds(Arrays.asList(progressIds), true));
    }


    @GetMapping("/key-list")
    public R<List<OaProgressDetail>> getKeyList() {
        return R.ok(iOaProgressService.getKeyList());
    }



    /**
     * 获取进度管理详细信息
     *
     * @param projectId 主键
     */
    @GetMapping("/{projectId}")
    public R<List<OaProgressVo>> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable("projectId") Long projectId) {
        List<OaProgressVo> progressVos = iOaProgressService.queryByProjectId(projectId);
        return R.ok(progressVos);
    }

}
