package com.ruoyi.frequency.hosearch.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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.frequency.hosearch.entity.HotSearch;
import com.ruoyi.frequency.hosearch.service.HotSearchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热门搜索记录Controller
 * 
 * @author liwenlong
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/frequency/hosearch")
public class HotSearchController extends BaseController
{
    @Autowired
    private HotSearchService hotSearchService;

    /**
     * 查询热门搜索记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:list')")
    @GetMapping("/list")
    public TableDataInfo<HotSearch> list(HotSearch hotSearch)
    {
        startPage();
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        return getDataTable(list);
    }

    /**
     * 导出热门搜索记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:export')")
    @Log(title = "热门搜索记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HotSearch hotSearch)
    {
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        ExcelUtil<HotSearch> util = new ExcelUtil<HotSearch>(HotSearch.class);
        return util.exportExcel(list, "热门搜索记录数据");
    }

    /**
     * 获取热门搜索记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<HotSearch> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hotSearchService.selectHotSearchById(id));
    }

    /**
     * 新增热门搜索记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:add')")
    @Log(title = "热门搜索记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotSearch hotSearch)
    {
        return toAjax(hotSearchService.insertHotSearch(hotSearch));
    }

    /**
     * 修改热门搜索记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:edit')")
    @Log(title = "热门搜索记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotSearch hotSearch)
    {
        return toAjax(hotSearchService.updateHotSearch(hotSearch));
    }

    /**
     * 删除热门搜索记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:hosearch:remove')")
    @Log(title = "热门搜索记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(hotSearchService.deleteHotSearchByIds(ids,delFlag));
    }
}
