LAPTOP-KB9HII50\70708 hai 1 ano
pai
achega
ab597d2304

+ 14 - 0
src/server/endpoints/v2/session.endpoint.js

@ -269,6 +269,20 @@ router.post(APIv2.Sessions.SessionName, function (req, res) {
    sessions.updateSessionName(sessionId, name);
});
/**
 * 把会话写入redis
 *
 * 请求URL /fixSessionToRedis?sessionId=testsessionmsg1
 */
router.get(APIv2.Sessions.FixSessionToRedis, function (req, res) {
    let sessionId = req.query.sessionId;
    if (!sessionId) {
        throw {httpStatus: 406, message: 'Missing sessionId.'};
    }
    let sessions = new Sessions();
    ControllerUtil.regModelEventHandler(sessions, res);
    sessions.fixSessionToRedis(sessionId);
});
/**
 * 取消置顶

+ 1 - 0
src/server/include/endpoints.js

@ -41,6 +41,7 @@ const APIv2 = {
        SessionSticky: '/:session_id/sticky',                           // 会话置顶,置顶使用PUT,取消置顶使用DELETE
        SessionStatus: '/:session_id/status',                           // 更新状态
        SessionName: '/:session_id/name',                               // 更新会话名称
        FixSessionToRedis: '/fixSessionToRedis',                        // 把会话写入redis
        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话
        IsExist: '/isExist',                                            // 判断会话是否存在(i健康发送muc的im消息会话前会先调用创建会话的方法,这个方法会更新redis中每个成员的最后获取时间,导致未读消息不准)

+ 61 - 0
src/server/models/sessions/sessions.js

@ -2103,6 +2103,67 @@ class Sessions extends RedisModel {
    }
    //把会话写入redis
    fixSessionToRedis(sessionId,handler) {
        let self = this;
        let participants = new Participants();
        let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
        let messageId = mongoose.Types.ObjectId().toString();
        let sessionType =0;
        redis.hmgetAsync(sessionKey, ["type", "name"]).then(function (res) {
            sessionType = res[0];
            let sessionName = res[1];
            if (sessionType == null) {
                self.getSessions(sessionId,function(err,res){
                    if (err){
                        logger.error("session data is error");
                    } else {
                        sessionName=res[0].name;
                        sessionType = res[0].type;
                    }
                });
                let participantArray = [];
                let participantsStr="{";
                ParticipantRepo.findAll(sessionId, function (err, participants) {
                    if (err) {
                        ModelUtil.emitError(self.eventEmitter, err.message);
                        return;
                    }
                    participants.forEach(function (participant) {
                        let participantId = participant.id;
                        let participantRole = participant.role;
                        let score = ObjectUtil.timestampToLong(participant.last_fetch_time||(new Date()));
                        participantsStr +="\""+participantId+"\":\""+participantRole+"\",";
                    });
                    participantsStr = participantsStr.substring(0,participantsStr.length-1)+'}';
                    participantsStr = JSON.parse(participantsStr);
                    for (let j in participantsStr) {
                        participantArray.push(j + ":" + participantsStr[j]);
                    }
                    //创建session到redis
                    self.createSessionToRedis(sessionId, sessionName, sessionType, participantArray, messageId, function (err, res) {
                        if (err) {
                            if (handler) {
                                handler(err, null);
                            }
                            ModelUtil.emitError(self.eventEmitter, {message: err, status: -1}, null);
                        } else {
                            if (handler) {
                                handler(null, res);
                            }
                            ModelUtil.emitOK(self.eventEmitter, {status: 200, data: res});
                        }
                    });
                });
            }else {
                ModelUtil.emitOK(self.eventEmitter, {status: 200, data: res});
            }
        })
    }
}
// Expose class