Przeglądaj źródła

代码修改错误修改

8 lat temu
rodzic
commit
dc423e808c

+ 1 - 1
src/server/endpoints/url.initializer.js

@ -53,7 +53,7 @@ class UrlInitializer {
        app.use(APIv2.Management.Base, management);
        app.use(APIv2.Users.Base, users);
        app.use(APIv2.Sessions.Base, sessions);
        app.use(APIv2.Sessions.Topics, topics);
        app.use(APIv2.Sessions.Base, topics);
    }
    static initWebPages(app) {

+ 8 - 8
src/server/endpoints/v2/session.endpoint.js

@ -32,7 +32,7 @@ const APIv2 = require('../../include/endpoints').APIv2;
 *  session_id: 会话ID,非必须,仅对群消息使用。
 *  session_type: 会话类型,必须。
 *  session_name: 会话名称,
 *  participants: 此会话的成员列表,格式:["userId1:role", "userId2:role"],用户的ID及角色。
 *  participants: 此会话的成员列表,格式:{"userId1:role", "userId2:role"},用户的ID及角色。
 * }
 */
router.post("/", function (req, res) {
@ -197,15 +197,15 @@ router.post(APIv2.Sessions.Messages, function (req, res) {
 *  /sessions/:session_id/messages?session_id=blabla&user_id=abc&start_message_id=100&end_message_id=20
 */
router.get(APIv2.Sessions.Messages, function (req, res) {
    let stratmsgid = req.query.stratmsgid;
    let endmsgid = req.query.endmsgid;
    let start_msg_id = req.query.start_msg_id;
    let end_msg_id = req.query.end_msg_id;
    let user = req.query.user;
    let sessionId = req.query.sessionId;
    if (!stratmsgid) {
        throw {httpStatus: 406, message: 'Missing stratmsgid.'};
    if (!start_msg_id) {
        throw {httpStatus: 406, message: 'Missing start_msg_id.'};
    }
    if (!endmsgid) {
        throw {httpStatus: 406, message: 'Missing endmsgid.'};
    if (!end_msg_id) {
        throw {httpStatus: 406, message: 'Missing end_msg_id.'};
    }
    if (!user) {
        throw {httpStatus: 406, message: 'Missing user.'};
@ -215,7 +215,7 @@ router.get(APIv2.Sessions.Messages, function (req, res) {
    }
    let sessions = new Sessions();
    ControllerUtil.regModelEventHandler(sessions, res);
    sessions.getMessages(sessionId, user, stratmsgid,endmsgid);
    sessions.getMessages(sessionId, user, start_msg_id,end_msg_id);
});
/**

+ 19 - 13
src/server/endpoints/v2/topic.endpoint.js

@ -9,7 +9,7 @@
let express = require('express');
let router = express.Router();
let log = require('../../util/log.js');
let ObjectUtil = require("../../util/object.util.js");
let ControllerUtil = require('../../util/controller.util');
let Topics = require('../../models/sessions/topics');
@ -26,28 +26,34 @@ router.get(APIv2.Sessions.Topics, function (req, res) {
});
router.post(APIv2.Sessions.Topics, function (req, res) {
    let data = req.body;
    //    data.topicName ="topicstest1";
    //    data.topicId ="12132312";
    //    data.healthDoctor ="1";
    //    data.doctor ="2";
    //    data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"};
    //let testing = ObjectUtil.fieldsCheck(data.message, "description", "title", "img", "patient","patientName");
    //if (!testing.description) {
    /**
     * //    data.topicName ="topicstest1";
     //    data.topicId ="12132312";
     //    data.healthDoctor ="1";
     //    data.doctor ="2";
     //    data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"};
     //let testing = ObjectUtil.fieldsCheck(data.message, "description", "title", "img", "patient","patientName");
     //if (!testing.description) {
    //    throw {httpStatus: 406, message: "miss message.description"};
    //}
    //if (!testing.title) {
     //if (!testing.title) {
    //    throw {httpStatus: 406, message:"miss message.title"};
    //}
    //if (!testing.patient) {
     //if (!testing.patient) {
    //    throw {httpStatus: 406, message:"miss message.patient"};
    //}
    //if (!testing.patientName) {
     //if (!testing.patientName) {
    //    throw {httpStatus: 406, message:"miss message.patientName"};
    //}
     */
    let payload = req.body;
    let testing = ObjectUtil.fieldsCheck(payload, "topicId", "topicName", "participants", "messages", "sessionId");
    if (!testing.pass) {
        throw {httpStatus: 406, message: testing.message}
    }
    let topic = new Topics();
    ControllerUtil.regModelEventHandler(topic, res);
    topic.createTopics(data.topicName, data.topicId, data.message.patient, data.healthDoctor, data.doctor, data.message);
    topic.createTopics(payload.topicName, payload.topicId,payload.sessionId,JSON.parse(payload.participants), JSON.parse(payload.messages));
});
router.get(APIv2.Sessions.TopicEnded, function (req, res) {

+ 16 - 16
src/server/models/sessions/sessions.js

@ -236,32 +236,32 @@ class Sessions extends RedisModel {
     * @param page 第几页
     * @param pagesize 分页数量
     */
    getMessages(sessionId, user, stratmsgid,endmsgid ) {
    getMessages(sessionId, user, page, pagesize) {
        let self = this;
        let message_timestamp_key = RedisModel.makeRedisKey(REDIS_KEYS.MessagesByTimestamp, sessionId);
        let message_key = RedisModel.makeRedisKey(REDIS_KEYS.Messages, sessionId);
        let participants_key = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
        //超过最大限制后从mysql获取数据
        // if (page * pagesize >= config.sessionConfig.maxMessageCount) {
        //     self.getMessageFromMySQL(sessionId, page, pagesize, function (err, res) {
        //         if (!err) {
        //             ModelUtil.emitOK(self.eventEmitter, {"status": 200, "data": res});
        //         } else {
        //             ModelUtil.emitOK(self.eventEmitter, {"status": -1, "data": err});
        //         }
        //     })
        // } else {
            // if (page > 0) {
            //     page = page * pagesize;
            //     pagesize = pagesize + page;
            // }
        if (page * pagesize >= config.sessionConfig.maxMessageCount) {
            self.getMessageFromMySQL(sessionId, page, pagesize, function (err, res) {
                if (!err) {
                    ModelUtil.emitOK(self.eventEmitter, {"status": 200, "data": res});
                } else {
                    ModelUtil.emitOK(self.eventEmitter, {"status": -1, "data": err});
                }
            })
        } else {
            if (page > 0) {
                page = page * pagesize;
                pagesize = pagesize + page;
            }
            let participants = new Participants();
            participants.existsParticipant(sessionId, user, function (res) {
                if (!res) {
                    ModelUtil.emitOK(self.eventEmitter, {"status": -1, "msg": "用户不在此会话中!"});
                } else {
                    //倒序取出最后N条消息
                    redis.zrevrangebyscoreAsync(message_timestamp_key, endmsgid, stratmsgid).then(function (res) {
                    redis.zrevrangeAsync(message_timestamp_key, page, pagesize).then(function (res) {
                        //取出消息实体
                        if (res.length == 0) {
                            ModelUtil.emitOK(self.eventEmitter, {"status": 200, "data": []});
@ -284,7 +284,7 @@ class Sessions extends RedisModel {
                    })
                }
            })
        // }
        }
    }
    getAllSessionsUnreadMessageCount(){}

+ 19 - 19
src/server/models/sessions/topics.js

@ -29,7 +29,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 +57,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, config.sessionConfig.MUC, pars, function (res) {
                            if (res) {
                                callbegin();
                            }
@ -105,12 +105,12 @@ class Topics extends RedisModel {
            msg.contentType = 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(startMsgId);
                }
            })
        }
@ -118,7 +118,7 @@ class Topics extends RedisModel {
        /**
         * 发送求助内容
         */
        function callBeginMsg() {
        function callBeginMsg(startMsgId) {
            let msg = {};
            msg.senderId = messages.patient;
            msg.senderName = messages.patientName;
@ -143,7 +143,7 @@ class Topics extends RedisModel {
                    })
                }
            }
            ModelUtil.emitOK(self.eventEmitter, "创建成功!");
            ModelUtil.emitOK(self.eventEmitter, startMsgId);
        }
    }