package org.dromara.system.controller.reservat;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.reservat.bo.XiaoyuanReservatConfigBo;
import org.dromara.system.domain.reservat.vo.XiaoyuanReservatConfigVo;
import org.dromara.system.service.reservat.IXiaoyuanReservatConfigService;
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
@RequestMapping("/system/reservatConfig")
public class XiaoyuanReservatConfigController extends BaseController {

    private final IXiaoyuanReservatConfigService xiaoyuanReservatConfigService;

    /**
     * 查询校园预约配置列表
     */
    @SaCheckPermission("system:reservatConfig:list")
    @GetMapping("/list")
    public TableDataInfo<XiaoyuanReservatConfigVo> list(XiaoyuanReservatConfigBo bo, PageQuery pageQuery) {
        return xiaoyuanReservatConfigService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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