Explorar el Código

查询接口修改

hace 7 años
padre
commit
4e04036ddd
Se han modificado 2 ficheros con 20 adiciones y 30 borrados
  1. 6 13
      src/server/models/sessions/sessions.js
  2. 14 17
      src/server/models/sessions/topics.js

+ 6 - 13
src/server/models/sessions/sessions.js

@ -1075,10 +1075,11 @@ class Sessions extends RedisModel {
                        ModelUtil.emitError(self.eventEmitter, "Session " + sessionId + " is not found.");
                        return;
                    }
                    if(sessionType == SESSION_TYPES.MUC&&(message.content_type == CONTENT_TYPES.PlainText ||
                                                            message.content_type == CONTENT_TYPES.Image ||
                                                            message.content_type == CONTENT_TYPES.Audio||
                                                            message.content_type == CONTENT_TYPES.Video)){
                    if(sessionType == SESSION_TYPES.MUC){
                        if(message.content_type == CONTENT_TYPES.PlainText ||
                           message.content_type == CONTENT_TYPES.Image ||
                           message.content_type == CONTENT_TYPES.Audio||
                           message.content_type == CONTENT_TYPES.Video){
                            TopicRepo.findLastBySessionId(sessionId,function(err,res){
                                if(res&&res.length>0&&res[0].reply==0){
                                    TopicRepo.updateTopics(res[0].id,{reply:1,reply_time:message.timestamp,reply_user:message.sender_id,reply_message_id:message.id},function(err,res){
@ -1090,12 +1091,12 @@ class Sessions extends RedisModel {
                                    });
                                }
                            })
                        }
                    }
                    // 消息保存到Redis,并更新会话最后状态、用户最后消息获取时间
                    messages.saveMessageToRedis(sessionId, sessionType, messageId, message);
                    Messages.updateLastContent(sessionKey, sessionType, sessionName, message);
                    Sessions.updateParticipantLastFetchTime(sessionId, message.sender_id, message.timestamp.getTime());
                    // 更新MYSQL中会话的最新状态,并保存消息
                    SessionRepo.updateSessionLastStatus(message.sender_id, message.sender_name, message.timestamp, message.content, message.content_type, sessionId);
                    messages.saveMessageToMysql(sessionId, sessionType, messageId, message, function (err, res) {
@ -1116,14 +1117,6 @@ class Sessions extends RedisModel {
                            res.forEach(function (participant) {
                                if (participant.id == message.sender_id||sessionType==SESSION_TYPES.SYSTEM){
                                    message.sender_img = participant.avatar;
                                    // if(participant.participant_role == PARTICIPANT_ROLES.REGULAR){
                                    //     if (message.content_type == CONTENT_TYPES.PlainText ||
                                    //         message.content_type == CONTENT_TYPES.Image ||
                                    //         message.content_type == CONTENT_TYPES.Audio||
                                    //         message.content_type == CONTENT_TYPES.Video){
                                    //              participants.updateUser(sessionId,message.sender_id,PARTICIPANT_ROLES.HOST);
                                    //     }
                                    // }
                                    callPush(res,message);
                                }
                            })

+ 14 - 17
src/server/models/sessions/topics.js

@ -196,21 +196,19 @@ class Topics extends RedisModel {
            pars.push(j + ":" + users[j]);
        }
        let sessions = new Sessions();
        let date = new Date();
        sessions.createSession(sessionId, messages.sender_name, sessionType, pars, function (err, session) {
            sessionId = session.id;
            self.saveTopicToRedis(topicName, topicId, sessionId, messages, date, function (err, startMsgId) {
            let datetime  = session.create_date;
            self.saveTopicToRedis(topicName, topicId, sessionId, messages, datetime, function (err, startMsgId) {
                if (err) {
                    ModelUtil.emitOK(self.eventEmitter, {status: -1, message: "议题创建失败!"});
                    return;
                }
                //返回给前端
                ModelUtil.emitOK(self.eventEmitter, {status: 200, message: "议题创建成功!", start_msg_id: startMsgId});
                sessions.updateSessionStatus(sessionId,SESSION_STATUS.PROCEEDINGS,function(err,res){
                });
                sessions.updateSessionStatus(sessionId,SESSION_STATUS.PROCEEDINGS,function(err,res){});
                //执行数据库操作
                self.saveTopicToMySQL(topicName, topicId, sessionId, startMsgId, date, messages.description, TOPIC_STATUS.NEW, function (err, res) {
                self.saveTopicToMySQL(topicName, topicId, sessionId, startMsgId,  new Date(datetime), messages.description, TOPIC_STATUS.NEW, function (err, res) {
                    if (err) {
                        ModelUtil.logError("Save topic to mysql failed", err);
                    }
@ -220,15 +218,14 @@ class Topics extends RedisModel {
    }
    saveTopicToRedis(topicName, topicId, sessionId, messages, date, handler) {
    saveTopicToRedis(topicName, topicId, sessionId, messages, datetime, handler) {
        let topics_key = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
        let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
        let sessions = new Sessions();
        //step1:创建topic到redis
        redis.zaddAsync(topics_key, date.getTime(), topicId).then(function (res) {
        redis.zaddAsync(topics_key, datetime, topicId).then(function (res) {
            redis.hmsetAsync(topic_key, "name", topicName,
                "session_id", sessionId, "create_time", date.getTime(),
                "session_id", sessionId, "create_time", datetime,
                "description", messages.description, "status", TOPIC_STATUS.NEW,
                "end_time", "", "end_by", ""
            ).then(function (res) {
@ -249,29 +246,29 @@ class Topics extends RedisModel {
            msg.sender_name = "系统";//messages.sender_name;发起和结束咨询的消息由系统发出,发送者ID记录操作人!
            msg.content_type = 10;
            msg.content = messages.sender_name + "发起了咨询";
            msg.timestamp = date;
            msg.timestamp = new Date(datetime);
            sessions.saveMessageByTopic(msg, sessionId, function (err, msgId) {
                if (err) {
                    handler(err, null);
                } else {
                    sendQuesionMsg(msgId);
                    sendQuesionMsg();
                    handler(null, msgId);
                }
            })
        }
        //step3:发送求助内容的文本
        function sendQuesionMsg(startMsgId) {
        function sendQuesionMsg() {
            let msg = {};
            msg.sender_id = messages.sender_id;
            msg.sender_name = messages.sender_name;
            msg.content_type = 6;
            msg.content = messages.description;
            msg.timestamp = new Date();
            msg.timestamp = new Date(datetime+200);
            sessions.saveMessageByTopic(msg, sessionId, function (err, msgId) {
                if (messages.img) {
                    setTimeout(function(){
                        sendQuesionImg(startMsgId);
                        sendQuesionImg();
                    },100);
                }
                if (err) {
@ -280,7 +277,7 @@ class Topics extends RedisModel {
            });
        }
        //step4:发送求助内容的图片
        function sendQuesionImg(startMsgId) {
        function sendQuesionImg() {
            let imgs = messages.img.split(",");
            for (var j in imgs) {
                let msgimg = {};
@ -288,7 +285,7 @@ class Topics extends RedisModel {
                msgimg.sender_name = messages.sender_name;
                msgimg.content_type = 2;
                msgimg.content = imgs[j];
                msgimg.timestamp = new Date();
                msgimg.timestamp = new Date(datetime+(200*j));
                sessions.saveMessageByTopic(msgimg, sessionId, function (err, msgId) {
                    if (err) {
                        log.info("send create img error " + imgs[j]);