package com.fs.store.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.store.domain.FsAdv;
import com.fs.store.service.IFsAdvService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 广告Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/adv")
public class FsAdvController extends BaseController
{
    @Autowired
    private IFsAdvService fsAdvService;

    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('store:adv:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsAdv fsAdv)
    {
        startPage();
        List<FsAdv> list = fsAdvService.selectFsAdvList(fsAdv);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('store:adv:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsAdv fsAdv)
    {
        List<FsAdv> list = fsAdvService.selectFsAdvList(fsAdv);
        ExcelUtil<FsAdv> util = new ExcelUtil<FsAdv>(FsAdv.class);
        return util.exportExcel(list, "adv");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:adv:query')")
    @GetMapping(value = "/{advId}")
    public AjaxResult getInfo(@PathVariable("advId") Long advId)
    {
        return AjaxResult.success(fsAdvService.selectFsAdvById(advId));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsAdv fsAdv)
    {
        return toAjax(fsAdvService.insertFsAdv(fsAdv));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsAdv fsAdv)
    {
        return toAjax(fsAdvService.updateFsAdv(fsAdv));
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advIds}")
    public AjaxResult remove(@PathVariable Long[] advIds)
    {
        return toAjax(fsAdvService.deleteFsAdvByIds(advIds));
    }
}
