package com.ruoyi.frequency.browserecord.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.browserecord.entity.BrowseRecord;
import com.ruoyi.frequency.browserecord.service.BrowseRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 浏览记录Controller
 * 
 * @author liwenlong
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/frequency/browserecord")
public class BrowseRecordController extends BaseController
{
    @Autowired
    private BrowseRecordService browseRecordService;

    /**
     * 查询浏览记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:list')")
    @PostMapping("/list")
    public TableDataInfo<BrowseRecord> list(@RequestBody BrowseRecord browseRecord)
    {
        startPage();
        List<BrowseRecord> list = browseRecordService.selectBrowseRecordList(browseRecord);
        return getDataTable(list);
    }

    /**
     * 导出浏览记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:export')")
    @Log(title = "浏览记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BrowseRecord browseRecord)
    {
        List<BrowseRecord> list = browseRecordService.selectBrowseRecordList(browseRecord);
        ExcelUtil<BrowseRecord> util = new ExcelUtil<BrowseRecord>(BrowseRecord.class);
        return util.exportExcel(list, "浏览记录数据");
    }

    /**
     * 获取浏览记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<BrowseRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(browseRecordService.selectBrowseRecordById(id));
    }

    /**
     * 新增浏览记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:add')")
    @Log(title = "浏览记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrowseRecord browseRecord)
    {
        return toAjax(browseRecordService.insertBrowseRecord(browseRecord));
    }

    /**
     * 修改浏览记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:edit')")
    @Log(title = "浏览记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrowseRecord browseRecord)
    {
        return toAjax(browseRecordService.updateBrowseRecord(browseRecord));
    }

    /**
     * 删除浏览记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:browserecord:remove')")
    @Log(title = "浏览记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(browseRecordService.deleteBrowseRecordByIds(ids,delFlag));
    }
}
