浏览代码

Merge branch 'im-internet-hospital' of liubing/im.doctor into im-internet-hospital

liubing 4 年之前
父节点
当前提交
faf8664f00

+ 20 - 0
src/server/endpoints/v2/message.endpoint.js

@ -50,6 +50,26 @@ router.post(APIv2.Message.DoctorSystemMessage, function (req, res) {
});
/**
 * 医养PC管理端端socket消息
 */
router.post(APIv2.Message.CloudCarePcManageMessage, function (req, res) {
    let clientType = req.body.clientType;
    let message = req.body.message;
    let wechatClient = new WechatClient();
    if (!clientType) {
        throw {httpStatus: 406, message: 'Missing clientType.'};
    }
    if (!message) {
        throw {httpStatus: 406, message: 'Missing message.'};
    }
    ControllerUtil.regModelEventHandler(wechatClient, res);
    //推送MDT,医生外层新消息
    wechatClient.CloudCarePcManageMessageToPc(clientType,JSON.parse(message));
});
router.get(APIv2.Message.DataMessage, function (req, res) {
    let sessionId = req.query.sessionId;
    let messages = new Messages();

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

@ -11,6 +11,7 @@ let PatientClient = require('./../models/socket.io/patient.client');
let PcPatientClient = require('./../models/socket.io/pcPatient.client');
let PcDoctorClient  = require('./../models/socket.io/pcDoctor.client');
let DoctorClient  = require('./../models/socket.io/doctor.client');
let CloudCarePcManageClient  = require('../models/socket.io/cloudCarePcManage.client');
let RtcClient  = require('../models/socket.io/rtc.client.js');
let Sessions = require('../models/sessions/sessions');
let Users = require('../models/user/users');
@ -19,6 +20,7 @@ let ModelUtil = require('../util/model.util.js');
let pusher = require('../models/push/pusher.js');
let AppClient = require('../models/client/app.client.js');
let Participants = require('../models/sessions/participants');
let uuid = require('uuid')
let sessions = new Sessions();
let users = new Users();
@ -86,6 +88,8 @@ class SocketHandler {
                            data.userId= "patient_system_"+data.userId;
                        }else if("doctor_system"===data.clientType){//新增医生APP外层-登陆类型-20191012-huangnwenjie
                            data.userId= "doctor_system_"+data.userId;
                        } else if("cloudCare_pcManage"===data.clientType){//新增医生APP外层-登陆类型-20191012-huangnwenjie
                            data.userId= "cloudCare_pcManage"+uuid.v1();
                        }
                        if(clientCache.removeByUserId(data.userId)){
@ -129,7 +133,14 @@ class SocketHandler {
                        //     pcdoctorClient.sessionId =  "";
                        //     clientCache.addClient(pcdoctorClient);
                        //     socket.emit('ack', {});
                        }else{
                        }else if("cloudCare_pcManage"===data.clientType){
                            let cloudCarePcManageClient = new CloudCarePcManageClient(socket, socketServer);
                            cloudCarePcManageClient.userId = data.userId;
                            cloudCarePcManageClient.clientType = data.clientType;
                            clientCache.addClient(cloudCarePcManageClient);
                            socket.emit('ack', {});
                        }
                        else{
                            let doctorClient = new DoctorClient(socket, socketServer);
                            doctorClient.userId = data.userId;
                            doctorClient.password = data.password;

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

@ -205,6 +205,7 @@ exports.SOCKET_TYPES={
    DOCTOR_SYSTEM:"doctor_system",//医生APP外层
    PC_DOCTOR:"pc_doctor",//医生PC
    PC_DOCTOR_SYSTEM:"pc_doctor_system",//医生PC外层
    CloudCarePcManage:"cloudCare_pcManage",//医养pc管理
    PCIM_DOCTOR:"pcim_doctor",//中山医院医生MDT
    DEMO:"demo"
}

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

@ -20,6 +20,7 @@ const APIv2 = {
        DataMessage: '/dataMessage',
        CleanMessageToRedis: '/cleanMessageToRedis',
        DoctorSystemMessage: '/doctorSystemMessage',
        CloudCarePcManageMessage: '/cloudCarePcManageMessage',//
        CleanMessageLastFetchTimeToRedis: '/cleanMessageLastFetchTimeToRedis'
    },
    Users: {

+ 39 - 0
src/server/models/client/wechat.client.js

@ -540,6 +540,45 @@ class WechatClient extends RedisModel {
    }
    /**
     * 医疗云 PC管理端发送socket
     * @param doctorId
     * @param message
     * @param response
     */
    CloudCarePcManageMessageToPc(clientType,message,handler) {
        let self = this;
        let CloudCarePcManageClients = clientCache.findByType(clientType);
        if(CloudCarePcManageClients.size==0){
            log.warn("target pcManage is not online!");
            ModelUtil.emitOK(self.eventEmitter, {status: 1,message:"pcManage_not_online"});
            return;
        }else {
            for (let clientKye of CloudCarePcManageClients.keys()){
                let CloudCarePcManageClient = CloudCarePcManageClients.get(clientKye);
                if (CloudCarePcManageClient){
                    if (message.content_type==CONTENT_TYPES.emergencyAssistance) {
                        CloudCarePcManageClient.socket.emit('message', {
                            session_id: message.session_id,
                            sender_name: message.sender_name,
                            content_notice: message.content_notice,
                            OrderStatus:message.OrderStatus,
                            sender_code: message.sender_code,
                            OrderType: message.OrderType, //20紧急救助工单21上门预约工单22安防警报工单
                            order_id: message.order_id,
                            type: message.content_type,
                            extend: message.extend
                        });
                    }
                }
            }
        }
        ModelUtil.emitOK(self.eventEmitter, {status: 200});
        return;
    }
    static sendPcImSocket(targetId, message, sessionType) {
        if (message.content_type == CONTENT_TYPES.PlainText ||
            message.content_type == CONTENT_TYPES.Image ||

+ 10 - 0
src/server/models/socket.io/client.cache.js

@ -15,6 +15,7 @@ class ClientCache {
        this._clientsBySocket = new Map();
        this._clientsByUserId = new Map();
        this._clientsByTypeAndUserId = new Map();
        this._clientsCloudCarePCManage = new Map();
    }
    get clients() {
@ -25,6 +26,9 @@ class ClientCache {
        this._clientsByUserId.set(client.userId, client);
        this._clientsBySocket.set(client.socket, client);
        this._clientsByTypeAndUserId.set(client.userId+":"+client.clientType,client);
        if ("cloudCare_pcManage"===client.clientType){
            this._clientsCloudCarePCManage.set(client.userId+":"+client.clientType,client);
        }
        //log.info('Current clients: ', this.clients);
    }
@ -54,6 +58,12 @@ class ClientCache {
       return  this._clientsByTypeAndUserId.get(userId+":"+type);
    }
    findByType(type){
        if ("cloudCare_pcManage"===type){
            return this._clientsCloudCarePCManage;
        }
    }
    findBySocket(socket) {
        return this._clientsBySocket.get(socket);
    }

+ 15 - 0
src/server/models/socket.io/cloudCarePcManage.client.js

@ -0,0 +1,15 @@
/**
 * 医养 socket.
 *
 */
"use strict";
var Client = require('./client');
class CloudCarePcManageClient extends Client{
    constructor(socket, socketServer){
        super(socket, socketServer);
    }
}
module.exports = CloudCarePcManageClient;