#init
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.maibu.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.manager.DeviceSessionManager;
|
||||
import com.fastbee.memory.MiddleGlobalMemory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/websocket")
|
||||
public class WebMiddlewareController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
|
||||
@GetMapping("/judgeConnection")
|
||||
public AjaxResult JudgeConnection(@RequestParam String userName, @RequestParam Integer sourceType, @RequestParam String token) {
|
||||
|
||||
String source = "web";
|
||||
if (sourceType == 1) {
|
||||
source = "web";
|
||||
} else if (sourceType == 2) {
|
||||
source = "app";
|
||||
} else if (sourceType == 3) {
|
||||
source = "pc";
|
||||
}
|
||||
String key = userName + ":" + source + ":" + token;
|
||||
if (MiddleGlobalMemory.onlineSockets.containsKey(key)) {
|
||||
return AjaxResult.success(true);
|
||||
} else {
|
||||
String keyContains = userName + ":" + source;
|
||||
boolean res = true;
|
||||
for (String s : MiddleGlobalMemory.onlineSockets.keySet()) {
|
||||
if (s.contains(keyContains)) {
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return AjaxResult.success(res);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/allMemory")
|
||||
public AjaxResult memory() {
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
res.put("deviceMap", deviceSessionManager.getDeviceMap());
|
||||
res.put("channelToDeviceIdMap", deviceSessionManager.getChannelToDeviceIdMap());
|
||||
res.put("channelMap", deviceSessionManager.getChannelMap());
|
||||
res.put("onlineSockets", MiddleGlobalMemory.onlineSockets.size());
|
||||
res.put("controlMap", MiddleGlobalMemory.controlMap);
|
||||
List<String> nettyClients = new ArrayList<>();
|
||||
MiddleGlobalMemory.nettyClientMap.values().forEach(x -> {
|
||||
if (x != null) {
|
||||
nettyClients.add(x.userName +":"+ x.token);
|
||||
}
|
||||
});
|
||||
res.put("nettyClientMap", nettyClients);
|
||||
return AjaxResult.success(res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user