package com.playlet.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PublicUserRecord;
import com.playlet.system.service.IPublicUserRecordService;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.utils.poi.ExcelUtil;
import com.playlet.common.core.page.TableDataInfo;

/**
 * 公众号用户浏览记录Controller
 *
 * @author ruoyi
 * @date 2024-06-15
 */
@Controller
@RequestMapping("/system/public/record")
public class PublicUserRecordController extends BaseController
{
    private String prefix = "system/public/record";

    @Autowired
    private IPublicUserRecordService publicUserRecordService;

    @RequiresPermissions("public:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询公众号用户浏览记录列表
     */
    @RequiresPermissions("public:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PublicUserRecord publicUserRecord)
    {
        startPage();
        List<PublicUserRecord> list = publicUserRecordService.selectPublicUserRecordList(publicUserRecord);
        return getDataTable(list);
    }

    /**
     * 导出公众号用户浏览记录列表
     */
    @RequiresPermissions("public:record:export")
    @Log(title = "公众号用户浏览记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PublicUserRecord publicUserRecord)
    {
        List<PublicUserRecord> list = publicUserRecordService.selectPublicUserRecordList(publicUserRecord);
        ExcelUtil<PublicUserRecord> util = new ExcelUtil<PublicUserRecord>(PublicUserRecord.class);
        return util.exportExcel(list, "公众号用户浏览记录数据");
    }

    /**
     * 新增公众号用户浏览记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公众号用户浏览记录
     */
    @RequiresPermissions("public:record:add")
    @Log(title = "公众号用户浏览记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PublicUserRecord publicUserRecord)
    {
        return toAjax(publicUserRecordService.insertPublicUserRecord(publicUserRecord));
    }

    /**
     * 修改公众号用户浏览记录
     */
    @RequiresPermissions("public:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PublicUserRecord publicUserRecord = publicUserRecordService.selectPublicUserRecordById(id);
        mmap.put("publicUserRecord", publicUserRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存公众号用户浏览记录
     */
    @RequiresPermissions("public:record:edit")
    @Log(title = "公众号用户浏览记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PublicUserRecord publicUserRecord)
    {
        return toAjax(publicUserRecordService.updatePublicUserRecord(publicUserRecord));
    }

    /**
     * 删除公众号用户浏览记录
     */
    @RequiresPermissions("public:record:remove")
    @Log(title = "公众号用户浏览记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(publicUserRecordService.deletePublicUserRecordByIds(ids));
    }
}
