package com.ruoyi.frequency.follow.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.follow.entity.Follow;
import com.ruoyi.frequency.follow.service.FollowService;
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-07-22
 */
@RestController
@RequestMapping("/frequency/follow")
public class FollowController extends BaseController
{
    @Autowired
    private FollowService followService;

    /**
     * 查询关注列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:follow:list')")
    @PostMapping("/list")
    public TableDataInfo<Follow> list(@RequestBody Follow follow)
    {
        startPage();
        List<Follow> list = followService.selectFollowList(follow);
        return getDataTable(list);
    }

    /**
     * 导出关注列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:follow:export')")
    @Log(title = "关注", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Follow follow)
    {
        List<Follow> list = followService.selectFollowList(follow);
        ExcelUtil<Follow> util = new ExcelUtil<Follow>(Follow.class);
        return util.exportExcel(list, "关注数据");
    }

    /**
     * 获取关注详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:follow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(followService.selectFollowById(id));
    }

    /**
     * 新增关注
     */
    @PreAuthorize("@ss.hasPermi('frequency:follow:add')")
    @Log(title = "关注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Follow follow)
    {
        return toAjax(followService.insertFollow(follow));
    }

    /**
     * 修改关注
     */
    @PreAuthorize("@ss.hasPermi('frequency:follow:edit')")
    @Log(title = "关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Follow follow)
    {
        return toAjax(followService.updateFollow(follow));
    }

    /**
     * 删除关注
     */
    @PreAuthorize("@ss.hasPermi('frequency:follow:remove')")
    @Log(title = "关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(followService.deleteFollowByIds(ids));
    }
}
