| 
					
				 | 
			
			
				@ -41,12 +41,12 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userTable 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchAll(sessionIdList, keyword, userTable, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchAll(sessionIdList,userId, keyword, userTable, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let data = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        async.waterfall([ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            function (callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchUser(sessionIdList, keyword, userTable, 0, 3, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchUser(sessionIdList,userId, keyword, userTable, 0, 4, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (err) return handler(err, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    let buffer = SearchRepo.userForge(res); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -56,7 +56,7 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            function (callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchSessions(sessionIdList, keyword, 0, 3, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchSessions(sessionIdList,userId, keyword, 0, 4, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (err) return handler(err, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.sessions = SearchRepo.sessionForge(res, keyword); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -65,7 +65,7 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            function (callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchMessages(sessionIdList, keyword, 0, 3, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                SearchRepo.searchMessages(sessionIdList,userId, keyword, 0, 4, function (err, res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (err) return handler(err, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.messages = SearchRepo.messageForge(res); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -86,22 +86,23 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchUser(sessionIdList, keyword, userTable, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let sql = "SELECT DISTINCT s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id, u.name user_name, u.sex, u.birthdate, u.avatar %s" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            " FROM sessions s, participants p, " + userTable + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            " u WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id AND u.name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchUser(sessionIdList,userId, keyword, userTable, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let sql = "SELECT DISTINCT u.name user_name,s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id,u.sex, u.birthdate, u.avatar %s " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            " FROM  participants p, " + userTable + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            " u,sessions s WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND u.name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (userTable === DB_TABLES.Doctors) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " AND s.type in (2,3) "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " AND s.type in (2) "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " AND s.type in (1,2) "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql += " limit ?, ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql = vsprintf(sql, [userTable == DB_TABLES.Doctors ? ', hospital_name' : '']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        keyword = '%' + keyword + '%'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ImDb.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql: sql, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            args: [sessionIdList, keyword, page * size, size], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            args: [sessionIdList,userId, keyword, page * size, size], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            handler: handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -109,25 +110,21 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 会话搜索。搜索会话名称与会话成员的名称。若有一个符合,就选中。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchSessions(sessionIdList, keyword, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (sessionIdList.length == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchSessions(sessionIdList,userId, keyword, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          if (sessionIdList.length == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return handler(null, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let sql = "SELECT * FROM(" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "SELECT s.id, s.name, s.type, s.create_date, s.business_type, u.name participant_name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "FROM sessions s, participants p, doctors u " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "WHERE s.id IN (?) AND s.id = p.session_id AND p.participant_id = u.id AND (s.name LIKE ? or u.name like ?) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            " UNION " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "SELECT s.id, s.name, s.type, s.create_date, s.business_type, u.name participant_name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "FROM sessions s, participants p, patients u " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "WHERE s.id IN (?) AND s.id = p.session_id AND p.participant_id = u.id AND (s.name LIKE ? or u.name like ?) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "SELECT s.id, s.name, s.type, s.create_date, s.business_type,GROUP_CONCAT(u. NAME) as participant_name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "FROM sessions s,  doctors u ,participants p " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "WHERE s.id IN (?) and s.type = 3 AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or s.name like ?) group by s.id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ") X LIMIT ?, ?"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        keyword = '%' + keyword + '%'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ImDb.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql: sql, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            args: [sessionIdList, keyword, keyword, sessionIdList, keyword, keyword, page * size, size], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            args: [sessionIdList,userId, keyword,keyword, page * size, size], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            handler: handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -135,7 +132,7 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 消息搜索 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchMessages(sessionIdList, keyword, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static searchMessages(sessionIdList,userId, keyword, page, size, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let sql = "SELECT * FROM(" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "SELECT s.id session_id, s.name session_name, s.type session_type, s.business_type session_business_type, m.id message_id, m.sender_id, m.sender_name, m.timestamp, m.content " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "FROM sessions s, muc_messages m " + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -174,21 +171,21 @@ class SearchRepo { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let lastSessionId = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        let tempSession = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.forEach(function (session) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (session.session_id !== lastSessionId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                lastSessionId = session.session_id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (session.id !== lastSessionId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                lastSessionId = session.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                tempSession = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    id: session.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    name: session.name, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    type: session.type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    business_type: session.business_type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    /*create_date: ObjectUtil.timestampToLong(session.create_date),*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    participants: [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    members: [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.push(tempSession); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (session.participant_name.indexOf(keyword) >= 0) tempSession.participants.push({name: session.participant_name}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (session.participant_name.indexOf(keyword) >= 0) tempSession.members.push({name: session.participant_name}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 |