преди 8 години
родител
ревизия
81785db090

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

@ -160,7 +160,6 @@ router.get(APIv2.Sessions.ParticipantsAvatar, function (req, res) {
    let participants = new Participants();
    let participants = new Participants();
    ControllerUtil.regModelEventHandler(participants, res);
    ControllerUtil.regModelEventHandler(participants, res);
    participants.getParticipantsAvatar(sessionId);
    participants.getParticipantsAvatar(sessionId);
});
});

+ 12 - 0
src/server/endpoints/v2/topic.endpoint.js

@ -31,6 +31,18 @@ router.get(APIv2.Sessions.TopicMessages, function (req, res) {
    topic.getTopicMessages(topicId,user,startMsgId,endMsgId,page,pagesize);
    topic.getTopicMessages(topicId,user,startMsgId,endMsgId,page,pagesize);
});
});
/**
 * 获取topic单条记录
 */
router.get(APIv2.Sessions.Topic, function (req, res) {
    let topicId = req.query.topic_id;
    let topic = new Topics();
    ControllerUtil.regModelEventHandler(topic, res);
    topic.getTopicByTopicId(topicId);
});
router.get(APIv2.Sessions.TopicList, function (req, res) {
router.get(APIv2.Sessions.TopicList, function (req, res) {
    let user = req.query.user;
    let user = req.query.user;
    let status = req.query.status;
    let status = req.query.status;

+ 2 - 1
src/server/handlers/socket.handler.js

@ -42,6 +42,7 @@ class SocketHandler {
                        patientClient.userId = data.userId;
                        patientClient.userId = data.userId;
                        patientClient.password = data.password;
                        patientClient.password = data.password;
                        patientClient.clientType = data.clientType||"patient";
                        patientClient.clientType = data.clientType||"patient";
                        patientClient.sessionId = data.sessionId||"";
                        clientCache.addClient(patientClient);
                        clientCache.addClient(patientClient);
                        users.login(data.userId, 10, '', '');
                        users.login(data.userId, 10, '', '');
@ -52,7 +53,7 @@ class SocketHandler {
                        doctorClient.userId = data.userId;
                        doctorClient.userId = data.userId;
                        doctorClient.password = data.password;
                        doctorClient.password = data.password;
                        doctorClient.clientType = data.clientType;
                        doctorClient.clientType = data.clientType;
                        doctorClient.sessionId = "";
                        doctorClient.sessionId =  data.sessionId||"";
                        clientCache.addClient(doctorClient);
                        clientCache.addClient(doctorClient);
                        socket.emit('ack', {});
                        socket.emit('ack', {});
                    }
                    }

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

@ -31,7 +31,7 @@ const APIv2 = {
        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话
        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话
        Topics: '/:topic_id/topics',
        Topics: '/:topic_id/topics',
        Topic: '/:session_id/topics/:topic_id',                          // 议题,指定ID的议题将返回其信息
        Topic: '/topics/:topic_id',                          // 议题,指定ID的议题将返回其信息
        TopicEnded: '/:session_id/topics/:topic_id/ended',              // 议题是否已结束,若top_id为current,则检查最后一个议题的状态
        TopicEnded: '/:session_id/topics/:topic_id/ended',              // 议题是否已结束,若top_id为current,则检查最后一个议题的状态
        TopicList:'/topics',
        TopicList:'/topics',
        TopicMessages:'/topic/:topic_id/messages',
        TopicMessages:'/topic/:topic_id/messages',

+ 20 - 16
src/server/models/client/wechat.client.js

@ -66,8 +66,10 @@ class WechatClient extends RedisModel {
                log.warn("User's wechat endpoint is online, sending via web socket. User id: ", targetUserId);
                log.warn("User's wechat endpoint is online, sending via web socket. User id: ", targetUserId);
                WechatClient.sendViaWebSocket(patientClient.socket, message);
                WechatClient.sendViaWebSocket(patientClient.socket, message);
                if(doctorClient){
                if(doctorClient){
                    if(patientClient.sessionId==doctorClient.sessionId){
                    //用户socket在线,推送给用户后,告知医生此消息已读
                    //用户socket在线,推送给用户后,告知医生此消息已读
                    WechatClient.sendReadDoctor(doctorClient.socket, message);
                        WechatClient.sendReadDoctor(doctorClient.socket, message);
                    }
                }
                }
            } else {
            } else {
                log.info("User's wechat endpoint is not online, sending via wechat template message. User id: ", targetUserId);
                log.info("User's wechat endpoint is not online, sending via wechat template message. User id: ", targetUserId);
@ -94,6 +96,7 @@ class WechatClient extends RedisModel {
    static sendAllRead(doctorId,sessionId){
    static sendAllRead(doctorId,sessionId){
        let doctorClient = clientCache.findByIdAndType(doctorId,SOCKET_TYPES.DOCTOR);
        let doctorClient = clientCache.findByIdAndType(doctorId,SOCKET_TYPES.DOCTOR);
        if(doctorClient){
        if(doctorClient){
            if(doctorClient.sessionId==sessionId)
                doctorClient.socket.emit('message',{ read:"all"});
                doctorClient.socket.emit('message',{ read:"all"});
        }else{
        }else{
            log.warn(doctorId+" target doctor is not online!");
            log.warn(doctorId+" target doctor is not online!");
@ -122,22 +125,23 @@ class WechatClient extends RedisModel {
            return;
            return;
        }
        }
        let sendDoctorClient = clientCache.findByIdAndType(message.sender_id,SOCKET_TYPES.DOCTOR);
        let sendDoctorClient = clientCache.findByIdAndType(message.sender_id,SOCKET_TYPES.DOCTOR);
        sendDoctorClient.socket.emit('message', {
            id: message.id,
            session_id: message.session_id,
            sender_id: message.sender_id,
            sender_name: message.sender_name,
            content_type: message.content_type,
            content: message.content,
            timestamp: ObjectUtil.timestampToLong(message.timestamp),
            type: message.content_type,          // legacy support
            name: message.sender_name,
            read:"one"
        });
        if(sendDoctorClient.sessionId==doctorClient.sessionId){
            sendDoctorClient.socket.emit('message', {
                id: message.id,
                session_id: message.session_id,
                sender_id: message.sender_id,
                sender_name: message.sender_name,
                content_type: message.content_type,
                content: message.content,
                timestamp: ObjectUtil.timestampToLong(message.timestamp),
                type: message.content_type,          // legacy support
                name: message.sender_name,
                read:"one"
            });
        }else{
            log.warn("doctor is not in the same session");
        }
    }
    }
    /**
    /**
     * 发送微信模板消息给居民
     * 发送微信模板消息给居民
     *
     *

+ 11 - 0
src/server/models/sessions/topics.js

@ -358,6 +358,17 @@ class Topics extends RedisModel {
    }
    }
    getTopicByTopicId(topicId){
        let self = this;
        TopicsRepo.findAllByTopicId(topicId,function (err,res) {
            if (!err) {
                ModelUtil.emitOK(self.eventEmitter, {"status": 200,"data":res});
            } else {
                ModelUtil.emitOK(self.eventEmitter, {"status": -1});
            }
        })
    }
}
}
// Expose class
// Expose class

+ 10 - 3
src/server/repository/mysql/participant.repo.js

@ -23,15 +23,22 @@ class ParticipantRepo {
     * @param handler
     * @param handler
     */
     */
    static findAll(sessionId, handler) {
    static findAll(sessionId, handler) {
        let sql = "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar, p.participant_role role, false is_patient,last_fetch_time FROM sessions s, participants p, doctors u " +
        let sql = "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar, p.participant_role role, false is_patient,p.last_fetch_time FROM sessions s, participants p, doctors u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id union " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id union " +
            "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar, p.participant_role role, true is_patient,last_fetch_time FROM sessions s, participants p, patients u " +
            "SELECT u.id, u.name, u.sex, u.birthdate, u.avatar, p.participant_role role, true is_patient,p.last_fetch_time FROM sessions s, participants p, patients u " +
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id";
            "WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.id";
        ImDb.execQuery({
        ImDb.execQuery({
            "sql": sql,
            "sql": sql,
            "args": [sessionId, sessionId],
            "args": [sessionId, sessionId],
            "handler": handler
            "handler": function(err,res){
                if(res&&res.length>0){
                    for(var j in res){
                        res[j].last_fetch_time = res[j].last_fetch_time.getTime();
                    }
                }
                handler(err,res);
            }
        });
        });
    }
    }