package com.ruoyi.oa.controller;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.oa.domain.CalendarDay;
import com.ruoyi.oa.domain.vo.SysHolidayVo;
import com.ruoyi.oa.domain.vo.SysOaHolidayListVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

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.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.SysOaHolidayVo;
import com.ruoyi.oa.domain.bo.SysOaHolidayBo;
import com.ruoyi.oa.service.ISysOaHolidayService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 休假管理
 *
 * @author liuzongkun999
 * @date 2025-02-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/oaHoliday")
public class SysOaHolidayController extends BaseController {

    private final ISysOaHolidayService iSysOaHolidayService;

    /**
     * 查询休假管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysOaHolidayVo> list(SysOaHolidayBo bo, PageQuery pageQuery) {
        return iSysOaHolidayService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出休假管理列表
     */
    @Log(title = "休假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaHolidayBo bo, HttpServletResponse response) {
        List<SysOaHolidayVo> list = iSysOaHolidayService.queryList(bo);
        ExcelUtil.exportExcel(list, "休假管理", SysOaHolidayVo.class, response);
    }

    /**
     * 获取休假管理详细信息
     *
     * @param holidayId 主键
     */
    @GetMapping("/{holidayId}")
    public R<SysOaHolidayVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long holidayId) {
        return R.ok(iSysOaHolidayService.queryById(holidayId));
    }

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

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

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

    /**
     * 查询指定日期的休假信息
     */
    @GetMapping("/queryHolidayByDate")
    public R<SysOaHolidayVo> queryHolidayByDate(@NotBlank(message = "日期不能为空") Date date){
        return R.ok(iSysOaHolidayService.queryHolidayByDate(date));
    }
    /**
     * 根据节假日类别查询相应的休假
     */
    @GetMapping("/queryHolidayByType")
    public R<List<SysOaHolidayListVo>> queryHolidayByType(@NotNull(message = "类别不能为空") Integer type){
        return R.ok(iSysOaHolidayService.queryHolidayByType(type));
    }

    /**
     * 查询当前月的所有休假
     */
    @GetMapping("/queryHolidayNowMonth")
    public R<List<SysOaHolidayVo>> queryHolidayNowMonth(){
        return R.ok(iSysOaHolidayService.queryHolidayNowMonth());
    }

    /**
     * 更新一段时间的休假状态
     */
    @PutMapping("/updateHolidayStatusByDate")
    public R<Void> updateHolidayStatusByDate(Integer type, @NotNull(message = "起始日期不能为空") Date startDate, @NotNull(message = "结束日期不能为空")Date endDate){
        return toAjax(iSysOaHolidayService.updateHolidayStatusByDate(type, startDate, endDate));
    }

    @GetMapping("/queryList")
    public R<List<SysHolidayVo>> queryList(SysOaHolidayBo bo){
        return R.ok(iSysOaHolidayService.queryVoList(bo));
    }

    @GetMapping("/queryOwnList")
    public List<CalendarDay> queryOwnList(SysOaHolidayBo bo, PageQuery pageQuery){
        return iSysOaHolidayService.queryOwnList(bo,pageQuery);
    }
}
