|
@ -12,11 +12,6 @@ var onlineCache = null;
|
|
|
class OnlineCache{
|
|
|
|
|
|
constructor() {
|
|
|
this._helper = 0;
|
|
|
this._teacher = 0;
|
|
|
this._child = 0;
|
|
|
this._olderWx = 0;
|
|
|
this._olderPad = 0;
|
|
|
this._helperMap = new Map();
|
|
|
this._teacherMap = new Map();
|
|
|
this._childMap = new Map();
|
|
@ -60,49 +55,34 @@ class OnlineCache{
|
|
|
|
|
|
getCountByType(type){
|
|
|
if("helper" == type){
|
|
|
return this._helper;
|
|
|
return this._helperMap.size;
|
|
|
}else if("teacher" == type){
|
|
|
return this._teacher;
|
|
|
return this._teacherMap.size;
|
|
|
}else if("child" == type){
|
|
|
return this._child;
|
|
|
return this._childMap.size;
|
|
|
}else if("olderWx" == type){
|
|
|
return this._olderWx;
|
|
|
return this._olderWxMap.size;
|
|
|
}else if("olderPad" == type){
|
|
|
return this._olderPad;
|
|
|
return this._olderPadMap.size;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
//新增用户,判断用户是否在线,在线人数统计
|
|
|
addUser(userId,type) {
|
|
|
var key = userId+":"+type;
|
|
|
var count = this.findByIdAndType(userId,type);
|
|
|
let key = userId+":"+type;
|
|
|
let count = this.findByIdAndType(userId,type);
|
|
|
if(count&&count>0){
|
|
|
log.info(count + '重复加入 ', key);
|
|
|
this.setUser(userId,type,count+1);
|
|
|
}else{
|
|
|
log.info('第一次加入 ', key);
|
|
|
this.setUser(userId,type,1);
|
|
|
if("helper" == type){
|
|
|
this._helper = this._helper+1;
|
|
|
}
|
|
|
if("teacher" == type){
|
|
|
this._teacher = this._teacher+1;
|
|
|
}
|
|
|
if("child" == type){
|
|
|
this._child = this._child+1;
|
|
|
}
|
|
|
if("olderWx" == type){
|
|
|
this._olderWx = this._olderWx+1;
|
|
|
}
|
|
|
if("olderPad" == type){
|
|
|
this._olderPad = this._olderPad+1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
setUser(userId,type,count){
|
|
|
if(count<0){
|
|
|
if(count<=0){
|
|
|
return;
|
|
|
}
|
|
|
if("helper" == type){
|
|
@ -148,25 +128,37 @@ class OnlineCache{
|
|
|
log.info(type+"--离线--");
|
|
|
return;
|
|
|
}
|
|
|
var key = userId+":"+type;
|
|
|
var count = this.findByIdAndType(userId,type);
|
|
|
if(count&&count>0){
|
|
|
let key = userId+":"+type;
|
|
|
let count = this.findByIdAndType(userId,type);
|
|
|
if(count&&count>1){
|
|
|
log.info(count + '离线 ', key);
|
|
|
this.setUser(userId,type,count-1);
|
|
|
}else if(count&&count==1){
|
|
|
log.info(count + '最后离线 ', key);
|
|
|
if("helper" == type){
|
|
|
this._helper = this._helper-1;
|
|
|
if(this._helperMap.get(userId)){
|
|
|
this._helperMap.delete(userId);
|
|
|
}
|
|
|
}
|
|
|
if("teacher" == type){
|
|
|
this._teacher = this._teacher-1;
|
|
|
if(this._teacherMap.get(userId)){
|
|
|
this._teacherMap.delete(userId);
|
|
|
}
|
|
|
}
|
|
|
if("child" == type){
|
|
|
this._child = this._child-1;
|
|
|
if(this._childMap.get(userId)){
|
|
|
this._childMap.delete(userId);
|
|
|
}
|
|
|
}
|
|
|
if("olderWx" == type){
|
|
|
this._olderWx = this._olderWx-1;
|
|
|
if(this._olderWxMap.get(userId)){
|
|
|
this._olderWxMap.delete(userId);
|
|
|
}
|
|
|
}
|
|
|
if("olderPad" == type){
|
|
|
this._olderPad = this._olderPad-1;
|
|
|
if(this._olderPadMap.get(userId)){
|
|
|
this._olderPadMap.delete(userId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|