/** * 搜索功能。 */ "use strict"; let ImDb = require('../mysql/db/im.db'); let log = require('../../util/log.js'); const IMTABLE = require('../../include/commons').IM_DB; class ParticipantRepo { constructor() { } /** * 获取某个会话中的成员信息 * @param sessionId * @param handler */ static getParticipantsBySessionId(sessionId,handler){ let sql ="select w.* from participants w where w.session_id =? "; ImDb.execQuery({ "sql": sql, "args": [sessionId], "handler": function (err, res) { if(err) { log.error("getParticipantsBySessionId is fail error: "+err); } handler(res); } }); } /** * 判断用户是否存在session中 * @param sessionId * @param userId * @param handler */ static existsUser(sessionId,userId,handler){ let sql ="select count(1) as count from participants w where w.session_id =? and w.participaint_id = ? "; ImDb.execQuery({ "sql": sql, "args": [sessionId,userId], "handler": function (err, res) { if(err) { log.error("existsUser is fail error: "+err); } handler(res[0].count); } }); } /** * 根据医生和患者 * @param patient * @param doctor */ static getSessionIdByParticipants(patient,doctor,handler){ let sql ="select session_id from "+IMTABLE.PARTICIPANTS+" p1 ,participants p2 " + "where p1.session_id = p2.session_id and " + "((p1.participaint_id = ? and p2.participaint_id = ?) or (p1.participaint_id = ? and p2.participaint_id = ?))" ImDb.execQuery({ "sql": sql, "args": [patient,doctor,doctor,patient], "handler": function (err, res) { if(err) { log.error("getSessionIdByParticipants is fail error: "+err); } handler(err,res); } }); } /** * mysql成员创建 * @param users */ createParticipantsToMysql(session_id,users){ let sql="insert into "+IMTABLE.PARTICIPANTS +" (session_id,participaint_id,participaint_role,receiving) VALUES " let args=[]; for(var j in users){ sql+="(?,?,?,?),"; args.push(session_id); args.push(users[j]); args.push(0); args.push(0); } sql = sql.substring(0,sql.lastIndexOf(",")); ImDb.execQuery({ "sql": sql, "args": args, "handler": function (err, res) { if(err) { log.error("createParticipantsForMysql is fail error: "+err+",session_id:"+session_id+",users:"+users.join(",")); }else{ return res; } } }); return true; } } module.exports = ParticipantRepo;