package com.ruoyi.frequency.recommend.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.recommend.entity.Recommend;
import com.ruoyi.frequency.recommend.service.RecommendService;
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 liwenlong
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/frequency/recommend")
public class RecommendController extends BaseController
{
    @Autowired
    private RecommendService recommendService;

    /**
     * 查询推荐列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo<Recommend> list(Recommend recommend)
    {
        startPage();
        List<Recommend> list = recommendService.selectRecommendList(recommend);
        return getDataTable(list);
    }

    /**
     * 导出推荐列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:recommend:export')")
    @Log(title = "推荐", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Recommend recommend)
    {
        List<Recommend> list = recommendService.selectRecommendList(recommend);
        ExcelUtil<Recommend> util = new ExcelUtil<Recommend>(Recommend.class);
        return util.exportExcel(list, "推荐数据");
    }

    /**
     * 获取推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:recommend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Recommend> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(recommendService.selectRecommendById(id));
    }

    /**
     * 新增推荐
     */
    @PreAuthorize("@ss.hasPermi('frequency:recommend:add')")
    @Log(title = "推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recommend recommend)
    {
        return toAjax(recommendService.insertRecommend(recommend));
    }

    /**
     * 修改推荐
     */
    @PreAuthorize("@ss.hasPermi('frequency:recommend:edit')")
    @Log(title = "推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recommend recommend)
    {
        return toAjax(recommendService.updateRecommend(recommend));
    }

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