| 
															
																@ -21,11 +21,12 @@ let redis = RedisClient.redisClient().connection; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let logger = require('../../util/log.js'); 
															 | 
															
															 | 
															
																let logger = require('../../util/log.js'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let mongoose = require('mongoose'); 
															 | 
															
															 | 
															
																let mongoose = require('mongoose'); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																let async = require("async"); 
															 | 
															
															 | 
															
																let async = require("async"); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																var log = require("../../util/log.js"); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																let log = require("../../util/log.js"); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																const REDIS_KEYS = require('../../include/commons').REDIS_KEYS; 
															 | 
															
															 | 
															
																const REDIS_KEYS = require('../../include/commons').REDIS_KEYS; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																const SESSION_TYPES = require('../../include/commons').SESSION_TYPES; 
															 | 
															
															 | 
															
																const SESSION_TYPES = require('../../include/commons').SESSION_TYPES; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																const STICKY_SESSION_BASE_SCORE = require('../../include/commons').STICKY_SESSION_BASE_SCORE; 
															 | 
															
															 | 
															
																const STICKY_SESSION_BASE_SCORE = require('../../include/commons').STICKY_SESSION_BASE_SCORE; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																const PARTICIPANT_ROLES = require('../../include/commons').PARTICIPANT_ROLES; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																class Sessions extends RedisModel { 
															 | 
															
															 | 
															
																class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																    constructor() { 
															 | 
															
															 | 
															
																    constructor() { 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -132,7 +133,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                timestamp: createDate, 
															 | 
															
															 | 
															
																                timestamp: createDate, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                id: messageId 
															 | 
															
															 | 
															
																                id: messageId 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            }; 
															 | 
															
															 | 
															
																            }; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            if(type == SESSION_TYPES.MUC){ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																            if (type == SESSION_TYPES.MUC) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                businessType = 2; 
															 | 
															
															 | 
															
																                businessType = 2; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            } 
															 | 
															
															 | 
															
																            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            let session = { 
															 | 
															
															 | 
															
																            let session = { 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -202,7 +203,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            //查找该sessionId是否存在存在则直接返回实例 
															 | 
															
															 | 
															
																            //查找该sessionId是否存在存在则直接返回实例 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            SessionRepo.findOne(sessionId, function (err, res) { 
															 | 
															
															 | 
															
																            SessionRepo.findOne(sessionId, function (err, res) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (res.length > 0) {//已经存在 
															 | 
															
															 | 
															
																                if (res.length > 0) {//已经存在 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                     //更新成员 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    //更新成员 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    Participants.saveParticipantsToMysql(sessionId, participantArray, function (err, update) { 
															 | 
															
															 | 
															
																                    Participants.saveParticipantsToMysql(sessionId, participantArray, function (err, update) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        handler(null, res[0]); 
															 | 
															
															 | 
															
																                        handler(null, res[0]); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        return; 
															 | 
															
															 | 
															
																                        return; 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -236,7 +237,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (err) { 
															 | 
															
															 | 
															
																                if (err) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    handler(err, null); 
															 | 
															
															 | 
															
																                    handler(err, null); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    return; 
															 | 
															
															 | 
															
																                    return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }else{ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                } else { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    handler(null, session); 
															 | 
															
															 | 
															
																                    handler(null, session); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    return; 
															 | 
															
															 | 
															
																                    return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																                } 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -385,12 +386,12 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                sessionName = res[0].name; 
															 | 
															
															 | 
															
																                                                sessionName = res[0].name; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            } 
															 | 
															
															 | 
															
																                                            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            var bir = new Date().getTime(); 
															 | 
															
															 | 
															
																                                            var bir = new Date().getTime(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            if(res.length!=0&&res[0].birthdate){ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                            if (res.length != 0 && res[0].birthdate) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                bir = res[0].birthdate.getTime(); 
															 | 
															
															 | 
															
																                                                bir = res[0].birthdate.getTime(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            } 
															 | 
															
															 | 
															
																                                            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            var sex = 1; 
															 | 
															
															 | 
															
																                                            var sex = 1; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            if(res.length!=0&&res[0].sex){ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                sex =   res[0].sex; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                            if (res.length != 0 && res[0].sex) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                                sex = res[0].sex; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            } 
															 | 
															
															 | 
															
																                                            } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            sessionList.push({ 
															 | 
															
															 | 
															
																                                            sessionList.push({ 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -405,8 +406,8 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                unread_count: count, 
															 | 
															
															 | 
															
																                                                unread_count: count, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                business_type: session.business_type, 
															 | 
															
															 | 
															
																                                                business_type: session.business_type, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                my_role: role, 
															 | 
															
															 | 
															
																                                                my_role: role, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                sender_sex:sex, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                                sender_birthday:bir, 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                                sender_sex: sex, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                                sender_birthday: bir, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            }); 
															 | 
															
															 | 
															
																                                            }); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                            index = (parseInt(index) + 1); 
															 | 
															
															 | 
															
																                                            index = (parseInt(index) + 1); 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -591,7 +592,7 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        let startMsgScore = res[1]; 
															 | 
															
															 | 
															
																                        let startMsgScore = res[1]; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        let endMsgScore = res[0]; 
															 | 
															
															 | 
															
																                        let endMsgScore = res[0]; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        if (startMsgScore == null || endMsgScore == null || (startMsgScore == endMsgScore&&isoffset==1)) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                        if (startMsgScore == null || endMsgScore == null || (startMsgScore == endMsgScore && isoffset == 1)) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            handler(null, []); 
															 | 
															
															 | 
															
																                            handler(null, []); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            return; 
															 | 
															
															 | 
															
																                            return; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        } 
															 | 
															
															 | 
															
																                        } 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -657,13 +658,13 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																                } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                count = count + con; 
															 | 
															
															 | 
															
																                count = count + con; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if(session.type ==2){ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    patientCount = patientCount+con; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                }else{ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    doctorCount = doctorCount+con; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                if (session.type == 2) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    patientCount = patientCount + con; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                } else { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    doctorCount = doctorCount + con; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																                } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                if (j == res.length - 1) { 
															 | 
															
															 | 
															
																                if (j == res.length - 1) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                    ModelUtil.emitOK(self.eventEmitter, {count: count,patient:patientCount,doctor:doctorCount}); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                    ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount, doctor: doctorCount}); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                } 
															 | 
															
															 | 
															
																                } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																            }) 
															 | 
															
															 | 
															
																            }) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																        } 
															 | 
															
															 | 
															
																        } 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@ -819,11 +820,9 @@ class Sessions extends RedisModel { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                        } else { 
															 | 
															
															 | 
															
																                        } else { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            message.session_id = sessionId; 
															 | 
															
															 | 
															
																                            message.session_id = sessionId; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            log.info("Candidate to push: " + participants); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            res.forEach(function (participant) { 
															 | 
															
															 | 
															
																                            res.forEach(function (participant) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                if (participant.id !== message.sender_id) { 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    log.warn('Push message to ' + participant.id); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                if (participant.id !== message.sender_id && 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																                                    participant.participant_role == PARTICIPANT_ROLES.HOST) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    Sessions.pushNotification(participant.id, message); 
															 | 
															
															 | 
															
																                                    Sessions.pushNotification(participant.id, message); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                } 
															 | 
															
															 | 
															
																                                } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            }); 
															 | 
															
															 | 
															
																                            }); 
															 |