|
@ -1952,6 +1952,131 @@ class Sessions extends RedisModel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取所有会话的未读消息数。
|
|
|
*/
|
|
|
getAllSessionsUnreadMessageCountByStatus(userId,businessType,status,handler) {
|
|
|
let self = this;
|
|
|
let count = 0;
|
|
|
let patientCount = 0;
|
|
|
let doctorCount = 0;
|
|
|
let patientEndCount = 0;
|
|
|
SessionRepo.findAllByTypeAndStatusAndNoPage(userId,businessType, status,function (err, res) {
|
|
|
// SessionRepo.findUnEndAll(userId, function (err, res) {
|
|
|
if (err) {
|
|
|
if (handler) {
|
|
|
handler(err, res);
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (res && res.length == 0) {
|
|
|
if (handler) {
|
|
|
handler(err, count);
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.emitOK(self.eventEmitter, {count: count});
|
|
|
return;
|
|
|
}
|
|
|
/*let has = false;*/
|
|
|
for (let j in res) {
|
|
|
/* has = false;
|
|
|
//是否过滤指定类型
|
|
|
if( type != null){
|
|
|
let typeString = type.split(",");
|
|
|
var str = res[j].type;
|
|
|
var str1 = str.toString();
|
|
|
if(typeString.indexOf(str1)<0){
|
|
|
continue;
|
|
|
}
|
|
|
}*/
|
|
|
//logger.info("type==="+res[j].type);
|
|
|
if (res[j].type == SESSION_TYPES.SYSTEM) {
|
|
|
|
|
|
if (j == res.length - 1) {
|
|
|
if (handler) {
|
|
|
handler(err, count);
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount, doctor: doctorCount});
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
callback(res, j, res[j]);
|
|
|
/* has = true*/
|
|
|
}
|
|
|
/* if(!has){
|
|
|
ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: 0, doctor: doctorCount});
|
|
|
}*/
|
|
|
});
|
|
|
|
|
|
/*function callback(res, j, session) {
|
|
|
self.getSessionUnreadMessageCount(res[j].id, userId, function (err, con) {
|
|
|
if (err) {
|
|
|
if(handler)
|
|
|
{
|
|
|
handler(err,count);
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
|
|
|
}
|
|
|
|
|
|
count = count + con;
|
|
|
if (session.business_type == SESSION_BUSINESS_TYPE.PATIENT) {
|
|
|
if(session.status == SESSION_STATUS.ENDED){//新增判断是否咨询结束
|
|
|
patientEndCount = patientEndCount + con;
|
|
|
}else{
|
|
|
patientCount = patientCount + con;
|
|
|
}
|
|
|
} else {
|
|
|
doctorCount = doctorCount + con;
|
|
|
}
|
|
|
if (j == res.length - 1) {
|
|
|
if(handler)
|
|
|
{
|
|
|
handler(err,count)
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: patientEndCount, doctor: doctorCount});
|
|
|
}
|
|
|
})
|
|
|
}*/
|
|
|
function callback(res, j, session) {
|
|
|
self.getSessionUnreadMessageCount(res[j].id, userId, function (err, con) {
|
|
|
if (err) {
|
|
|
if(handler)
|
|
|
{
|
|
|
handler(err,count);
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
|
|
|
}
|
|
|
|
|
|
count = count + con;
|
|
|
if (session.business_type == SESSION_BUSINESS_TYPE.PATIENT) {
|
|
|
if(session.status == SESSION_STATUS.ENDED){//新增判断是否咨询结束
|
|
|
patientEndCount = patientEndCount + con;
|
|
|
}else{
|
|
|
patientCount = patientCount + con;
|
|
|
}
|
|
|
} else {
|
|
|
doctorCount = doctorCount + con;
|
|
|
}
|
|
|
if (j == res.length - 1) {
|
|
|
if(handler)
|
|
|
{
|
|
|
handler(err,count)
|
|
|
return;
|
|
|
}
|
|
|
ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: patientEndCount, doctor: doctorCount});
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取会话的未读消息数。根据成员最后一次获取消息的时候与当前时间。
|
|
|
*
|