|  | @ -50,16 +50,16 @@ class SearchRepo {
 | 
	
		
			
				|  |  |                     if (err) return handler(err, null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     let buffer = SearchRepo.userForge(res);
 | 
	
		
			
				|  |  |                     userTable == DB_TABLES.Doctors ? data.doctors = buffer : data.patients = buffer;
 | 
	
		
			
				|  |  |                     data.users = buffer;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     callback(null);
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  |             },
 | 
	
		
			
				|  |  |             function (callback) {
 | 
	
		
			
				|  |  |                 SearchRepo.searchSessions(sessionIdList, keyword, userTable, 0, 3, function (err, res) {
 | 
	
		
			
				|  |  |                 SearchRepo.searchSessions(sessionIdList, keyword, 0, 3, function (err, res) {
 | 
	
		
			
				|  |  |                     if (err) return handler(err, null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     data.sessions = SearchRepo.sessionForge(res);
 | 
	
		
			
				|  |  |                     data.sessions = SearchRepo.sessionForge(res, keyword);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     callback(null);
 | 
	
		
			
				|  |  |                 })
 | 
	
	
		
			
				|  | @ -103,20 +103,25 @@ class SearchRepo {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 会话搜索。搜索会话名称与会话成员的名称。若有一个符合,就选中。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     static searchSessions(sessionIdList, keyword, userTable, page, size, handler) {
 | 
	
		
			
				|  |  |     static searchSessions(sessionIdList, keyword, page, size, handler) {
 | 
	
		
			
				|  |  |         if (sessionIdList.length == 0) {
 | 
	
		
			
				|  |  |             return handler(null, []);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         let sql = "SELECT s.id, s.name, s.type, s.create_date, s.business_type, u.name participant_name " +
 | 
	
		
			
				|  |  |             "FROM sessions s, participants p, " + userTable + " u " +
 | 
	
		
			
				|  |  |         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 ?) " +
 | 
	
		
			
				|  |  |             "GROUP by s.id LIMIT ?, ?";
 | 
	
		
			
				|  |  |             ") X LIMIT ?, ?";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         keyword = '%' + keyword + '%';
 | 
	
		
			
				|  |  |         ImDb.execQuery({
 | 
	
		
			
				|  |  |             sql: sql,
 | 
	
		
			
				|  |  |             args: [sessionIdList, keyword, keyword, page * size, size],
 | 
	
		
			
				|  |  |             args: [sessionIdList, keyword, keyword, sessionIdList, keyword, keyword, page * size, size],
 | 
	
		
			
				|  |  |             handler: handler
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -157,12 +162,30 @@ class SearchRepo {
 | 
	
		
			
				|  |  |         return res;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     static sessionForge(res) {
 | 
	
		
			
				|  |  |     static sessionForge(res, keyword) {
 | 
	
		
			
				|  |  |         let result = [];
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         let lastSessionId = null;
 | 
	
		
			
				|  |  |         let tempSession = null;
 | 
	
		
			
				|  |  |         res.forEach(function (session) {
 | 
	
		
			
				|  |  |             session.create_date = ObjectUtil.timestampToLong(session.timestamp);
 | 
	
		
			
				|  |  |             if (session.session_id !== lastSessionId) {
 | 
	
		
			
				|  |  |                 lastSessionId = session.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: []
 | 
	
		
			
				|  |  |                 };
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 result.push(tempSession);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if(session.participant_name.indexOf(keyword) >= 0) tempSession.participants.push({name: session.participant_name});
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return res;
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     static messageForge(res) {
 | 
	
	
		
			
				|  | @ -177,7 +200,7 @@ class SearchRepo {
 | 
	
		
			
				|  |  |                     session_id: message.session_id,
 | 
	
		
			
				|  |  |                     session_name: message.session_name,
 | 
	
		
			
				|  |  |                     session_type: message.session_type,
 | 
	
		
			
				|  |  |                     session_business_type: message.session_business_type,
 | 
	
		
			
				|  |  |                     /*session_business_type: message.session_business_type,*/
 | 
	
		
			
				|  |  |                     messages: []
 | 
	
		
			
				|  |  |                 };
 | 
	
		
			
				|  |  | 
 |