package org.dromara.system.controller.reservat;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.core.domain.AjaxResult;
import org.dromara.system.domain.reservat.bo.XiaoyuanReservatBo;
import org.dromara.system.domain.reservat.vo.XiaoyuanReservatVo;
import org.dromara.system.service.reservat.IXiaoyuanReservatService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 校园预约
 *
 * @author boman
 * @date 2023-09-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@SaIgnore
@RequestMapping("/system/reservat")
public class XiaoyuanReservatController extends BaseController {

    private final IXiaoyuanReservatService xiaoyuanReservatService;

    /**
     * 查询校园预约列表
     */
    @SaCheckPermission("system:reservat:list")
    @GetMapping("/list")
    public TableDataInfo<XiaoyuanReservatVo> list(XiaoyuanReservatBo bo, PageQuery pageQuery) {
        return xiaoyuanReservatService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出校园预约列表
     */
    @SaCheckPermission("system:reservat:export")
    @Log(title = "校园预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XiaoyuanReservatBo bo, HttpServletResponse response) {
        List<XiaoyuanReservatVo> list = xiaoyuanReservatService.queryList(bo);
        ExcelUtil.exportExcel(list, "校园预约", XiaoyuanReservatVo.class, response);
    }

    /**
     * 获取校园预约详细信息
     *
     * @param reservatId 主键
     */
    @SaCheckPermission("system:reservat:query")
    @GetMapping("/{reservatId}")
    public R<XiaoyuanReservatVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long reservatId) {
        return R.ok(xiaoyuanReservatService.queryById(reservatId));
    }

    /**
     * 新增校园预约
     */
    @SaCheckPermission("system:reservat:add")
    @Log(title = "校园预约", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XiaoyuanReservatBo bo) {
        return toAjax(xiaoyuanReservatService.insertByBo(bo));
    }

    /**
     * 修改校园预约
     */
    @SaCheckPermission("system:reservat:edit")
    @Log(title = "校园预约", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XiaoyuanReservatBo bo) {
        return toAjax(xiaoyuanReservatService.updateByBo(bo));
    }

    /**
     * 删除校园预约
     *
     * @param reservatIds 主键串
     */
    @SaCheckPermission("system:reservat:remove")
    @Log(title = "校园预约", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{reservatIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] reservatIds) {
        return toAjax(xiaoyuanReservatService.deleteWithValidByIds(List.of(reservatIds), true));
    }

    /**
     * 校园预约核销
     *
     * @param reservatId
     */
    @SaCheckPermission("system:reservat:cav")
    @Log(title = "校园预约", businessType = BusinessType.DELETE)
    @GetMapping("/cav")
    public R<Void> cav(Long reservatId) {
        return xiaoyuanReservatService.cav(reservatId);
    }


    /**
     * 根据教职工手机号查询可预约的时间
     */
    @PostMapping("/subscribe")
    public AjaxResult subscribe(@RequestBody XiaoyuanReservatBo bo) {
        return  xiaoyuanReservatService.subscribe(bo);
    }

    /**
     * 预约首页统计
     */
    @PostMapping("/indexStatistics")
    public AjaxResult indexStatistics(@RequestBody XiaoyuanReservatBo bo) {
        return  xiaoyuanReservatService.indexStatistics(bo);
    }


    /**
     * 修改校园sh
     */
    @SaCheckPermission("system:reservat:sh")
    @RepeatSubmit()
    @PostMapping("/sh")
    public R<Void> sh(@Validated(EditGroup.class) @RequestBody XiaoyuanReservatBo bo) {
        return toAjax(xiaoyuanReservatService.shByBo(bo));
    }

}
