package com.fs.ad.controller;

import java.util.List;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.ad.domain.AdAccount;
import com.fs.ad.service.IAdAccountService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 推广账户Controller
 * 
 * @author fs
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/ad/adAccount")
public class AdAccountController extends BaseController
{
    @Autowired
    private IAdAccountService adAccountService;

    /**
     * 查询推广账户列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdAccount adAccount)
    {
        startPage();
        List<AdAccount> list = adAccountService.selectAdAccountList(adAccount);
        return getDataTable(list);
    }

    /**
     * 导出推广账户列表
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:export')")
    @Log(title = "推广账户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdAccount adAccount)
    {
        List<AdAccount> list = adAccountService.selectAdAccountList(adAccount);
        ExcelUtil<AdAccount> util = new ExcelUtil<AdAccount>(AdAccount.class);
        return util.exportExcel(list, "推广账户数据");
    }

    /**
     * 获取推广账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(adAccountService.selectAdAccountById(id));
    }

    /**
     * 新增推广账户
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:add')")
    @Log(title = "推广账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdAccount adAccount)
    {
        return toAjax(adAccountService.insertAdAccount(adAccount));
    }

    /**
     * 修改推广账户
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:edit')")
    @Log(title = "推广账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdAccount adAccount)
    {
        return toAjax(adAccountService.updateAdAccount(adAccount));
    }

    /**
     * 删除推广账户
     */
    @PreAuthorize("@ss.hasPermi('ad:adAccount:remove')")
    @Log(title = "推广账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adAccountService.deleteAdAccountByIds(ids));
    }
}
