package com.bonus.zlpt.equip.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.log.annotation.Log;
import com.bonus.zlpt.common.log.enums.BusinessType;
import com.bonus.zlpt.common.security.annotation.RequiresPermissions;
import com.bonus.zlpt.equip.api.domain.HotSearch;
import io.swagger.annotations.Api;
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.bonus.zlpt.equip.service.IHotSearchService;

/**
 * 热搜设备Controller
 * 
 * @author xsheng
 * @date 2023-12-02
 */
@Api(tags = "装备浏览量接口")
@RestController
@RequestMapping("/search")
public class HotSearchController extends BaseController
{
    @Autowired
    private IHotSearchService hotSearchService;

    /**
     * 查询热搜设备列表
     */
    @RequiresPermissions("equip:search:list")
    @GetMapping("/list")
    public TableDataInfo list(HotSearch hotSearch)
    {
        startPage();
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        return getDataTable(list);
    }

    /**
     * 导出热搜设备列表
     */
    @RequiresPermissions("equip:search:export")
    @Log(title = "热搜设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotSearch hotSearch)
    {
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        ExcelUtil<HotSearch> util = new ExcelUtil<HotSearch>(HotSearch.class);
        util.exportExcel(response, list, "热搜设备数据");
    }

    /**
     * 获取热搜设备详细信息
     */
    @RequiresPermissions("equip:search:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hotSearchService.selectHotSearchById(id));
    }

    /**
     * 新增热搜设备
     */
    @RequiresPermissions("equip:search:add")
    @Log(title = "热搜设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotSearch hotSearch)
    {
        return toAjax(hotSearchService.insertHotSearch(hotSearch));
    }

    /**
     * 修改热搜设备
     */
    @RequiresPermissions("equip:search:edit")
    @Log(title = "热搜设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotSearch hotSearch)
    {
        return toAjax(hotSearchService.updateHotSearch(hotSearch));
    }

    /**
     * 删除热搜设备
     */
    @RequiresPermissions("equip:search:remove")
    @Log(title = "热搜设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hotSearchService.deleteHotSearchByIds(ids));
    }
}
