package com.fs.ad.controller;

import com.fs.ad.domain.AdDomain;
import com.fs.ad.service.IAdDomainService;
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.domain.R;
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/adDomain")
public class AdDomainController extends BaseController
{
    @Autowired
    private IAdDomainService adDomainService;

    /**
     * 查询广告域名列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdDomain adDomain)
    {
        startPage();
        List<AdDomain> list = adDomainService.selectAdDomainList(adDomain);
        return getDataTable(list);
    }

    /**
     * 导出广告域名列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:export')")
    @Log(title = "广告域名", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdDomain adDomain)
    {
        List<AdDomain> list = adDomainService.selectAdDomainList(adDomain);
        ExcelUtil<AdDomain> util = new ExcelUtil<AdDomain>(AdDomain.class);
        return util.exportExcel(list, "广告域名数据");
    }

    /**
     * 获取广告域名详细信息
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(adDomainService.selectAdDomainById(id));
    }

    /**
     * 新增广告域名
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:add')")
    @Log(title = "广告域名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdDomain adDomain)
    {
        return toAjax(adDomainService.insertAdDomain(adDomain));
    }

    /**
     * 修改广告域名
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:edit')")
    @Log(title = "广告域名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdDomain adDomain)
    {
        return toAjax(adDomainService.updateAdDomain(adDomain));
    }

    /**
     * 删除广告域名
     */
    @PreAuthorize("@ss.hasPermi('ad:adDomain:remove')")
    @Log(title = "广告域名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adDomainService.deleteAdDomainByIds(ids));
    }




    @GetMapping(value = "/listAll")
    public R listAll(){
        return R.ok().put("data", adDomainService.list());
    }
}
