Procházet zdrojové kódy

适配达梦修改

LAPTOP-KB9HII50\70708 před 1 měsícem
rodič
revize
6149fb723c

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

@ -225,6 +225,21 @@ router.get("/findByUserIdAndType", function (req, res) {
    sessions.findByUserIdAndType(userId,type)
});
/**
 * 把会话写入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);
});
/**
 * 按会话类型获取会话列表
 * 请求URL /sessions/sessionListByType?user_id=3121&page=0&size=10&type=4

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

@ -194,6 +194,7 @@ const CONTENT_TYPES = {
    SystemMessagePushAssistance:999,// 系统推送消息统一   999  Pad 使用
    DeviceMessagePushAssistance:991,// 设备消息统一推送   991  Pad 使用
    EmergencyAssistanceMessage:43,//云招呼-预警消息
    InspectRecord:50,//影响解读
    KnowCommonQuestion:3001,//知识库-常见问题
    KnowCommonQuestions:3002,//知识库-常见问题集
    KnowCommonDict:3003,//知识库-字典

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

@ -39,6 +39,7 @@ const APIv2 = {
        Session: '/:session_id/session',                                // 获取会话
        SessionListByType: '/sessionListByType',                        // 按会话类型获取会话
        FixSessionToRedis: '/fixSessionToRedis',                        // 把会话写入redis
        SessionListByNoParticipant: '/sessionListByNoParticipant',    //导诊获取没有参与会话的列表
        SessionCountByType: '/sessionCountByType',                      // 按会话类型获取会话数量
        SessionSticky: '/:session_id/sticky',                           // 会话置顶,置顶使用PUT,取消置顶使用DELETE

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

@ -2884,7 +2884,66 @@ 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