package com.ruoyi.frequency.collect.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.collect.entity.Collect;
import com.ruoyi.frequency.collect.service.CollectService;
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 zj
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/frequency/collect")
public class CollectController extends BaseController
{
    @Autowired
    private CollectService collectService;

    /**
     * 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:list')")
    @GetMapping("/list")
    public TableDataInfo<Collect> list(Collect collect)
    {
        startPage();
        List<Collect> list = collectService.selectCollectList(collect);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Collect collect)
    {
        List<Collect> list = collectService.selectCollectList(collect);
        ExcelUtil<Collect> util = new ExcelUtil<Collect>(Collect.class);
        return util.exportExcel(list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Collect> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(collectService.selectCollectById(id));
    }

    /**
     * 新增收藏
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Collect collect)
    {
        return toAjax(collectService.insertCollect(collect));
    }

    /**
     * 修改收藏
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Collect collect)
    {
        return toAjax(collectService.updateCollect(collect));
    }

    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('frequency:collect:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(collectService.deleteCollectByIds(ids));
    }
}
