package beilv.web.controller.admissionticket;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import beilv.admissionticket.domain.AdmissionTicket;
import beilv.admissionticket.service.IAdmissionTicketService;
import beilv.venue.domain.BeilvVenue;
import beilv.venue.service.IBeilvVenueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import beilv.common.annotation.Log;
import beilv.common.enums.BusinessType;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.utils.poi.ExcelUtil;
import beilv.common.core.page.TableDataInfo;

/**
 * 约球购票Controller
 *
 * @author LG
 * @date 2025-01-06
 */
@Controller
@RequestMapping("/admissionticket")
public class AdmissionTicketController extends BaseController {
    private String prefix = "admissionticket";

    @Autowired
    private IAdmissionTicketService beilvAdmissionTicketService;

    @Autowired
    private IBeilvVenueService beilvVenueService;

    @RequiresPermissions("admissionticket:AdmissionTicket:view")
    @GetMapping()
    public String AdmissionTicket(ModelMap mmap) {
        mmap.put("ticketDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return prefix + "/admissionTicket";
    }

    /**
     * 查询约球购票列表
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdmissionTicket beilvAdmissionTicket) {
        startPage();
        List<AdmissionTicket> list = beilvAdmissionTicketService.selectBeilvAdmissionTicketList(beilvAdmissionTicket);
        return getDataTable(list);
    }

    /**
     * 导出约球购票列表
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:export")
    @Log(title = "约球购票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdmissionTicket beilvAdmissionTicket) {
        List<AdmissionTicket> list = beilvAdmissionTicketService.selectBeilvAdmissionTicketList(beilvAdmissionTicket);
        ExcelUtil<AdmissionTicket> util = new ExcelUtil<AdmissionTicket>(AdmissionTicket.class);
        return util.exportExcel(list, "约球购票数据");
    }

    /**
     * 新增约球购票
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:add")
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<BeilvVenue> beilvSitesList = beilvVenueService.selectBeilvVenueList(new BeilvVenue());
        mmap.put("beilvSitesList", beilvSitesList);
        return prefix + "/add";
    }

    /**
     * 新增保存约球购票
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:add")
    @Log(title = "约球购票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdmissionTicket beilvAdmissionTicket) {
        return toAjax(beilvAdmissionTicketService.insertBeilvAdmissionTicket(beilvAdmissionTicket));
    }

    /**
     * 修改约球购票
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        AdmissionTicket beilvAdmissionTicket = beilvAdmissionTicketService.selectBeilvAdmissionTicketById(id);
        mmap.put("beilvAdmissionTicket", beilvAdmissionTicket);
        return prefix + "/edit";
    }

    /**
     * 修改保存约球购票
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:edit")
    @Log(title = "约球购票", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdmissionTicket beilvAdmissionTicket) {
        return toAjax(beilvAdmissionTicketService.updateBeilvAdmissionTicket(beilvAdmissionTicket));
    }

    /**
     * 删除约球购票
     */
    @RequiresPermissions("admissionticket:AdmissionTicket:remove")
    @Log(title = "约球购票", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(beilvAdmissionTicketService.deleteBeilvAdmissionTicketByIds(ids));
    }

    /**
     * 预定场地+时段
     */
    @PostMapping("/makeAnAppointment")
    @ResponseBody
    public AjaxResult makeAnAppointment(AdmissionTicket beilvAdmissionTicket){
        return toAjax(beilvAdmissionTicketService.updateBeilvAdmissionTicket(beilvAdmissionTicket));
    }

    /**
     * 手动核销
     */
    @PostMapping("/confirm")
    @ResponseBody
    public AjaxResult confirm(AdmissionTicket beilvAdmissionTicket){
        return toAjax(beilvAdmissionTicketService.confirm(beilvAdmissionTicket));
    }

    /**
     * 约球页面线下退款 暂未开启
     */
//    @PostMapping("/refund")
//    @ResponseBody
//    public AjaxResult refund(AdmissionTicket beilvAdmissionTicket){
//        return beilvAdmissionTicketService.refund(beilvAdmissionTicket);
//    }
}
