package beilv.site.controller;

import java.util.List;

import beilv.shopping.domain.QmjsShoppingMall;
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.site.domain.BeilvSite;
import beilv.site.service.IBeilvSiteService;
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 lc
 * @date 2025-01-06
 */
@Controller
@RequestMapping("/system/site")
public class BeilvSiteController extends BaseController {
    private String prefix = "system/site";

    @Autowired
    private IBeilvSiteService beilvSiteService;

    @Autowired
    private IBeilvVenueService beilvVenueService;


    @RequiresPermissions("system:site:view")
    @GetMapping()
    public String site() {
        return prefix + "/site";
    }

    /**
     * 查询球场管理列表
     */
    @RequiresPermissions("system:site:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BeilvSite beilvSite) {
        startPage();
        List<BeilvSite> list = beilvSiteService.selectBeilvSiteList(beilvSite);
        return getDataTable(list);
    }

    /**
     * 导出球场管理列表
     */
    @RequiresPermissions("system:site:export")
    @Log(title = "球场管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BeilvSite beilvSite) {
        List<BeilvSite> list = beilvSiteService.selectBeilvSiteList(beilvSite);
        ExcelUtil<BeilvSite> util = new ExcelUtil<BeilvSite>(BeilvSite.class);
        return util.exportExcel(list, "球场管理数据");
    }

    /**
     * 新增球场管理
     */
    @RequiresPermissions("system:site:add")
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<BeilvVenue> beilvSitesList = beilvVenueService.selectBeilvVenueList(new BeilvVenue());
        mmap.put("beilvSitesList", beilvSitesList);
        return prefix + "/add";
    }

    /**
     * 新增保存球场管理
     */
    @RequiresPermissions("system:site:add")
    @Log(title = "球场管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BeilvSite beilvSite) {
        return judgment(beilvSiteService.insertBeilvSite(beilvSite));
    }

    /**
     * 修改球场管理
     */
    @RequiresPermissions("system:site:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BeilvSite beilvSite = beilvSiteService.selectBeilvSiteById(id);
        List<BeilvVenue> beilvSitesList = beilvVenueService.selectBeilvVenueList(new BeilvVenue());
        mmap.put("beilvSitesList", beilvSitesList);
        mmap.put("beilvSite", beilvSite);
        return prefix + "/edit";
    }

    /**
     * 修改保存球场管理
     */
    @RequiresPermissions("system:site:edit")
    @Log(title = "球场管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BeilvSite beilvSite) {
        return judgment(beilvSiteService.updateBeilvSite(beilvSite));
    }

    private AjaxResult judgment(int i) {
        if (i > 0) {
            return toAjax(i);
        } else {
            return AjaxResult.error("当前名称的数据已存在");
        }
    }

    /**
     * 删除球场管理
     */
    @RequiresPermissions("system:site:remove")
    @Log(title = "球场管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(beilvSiteService.deleteBeilvSiteByIds(ids));
    }

    @GetMapping("/selectStadium")
    public AjaxResult selectStadium() {
        return AjaxResult.success(beilvSiteService.selectBeilvSiteList(new BeilvSite()));
    }

    /**
     * 球场状态修改
     */
    @Log(title = "球场管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:site:edit")
    @PostMapping("/siteStatus")
    @ResponseBody
    public AjaxResult siteStatus(BeilvSite beilvSite)
    {
        return toAjax(beilvSiteService.siteStatus(beilvSite));
    }
}
