package com.fs.hisStore.controller;

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 com.fs.hisStore.domain.FsStoreRecommendScrm;
import com.fs.hisStore.service.IFsStoreRecommendScrmService;
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 2023-06-15
 */
@RestController
@RequestMapping("/store/recommend")
public class FsStoreRecommendScrmController extends BaseController
{
    @Autowired
    private IFsStoreRecommendScrmService fsStoreRecommendService;

    /**
     * 查询店铺推荐列表
     */
    @PreAuthorize("@ss.hasPermi('store:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreRecommendScrm fsStoreRecommendScrm)
    {
        startPage();
        List<FsStoreRecommendScrm> list = fsStoreRecommendService.selectFsStoreRecommendScrmList(fsStoreRecommendScrm);
        return getDataTable(list);
    }

    /**
     * 获取店铺推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:recommend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsStoreRecommendService.selectFsStoreRecommendScrmById(id));
    }

    /**
     * 新增店铺推荐
     */
    @PreAuthorize("@ss.hasPermi('store:recommend:add')")
    @Log(title = "店铺推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreRecommendScrm fsStoreRecommendScrm)
    {
        return toAjax(fsStoreRecommendService.insertFsStoreRecommendScrm(fsStoreRecommendScrm));
    }

    /**
     * 修改店铺推荐
     */
    @PreAuthorize("@ss.hasPermi('store:recommend:edit')")
    @Log(title = "店铺推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreRecommendScrm fsStoreRecommendScrm)
    {
        return toAjax(fsStoreRecommendService.updateFsStoreRecommendScrm(fsStoreRecommendScrm));
    }

    /**
     * 删除店铺推荐
     */
    @PreAuthorize("@ss.hasPermi('store:recommend:delete')")
    @Log(title = "店铺推荐", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsStoreRecommendService.deleteFsStoreRecommendScrmByIds(ids));
    }

    /**
     * 查询有效的推荐店铺列表(用于前端展示)
     */
    @GetMapping("/validList")
    public TableDataInfo validList(FsStoreRecommendScrm fsStoreRecommendScrm)
    {
        startPage();
        List<FsStoreRecommendScrm> list = fsStoreRecommendService.selectValidRecommendList(fsStoreRecommendScrm);
        return getDataTable(list);
    }

    /**
     * 导出
     * */
    @PreAuthorize("@ss.hasPermi('store:recommend:export')")
    @Log(title = "店铺推荐", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreRecommendScrm fsStoreRecommendScrm)
        {
        List<FsStoreRecommendScrm> list = fsStoreRecommendService.selectFsStoreRecommendScrmList(fsStoreRecommendScrm);
        ExcelUtil<FsStoreRecommendScrm> util = new ExcelUtil<>(FsStoreRecommendScrm.class);
        return util.exportExcel(list, "店铺推荐数据");
    }
}
