package com.ruoyi.web.controller.app;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISysUserOnlineTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;


//备用的,当websocket不能用时,应急的.
@RestController
@RequestMapping("/app/user/online")
public class SysUserOnlineTimeController {

    @Autowired
    private ISysUserOnlineTimeService userOnlineTimeService;

    // 暂时用不到
//    @GetMapping("/stats/{userId}")
//    public AjaxResult getUserOnlineStats(@PathVariable Long userId) {
//        return AjaxResult.success(userOnlineTimeService.selectUserOnlineStats(userId));
//    }
    // 这就纯纯为了socket失败备用的请求地址
    @PostMapping("/heartbeat")
    public AjaxResult heartbeat() {
        Long userId = getUserId();
    	userOnlineTimeService.updateUserHeartbeat(userId, 5000L);
    	return AjaxResult.success();
    }

    @PostMapping("/logout")
    public AjaxResult logout() {
        Long userId = getUserId();
    	userOnlineTimeService.recordUserLogout(userId);
    	return AjaxResult.success();
    }


}
