Parcourir la source

错误代码修正

il y a 8 ans
Parent
commit
6992826e1d

+ 2 - 2
src/server/endpoints/v2/topic.endpoint.js

@ -30,14 +30,14 @@ router.get(APIv2.Sessions.Topics, function (req, res) {
router.post(APIv2.Sessions.Topics, function (req, res) {
    let payload = req.body;
    let testing = ObjectUtil.fieldsCheck(payload, "topicId", "topicName", "participants", "messages", "sessionId");
    let testing = ObjectUtil.fieldsCheck(payload, "topic_id", "topic_name", "participants", "messages", "session_id", "session_type");
    if (!testing.pass) {
        throw {httpStatus: 406, message: testing.message}
    }
    let topic = new Topics();
    ControllerUtil.regModelEventHandler(topic, res);
    topic.createTopic(payload.topicName, payload.topicId, payload.sessionId, JSON.parse(payload.participants), JSON.parse(payload.messages));
    topic.createTopic(payload.topic_name, payload.topic_id, payload.session_id, JSON.parse(payload.participants), JSON.parse(payload.messages),payload.session_type);
});
router.put(APIv2.Sessions.Topics, function (req, res) {

+ 3 - 4
src/server/models/sessions/participants.js

@ -78,12 +78,11 @@ class Participants extends RedisModel {
    /**
     * 获取P2P成员所在会话
     *
     * @param patient
     * @param doctor
     * @param users
     * @param handler
     */
    getSessionIdByParticipants(patient, doctor, handler) {
        ParticipantRepo.findSessionIdByParticipantIds(patient, doctor, handler);
    getMucSessionIdByParticipants(users, handler) {
        ParticipantRepo.findMucSessionIdByUser(users, handler);
    }
    /**

+ 3 - 7
src/server/models/sessions/sessions.js

@ -106,9 +106,6 @@ class Sessions extends RedisModel {
                            ModelUtil.emitError(self.eventEmitter, err.message);
                            return;
                        }
                        // 保存会话及成员至Redis中,并更新会话的最后状态
                        let isMucSession = SESSION_TYPES.MUC == type;
                        let message = {
                            sender_id: "System",
                            sender_name: "System",
@ -119,7 +116,7 @@ class Sessions extends RedisModel {
                        Messages.updateLastContent(sessionKey, type, name, message);
                        Participants.saveParticipantsToRedis(sessionId, participantArray, createDate, function (res) {
                            if (isMucSession&&handler) {
                            if (handler) {
                                handler(true, sessionId);
                            } else {
                                ModelUtil.emitOK(self.eventEmitter, {id: sessionId});
@ -555,7 +552,7 @@ class Sessions extends RedisModel {
        let participants = new Participants();
        let session_key = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
        let messageId = mongoose.Types.ObjectId().toString();
        let self = this;
        let sessionType = 0;
        let sessionName = "";
@ -597,8 +594,7 @@ class Sessions extends RedisModel {
                        }
                    })
                }).catch(function (err) {
                    ModelUtil.emitError(self.eventEmitter, {message: "Error occurred while save message to topic: " + err});
                    ModelUtil.emitError(self.eventEmitter, "Error occurred while save message to topic: ");
                    handler(err, messageId)
                })
            } else {

+ 3 - 5
src/server/models/sessions/topics.js

@ -59,9 +59,8 @@ class Topics extends RedisModel {
     * @param users 发起议题的患者,格式:{"userId1:role", "userId2:role"}
     * @param messages 发送的消息对象,格式:{description:"",title:"",img:"image1,image2",senderId:"",senderName:""},多个图片用逗号隔开
     */
    createTopic(topicName, topicId, sessionId, users, messages) {
    createTopic(topicName, topicId, sessionId, users, messages,sessionType) {
        let self = this;
        //MUC模式中sessionID就是患者ID
        let topics_key = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
        let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
@ -81,20 +80,19 @@ class Topics extends RedisModel {
                "description", messages.description,
                "status", TOPIC_STATUS.NEW)
                .then(function (res) {
                    sessions.getSessions(sessionId, function (err, res) {
                    participants.getMucSessionIdByParticipants(users, function (err, res) {
                        // 已经存在对应的会话更新全科为旁听
                        if (res && res.length > 0) {
                            for (var j in users) {
                                participants.updateUser(sessionId, j, users[j]);
                            }
                            callbegin();
                        } else {
                            // 不存在创建SESSION
                            for (var j in users) {
                                pars.push(j + ":" + users[j]);
                            }
                            sessions.createSession(sessionId, messages.senderName, SESSION_TYPES.MUC, pars, function (res) {
                            sessions.createSession(sessionId, messages.senderName, sessionType, pars, function (res) {
                                if (res) {
                                    callbegin();
                                }

+ 19 - 1
src/server/repository/mysql/participant.repo.js

@ -7,7 +7,8 @@ let ImDb = require('../mysql/db/im.db');
let DbUtil = require('../../util/db.util');
let log = require('../../util/log.js');
const DB_TABLES = require('../../include/commons').DB_TABLES;
const SESSION_USER_STATUS = require('../../include/commons').SESSION_USER_STATUS;
const SESSION_TYPES = require('../../include/commons').SESSION_TYPES;
class ParticipantRepo {
    constructor() {
    }
@ -98,6 +99,23 @@ class ParticipantRepo {
        handler(null, sessionId);
    }
    static findMucSessionIdByUser(users,handler){
        var userTemp = [];//先匹配出在线用户
        for(var j in users){
            if(users[j]==SESSION_USER_STATUS.ONLINE){
                userTemp.push(j);
            }
        }
        let sql ="select s.* from "+DB_TABLES.Participants +" p1,"+DB_TABLES.Participants+ " p2,"+
                DB_TABLES.Sessions+" s  where p1.session_id =  s.id and p2.session_id = s.id  and s.type =? " +
                "and ((p1.participant_id =? and p2.participant_id = ?) or (p1.participant_id =? and p2.participant_id = ?))"
        ImDb.execQuery({
            "sql": sql,
            "args": [SESSION_TYPES.MUC,userTemp[0], userTemp[1], userTemp[1],userTemp[0]],
            "handler": handler
        });
    }
    /**
     * 更新最后消息获取时间。
     *