|  | @ -17,6 +17,7 @@ let config = require('../../resources/config/' + configFile);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | const REDIS_KEYS = require('../../include/commons').REDIS_KEYS;
 | 
	
		
			
				|  |  | const SESSION_USER_STATUS = require('../../include/commons').SESSION_USER_STATUS;
 | 
	
		
			
				|  |  | const SESSION_TYPES = require('../../include/commons').SESSION_TYPES;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | class Topics extends RedisModel {
 | 
	
		
			
				|  |  |     constructor() {
 | 
	
	
		
			
				|  | @ -29,7 +30,7 @@ class Topics extends RedisModel {
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param size
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     getTopicMessages(topicId, page, size) {
 | 
	
		
			
				|  |  |     getTopicMessages(topicId) {
 | 
	
		
			
				|  |  |         let self = this;
 | 
	
		
			
				|  |  |         let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
 | 
	
		
			
				|  |  |         let _super = RedisModel.makeRedisKey;
 | 
	
	
		
			
				|  | @ -57,35 +58,35 @@ class Topics extends RedisModel {
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param topicName 发起议题的名称
 | 
	
		
			
				|  |  |      * @param topicId
 | 
	
		
			
				|  |  |      * @param patient 发起议题的患者
 | 
	
		
			
				|  |  |      * @param healthDoctor
 | 
	
		
			
				|  |  |      * @param doctor 参与的医生
 | 
	
		
			
				|  |  |      * @param users 发起议题的患者{"userId1:role", "userId2:role"}
 | 
	
		
			
				|  |  |      * @param messages 发送的消息对象{description:"",title:"",img:"",patient:"",patientName:""}图片多个用逗号隔开
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     createTopics(topicName, topicId, patient, healthDoctor, doctor, messages) {
 | 
	
		
			
				|  |  |     createTopics(topicName, topicId,sessionId,users, messages) {
 | 
	
		
			
				|  |  |         let self = this;
 | 
	
		
			
				|  |  |         
 | 
	
		
			
				|  |  |         //MUC模式中sessionID就是患者ID
 | 
	
		
			
				|  |  |         let topics_key = RedisModel.makeRedisKey(REDIS_KEYS.Topics, patient);
 | 
	
		
			
				|  |  |         let topics_key = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
 | 
	
		
			
				|  |  |         let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
 | 
	
		
			
				|  |  |         let sessions = new Sessions();
 | 
	
		
			
				|  |  |         let participants = new Participants();
 | 
	
		
			
				|  |  |         
 | 
	
		
			
				|  |  |         //从数据库中获取sessionId
 | 
	
		
			
				|  |  |         let date = new Date();
 | 
	
		
			
				|  |  |         var pars=[];
 | 
	
		
			
				|  |  |         redis.zaddAsync(topics_key, date.getTime(), topicId).then(function (res) {
 | 
	
		
			
				|  |  |             redis.hmsetAsync(topic_key, "name", topicName, "end_by", "", "session_id", patient, "create_time", date.getTime(), "end_time", "", "description", messages.description).then(function (res) {
 | 
	
		
			
				|  |  |                 sessions.getSessions(patient, function (err, res) {
 | 
	
		
			
				|  |  |             redis.hmsetAsync(topic_key, "name", topicName, "end_by", "", "session_id", sessionId, "create_time", date.getTime(), "end_time", "", "description", messages.description).then(function (res) {
 | 
	
		
			
				|  |  |                 sessions.getSessions(sessionId, function (err, res) {
 | 
	
		
			
				|  |  |                     //已经存在对应的会话更新全科为旁听
 | 
	
		
			
				|  |  |                     if (res && res.length > 0) {
 | 
	
		
			
				|  |  |                         participants.updateUser(patient, doctor, SESSION_USER_STATUS.OTHER);
 | 
	
		
			
				|  |  |                         for(var j in users){
 | 
	
		
			
				|  |  |                            participants.updateUser(sessionId, j, users[j]);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         callbegin();
 | 
	
		
			
				|  |  |                     } else {//不存在创建SESSION
 | 
	
		
			
				|  |  |                         var users = {};
 | 
	
		
			
				|  |  |                         users[patient] = SESSION_USER_STATUS.ONLINE;
 | 
	
		
			
				|  |  |                         users[healthDoctor] = SESSION_USER_STATUS.ONLINE;
 | 
	
		
			
				|  |  |                         users[doctor] = SESSION_USER_STATUS.OTHER;
 | 
	
		
			
				|  |  |                         sessions.createSession(patient, messages.patientName, config.sessionConfig.MUC, JSON.stringify(users), function (res) {
 | 
	
		
			
				|  |  |                         for(var j in users){
 | 
	
		
			
				|  |  |                             pars.push(j+":"+users[j]);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         sessions.createSession(sessionId, messages.patientName, SESSION_TYPES.MUC, pars, function (res) {
 | 
	
		
			
				|  |  |                             if (res) {
 | 
	
		
			
				|  |  |                                 callbegin();
 | 
	
		
			
				|  |  |                             }
 | 
	
	
		
			
				|  | @ -100,17 +101,17 @@ class Topics extends RedisModel {
 | 
	
		
			
				|  |  |          */
 | 
	
		
			
				|  |  |         function callbegin() {
 | 
	
		
			
				|  |  |             let msg = {};
 | 
	
		
			
				|  |  |             msg.senderId = messages.patient;
 | 
	
		
			
				|  |  |             msg.senderName = messages.patientName;
 | 
	
		
			
				|  |  |             msg.contentType = 6;
 | 
	
		
			
				|  |  |             msg.sender_id = messages.patient;
 | 
	
		
			
				|  |  |             msg.sender_name = messages.patientName;
 | 
	
		
			
				|  |  |             msg.content_type = 6;
 | 
	
		
			
				|  |  |             msg.content = "开始咨询"
 | 
	
		
			
				|  |  |             msg.timestamp = date;
 | 
	
		
			
				|  |  |             sessions.saveMessageByTopic(msg, patient, function (err, msgId) {
 | 
	
		
			
				|  |  |             sessions.saveMessageByTopic(msg, sessionId, function (err, msgId) {
 | 
	
		
			
				|  |  |                 if (err) {
 | 
	
		
			
				|  |  |                     ModelUtil.emitOK(self.eventEmitter, err);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     self.saveTopicsToSql(topicName, topicId, patient, msgId, date);
 | 
	
		
			
				|  |  |                     callBeginMsg();
 | 
	
		
			
				|  |  |                     self.saveTopicsToSql(topicName, topicId, sessionId, msgId, date);
 | 
	
		
			
				|  |  |                     callBeginMsg(msgId);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             })
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -118,14 +119,14 @@ class Topics extends RedisModel {
 | 
	
		
			
				|  |  |         /**
 | 
	
		
			
				|  |  |          * 发送求助内容
 | 
	
		
			
				|  |  |          */
 | 
	
		
			
				|  |  |         function callBeginMsg() {
 | 
	
		
			
				|  |  |         function callBeginMsg(startMsgId) {
 | 
	
		
			
				|  |  |             let msg = {};
 | 
	
		
			
				|  |  |             msg.senderId = messages.patient;
 | 
	
		
			
				|  |  |             msg.senderName = messages.patientName;
 | 
	
		
			
				|  |  |             msg.contentType = 1;
 | 
	
		
			
				|  |  |             msg.sender_id = messages.patient;
 | 
	
		
			
				|  |  |             msg.sender_name = messages.patientName;
 | 
	
		
			
				|  |  |             msg.content_type = 1;
 | 
	
		
			
				|  |  |             msg.content = messages.description;
 | 
	
		
			
				|  |  |             msg.timestamp = new Date();
 | 
	
		
			
				|  |  |             sessions.saveMessageByTopic(msg, patient, function (err, msgId) {
 | 
	
		
			
				|  |  |             sessions.saveMessageByTopic(msg,  sessionId, function (err, msgId) {
 | 
	
		
			
				|  |  |                 log.info("begin send" + messages.description);
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |             
 | 
	
	
		
			
				|  | @ -133,17 +134,17 @@ class Topics extends RedisModel {
 | 
	
		
			
				|  |  |                 let imgs = messages.img.split(",");
 | 
	
		
			
				|  |  |                 for (var j in imgs) {
 | 
	
		
			
				|  |  |                     let msgimg = {};
 | 
	
		
			
				|  |  |                     msgimg.senderId = messages.patient;
 | 
	
		
			
				|  |  |                     msgimg.senderName = messages.patientName;
 | 
	
		
			
				|  |  |                     msgimg.contentType = 2;
 | 
	
		
			
				|  |  |                     msgimg.sender_id = messages.patient;
 | 
	
		
			
				|  |  |                     msgimg.sender_name = messages.patientName;
 | 
	
		
			
				|  |  |                     msgimg.content_type = 2;
 | 
	
		
			
				|  |  |                     msgimg.content = imgs[j];
 | 
	
		
			
				|  |  |                     msgimg.timestamp = new Date();
 | 
	
		
			
				|  |  |                     sessions.saveMessageByTopic(msgimg, patient, function (err, msgId) {
 | 
	
		
			
				|  |  |                     sessions.saveMessageByTopic(msgimg, sessionId, function (err, msgId) {
 | 
	
		
			
				|  |  |                         log.info("begin send" + imgs[j]);
 | 
	
		
			
				|  |  |                     })
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             ModelUtil.emitOK(self.eventEmitter, "创建成功!");
 | 
	
		
			
				|  |  |             ModelUtil.emitOK(self.eventEmitter, startMsgId);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 |