package com.ruoyi.web.controller.reservat;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BomanReservat;
import com.ruoyi.system.service.IBomanReservatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import sun.misc.BASE64Encoder;

/**
 * 陵园预约Controller
 *
 * @author ruoyi
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/system/reservat")
public class BomanReservatController extends BaseController {
    @Autowired
    private IBomanReservatService bomanReservatService;

    /**
     * 查询陵园预约列表
     */
    //@PreAuthorize("@ss.hasPermi('system:reservat:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomanReservat bomanReservat) {
        startPage();
        List<BomanReservat> list = bomanReservatService.selectBomanReservatList(bomanReservat);
        return getDataTable(list);
    }

    /**
     * 导出陵园预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:reservat:export')")
    @Log(title = "陵园预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomanReservat bomanReservat) {
        List<BomanReservat> list = bomanReservatService.selectBomanReservatList(bomanReservat);
        ExcelUtil<BomanReservat> util = new ExcelUtil<BomanReservat>(BomanReservat.class);
        util.exportExcel(response, list, "陵园预约数据");
    }

    /**
     * 获取陵园预约详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:reservat:query')")
    @GetMapping(value = "/{reservatId}")
    public AjaxResult getInfo(@PathVariable("reservatId") Long reservatId) {
        return success(bomanReservatService.selectBomanReservatByReservatId(reservatId));
    }

    /**
     * 新增陵园预约
     */
    //@PreAuthorize("@ss.hasPermi('system:reservat:add')")
    //@Log(title = "陵园预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomanReservat bomanReservat) {
        int i = bomanReservatService.insertBomanReservat(bomanReservat);
        return i > 0 ? AjaxResult.success(i) : AjaxResult.error("超过最大可预约人数或接待人员已满,请重新选择");
    }

    /**
     * 修改陵园预约
     */
    @PreAuthorize("@ss.hasPermi('system:reservat:edit')")
    @Log(title = "陵园预约", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody BomanReservat bomanReservat) {
        return bomanReservatService.updateBomanReservat(bomanReservat);
    }

    /**
     * 陵园预约审核
     */
    @PreAuthorize("@ss.hasPermi('system:reservat:sh')")
    @PostMapping("/sh")
    public AjaxResult examine(@RequestBody BomanReservat bomanReservat) {
        return bomanReservatService.examine(bomanReservat);
    }

    /**
     * 陵园预约核销
     */
    @PreAuthorize("@ss.hasPermi('system:reservat:hx')")
    @GetMapping("/hx")
    public AjaxResult verification(Long reservatId) {
        return bomanReservatService.verification(reservatId);
    }

    /**
     * 删除陵园预约
     */
    @GetMapping("/delete/{receptionIds}")
    public AjaxResult remove(@PathVariable Long[] receptionIds) {
        return toAjax(bomanReservatService.deleteBomanReservatByReservatIds(receptionIds));
    }

    /**
     * 陵园实时参观统计
     */
    @GetMapping("/statistics/realTime")
    public AjaxResult realTime() {
        return bomanReservatService.realTime();
    }

    /**
     * 陵园实时参观统计
     */
    @GetMapping("/statistics/people")
    public AjaxResult people() {
        return bomanReservatService.people();
    }


}
