package com.ruoyi.web.controller.system;

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.ss.onlineLog.domain.OnlineLog;
import com.ruoyi.ss.onlineLog.service.IOnlineLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 在线/离线日志Controller
 *
 * @author 邱贞招
 * @date 2024-07-13
 */
@RestController
@RequestMapping("/system/onlineLog")
public class OnlineLogController extends BaseController
{
    @Autowired
    private IOnlineLogService etOnlineLogService;

    /**
     * 查询在线/离线日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(OnlineLog eOnlineLog)
    {
        startPage();
        List<OnlineLog> list = etOnlineLogService.selectEtOnlineLogList(eOnlineLog);
        return getDataTable(list);
    }

    /**
     * 导出在线/离线日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:export')")
    @Log(title = "在线/离线日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OnlineLog eOnlineLog)
    {
        List<OnlineLog> list = etOnlineLogService.selectEtOnlineLogList(eOnlineLog);
        ExcelUtil<OnlineLog> util = new ExcelUtil<OnlineLog>(OnlineLog.class);
        util.exportExcel(response, list, "在线/离线日志数据");
    }

    /**
     * 获取在线/离线日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(etOnlineLogService.selectEtOnlineLogById(id));
    }

    /**
     * 新增在线/离线日志
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:add')")
    @Log(title = "在线/离线日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OnlineLog eOnlineLog)
    {
        return toAjax(etOnlineLogService.insertEtOnlineLog(eOnlineLog));
    }

    /**
     * 修改在线/离线日志
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:edit')")
    @Log(title = "在线/离线日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OnlineLog eOnlineLog)
    {
        return toAjax(etOnlineLogService.updateEtOnlineLog(eOnlineLog));
    }

    /**
     * 删除在线/离线日志
     */
    @PreAuthorize("@ss.hasPermi('system:onlineLog:remove')")
    @Log(title = "在线/离线日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(etOnlineLogService.deleteEtOnlineLogByIds(ids));
    }
}
