package com.fs.ad.controller;

import com.fs.ad.domain.AdSite;
import com.fs.ad.service.IAdSiteService;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站点管理Controller
 * 
 * @author fs
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/ad/adSite")
public class AdSiteController extends BaseController
{
    @Autowired
    private IAdSiteService adSiteService;

    /**
     * 查询站点管理列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdSite adSite)
    {
        startPage();
        List<AdSite> list = adSiteService.selectAdSiteList(adSite);
        return getDataTable(list);
    }

    /**
     * 导出站点管理列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:export')")
    @Log(title = "站点管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdSite adSite)
    {
        List<AdSite> list = adSiteService.selectAdSiteList(adSite);
        ExcelUtil<AdSite> util = new ExcelUtil<AdSite>(AdSite.class);
        return util.exportExcel(list, "站点管理数据");
    }

    /**
     * 获取站点管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(adSiteService.selectAdSiteById(id));
    }

    /**
     * 新增站点管理
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:add')")
    @Log(title = "站点管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdSite adSite)
    {
        return toAjax(adSiteService.insertAdSite(adSite));
    }

    /**
     * 修改站点管理
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:edit')")
    @Log(title = "站点管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdSite adSite)
    {
        return toAjax(adSiteService.updateAdSite(adSite));
    }

    /**
     * 删除站点管理
     */
    @PreAuthorize("@ss.hasPermi('ad:adSite:remove')")
    @Log(title = "站点管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adSiteService.deleteAdSiteByIds(ids));
    }

}
