package com.ruoyi.system.controller;

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.SysScenic;
import com.ruoyi.system.service.ISysScenicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景区Controller
 * 
 * @author haotian
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/system/scenic")
public class SysScenicController extends BaseController
{
    @Autowired
    private ISysScenicService sysScenicService;

    /**
     * 查询景区列表
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysScenic sysScenic)
    {
        startPage();
        List<SysScenic> list = sysScenicService.selectSysScenicList(sysScenic);
        return getDataTable(list);
    }

    /**
     * 导出景区列表
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:export')")
    @Log(title = "景区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysScenic sysScenic)
    {
        List<SysScenic> list = sysScenicService.selectSysScenicList(sysScenic);
        ExcelUtil<SysScenic> util = new ExcelUtil<SysScenic>(SysScenic.class);
        util.exportExcel(response, list, "景区数据");
    }

    /**
     * 获取景区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:query')")
    @GetMapping(value = "/{scenicId}")
    public AjaxResult getInfo(@PathVariable("scenicId") Long scenicId)
    {
        return success(sysScenicService.selectSysScenicByScenicId(scenicId));
    }

    /**
     * 新增景区
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:add')")
    @Log(title = "景区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysScenic sysScenic)
    {
        return toAjax(sysScenicService.insertSysScenic(sysScenic));
    }

    /**
     * 修改景区
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:edit')")
    @Log(title = "景区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysScenic sysScenic)
    {
        return toAjax(sysScenicService.updateSysScenic(sysScenic));
    }

    /**
     * 删除景区
     */
    @PreAuthorize("@ss.hasPermi('system:scenic:remove')")
    @Log(title = "景区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicIds}")
    public AjaxResult remove(@PathVariable Long[] scenicIds)
    {
        return toAjax(sysScenicService.deleteSysScenicByScenicIds(scenicIds));
    }
}
