Browse Source

中山医院MDT修改

huangwenjie 5 years ago
parent
commit
37c751781d

+ 81 - 42
src/server/endpoints/v2/session.endpoint.js

@ -54,56 +54,95 @@ router.post("/", function (req, res) {
    log.info("participants: "+participants);
    participants = JSON.parse(participants);
    /**
     *MDT 医生数据转换,根据手机号查询医生CODE
     */
    if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
        participants = sessions.conversionAarticipant(participants);
    //获取传入的参与者数组长度
    let participantLength = 0;
    for (let i in participants) {
        participantLength ++;
    }
    for (let j in participants) {
        log.info("aaaa:"+j + ":" + participants[j]);
        participantArray.push(j + ":" + participants[j]);
    }
    ControllerUtil.regModelEventHandler(sessions, res);
    console.log(sessionId, sessionName, sessionType, participantArray);
    sessions.createSession(sessionId, sessionName, sessionType, participantArray);
    ///是否视频会议的会话
    let videoconferencing = false;
    // participants = JSON.parse(participants);
    // for (let j in participants) {
    //     participantArray.push(j + ":" + participants[j]);
    // }
    //视频会议的会话 szx add 20181121
    if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
        let access_token = "";
        if(payload.hasOwnProperty("mobile"))access_token = payload.access_token;
        videoconferencing = true;
        //发送广播,给相关的与会人员
        for (let j in participants) {
            let userId = "pcim_"+j;
            let pc_doctorClient = clientCache.findById(userId);
            if(pc_doctorClient){
                log.info("videoconferencing send to "+userId);
                pc_doctorClient.socket.emit("startVideoconference",{"sessionId":sessionId,"user_id":j});
            }
            else{
                log.info("videoconferencing not find "+userId);
        if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
            sessions.conversionAarticipant(j, (doctorid) => {
                participantArray.push(doctorid+":"+participants[j])
                //判断数组长度等于传入的长度,则执行创建会话的请求
                if(participantArray.length == participantLength){
                    ControllerUtil.regModelEventHandler(sessions, res);
                    console.log(sessionId, sessionName, sessionType, participantArray);
                    sessions.createSession(sessionId, sessionName, sessionType, participantArray);
                    ///是否视频会议的会话
                    let videoconferencing = false;
                    // participants = JSON.parse(participants);
                    // for (let j in participants) {
                    //     participantArray.push(j + ":" + participants[j]);
                    // }
                    //视频会议的会话 szx add 20181121
                    if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
                        let access_token = "";
                        if(payload.hasOwnProperty("mobile"))access_token = payload.access_token;
                        videoconferencing = true;
                        //发送广播,给相关的与会人员
                        for (let j in participants) {
                            let userId = "pcim_"+j;
                            let pc_doctorClient = clientCache.findById(userId);
                            if(pc_doctorClient){
                                log.info("videoconferencing send to "+userId);
                                pc_doctorClient.socket.emit("startVideoconference",{"sessionId":sessionId,"user_id":j});
                            }
                            else{
                                log.info("videoconferencing not find "+userId);
                            }
                        }
                    }
                }
            })
        }else{
            participantArray.push(j + ":" + participants[j]);
            //判断数组长度等于传入的长度,则执行创建会话的请求
            if(participantArray.length == participantLength){
                ControllerUtil.regModelEventHandler(sessions, res);
                console.log(sessionId, sessionName, sessionType, participantArray);
                sessions.createSession(sessionId, sessionName, sessionType, participantArray);
                ///是否视频会议的会话
                let videoconferencing = false;
                // participants = JSON.parse(participants);
                // for (let j in participants) {
                //     participantArray.push(j + ":" + participants[j]);
                // }
                //视频会议的会话 szx add 20181121
                if (payload.hasOwnProperty('videoconferencing') && payload.videoconferencing == 1){
                    let access_token = "";
                    if(payload.hasOwnProperty("mobile"))access_token = payload.access_token;
                    videoconferencing = true;
                    //发送广播,给相关的与会人员
                    for (let j in participants) {
                        let userId = "pcim_"+j;
                        let pc_doctorClient = clientCache.findById(userId);
                        if(pc_doctorClient){
                            log.info("videoconferencing send to "+userId);
                            pc_doctorClient.socket.emit("startVideoconference",{"sessionId":sessionId,"user_id":j});
                        }
                        else{
                            log.info("videoconferencing not find "+userId);
                        }
                    }
                }
            }
        }
    }
});
/**

+ 92 - 40
src/server/handlers/socket.handler.js

@ -42,40 +42,98 @@ class SocketHandler {
                if (!data.userId) {
                    socketServer.sockets.emit('error', {message: 'Missing fields(s): userId.'});
                } else {
                    if("pc_doctor"===data.clientType){//新增pc端医生登录
                        data.userId = "pc_"+data.userId;
                    }else if("pcim_doctor"===data.clientType){//用于pcim 消息通知
                        data.userId = "pcim_"+data.userId;
                    }else if("pc_patient"===data.clientType){//新增居民PC登陆类型
                        data.userId= "pcpatient_"+data.userId;
                    }
                    if(clientCache.removeByUserId(data.userId)){
                        log.info("User " + data.userId + " already login");
                        return;
                    let mdt_login_tag = data.SYSTEM_TYPE;
                    //MDT 托盘登陆
                    if(mdt_login_tag && "MDT" == mdt_login_tag){
                        //传入手机号,转换成医生CODE
                        sessions.conversionAarticipant(data.userId, (doctorid) => {
                            data.userId = "pcim_"+doctorid;
                            if(clientCache.removeByUserId(data.userId)){
                                log.info("User " + data.userId + " already loginMDT");
                                return;
                            }
                            log.info('User ' + data.userId + ' loginMDT');
                            // if("pcim_doctor"===data.clientType){
                            //用于pcim 消息通知
                            let pcdoctorClient = new PcDoctorClient(socket, socketServer);
                            pcdoctorClient.userId = data.userId;
                            pcdoctorClient.password = data.password;
                            pcdoctorClient.clientType = data.clientType;
                            pcdoctorClient.sessionId =  "";
                            clientCache.addClient(pcdoctorClient);
                            socket.emit('ack', {});
                        });
                    }else{
                        if("pc_doctor"===data.clientType){//新增pc端医生登录
                            data.userId = "pc_"+data.userId;
                        }else if("pcim_doctor"===data.clientType){//用于pcim 消息通知
                            data.userId = "pcim_"+data.userId;
                        }else if("pc_patient"===data.clientType){//新增居民PC登陆类型
                            data.userId= "pcpatient_"+data.userId;
                        }
                        if(clientCache.removeByUserId(data.userId)){
                            log.info("User " + data.userId + " already login");
                            return;
                        }
                        log.info('User ' + data.userId + ' login');
                        if(!data.clientType||data.clientType=="patient"){
                            let patientClient = new PatientClient(socket, socketServer);
                            patientClient.userId = data.userId;
                            patientClient.password = data.password;
                            patientClient.clientType = data.clientType||"patient";
                            patientClient.sessionId = data.sessionId||"";
                            clientCache.addClient(patientClient);
                            users.login(data.userId, 10, '', '');
                            socket.emit('ack', {});
                        }else if("pc_patient"===data.clientType){
                            //用于pcpatient 消息通知
                            let pcpatientClient = new PcPatientClient(socket, socketServer);
                            pcpatientClient.userId = data.userId;
                            pcpatientClient.password = data.password;
                            pcpatientClient.clientType = data.clientType;
                            pcpatientClient.sessionId = data.sessionId||"";
                            clientCache.addClient(pcpatientClient);
                            users.login(data.userId, 10, '', '');
                            socket.emit('ack', {});
                        }else if("pcim_doctor"===data.clientType){
                            //用于pcim 消息通知
                            let pcdoctorClient = new PcDoctorClient(socket, socketServer);
                            pcdoctorClient.userId = data.userId;
                            pcdoctorClient.password = data.password;
                            pcdoctorClient.clientType = data.clientType;
                            pcdoctorClient.sessionId =  "";
                            clientCache.addClient(pcdoctorClient);
                            socket.emit('ack', {});
                        }else{
                            let doctorClient = new DoctorClient(socket, socketServer);
                            doctorClient.userId = data.userId;
                            doctorClient.password = data.password;
                            doctorClient.clientType = data.clientType;
                            doctorClient.sessionId =  data.sessionId||"";
                            clientCache.addClient(doctorClient);
                            socket.emit('ack', {});
                        }
                    }
                }
            });
                    log.info('User ' + data.userId + ' login');
                    if(!data.clientType||data.clientType=="patient"){
                        let patientClient = new PatientClient(socket, socketServer);
                        patientClient.userId = data.userId;
                        patientClient.password = data.password;
                        patientClient.clientType = data.clientType||"patient";
                        patientClient.sessionId = data.sessionId||"";
                        clientCache.addClient(patientClient);
                        users.login(data.userId, 10, '', '');
                        socket.emit('ack', {});
                    }else if("pc_patient"===data.clientType){
                        //用于pcpatient 消息通知
                        let pcpatientClient = new PcPatientClient(socket, socketServer);
                        pcpatientClient.userId = data.userId;
                        pcpatientClient.password = data.password;
                        pcpatientClient.clientType = data.clientType;
                        pcpatientClient.sessionId = data.sessionId||"";
                        clientCache.addClient(pcpatientClient);
                        users.login(data.userId, 10, '', '');
                        socket.emit('ack', {});
                    }else if("pcim_doctor"===data.clientType){
            // 客户端注册
            socket.on('loginMDT', function (data) {
                if (!data.userId) {
                    socketServer.sockets.emit('error', {message: 'Missing fields(s): userId.'});
                } else {
                    sessions.conversionAarticipant(j, (doctorid) => {
                        data.userId = "pcim_"+doctorid;
                        if(clientCache.removeByUserId(data.userId)){
                            log.info("User " + data.userId + " already loginMDT");
                            return;
                        }
                        log.info('User ' + data.userId + ' loginMDT');
                        // if("pcim_doctor"===data.clientType){
                        //用于pcim 消息通知
                        let pcdoctorClient = new PcDoctorClient(socket, socketServer);
                        pcdoctorClient.userId = data.userId;
@ -84,15 +142,9 @@ class SocketHandler {
                        pcdoctorClient.sessionId =  "";
                        clientCache.addClient(pcdoctorClient);
                        socket.emit('ack', {});
                    }else{
                        let doctorClient = new DoctorClient(socket, socketServer);
                        doctorClient.userId = data.userId;
                        doctorClient.password = data.password;
                        doctorClient.clientType = data.clientType;
                        doctorClient.sessionId =  data.sessionId||"";
                        clientCache.addClient(doctorClient);
                        socket.emit('ack', {});
                    }
                        // }
                    });
                }
            });

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

@ -89,22 +89,6 @@ class Sessions extends RedisModel {
    }
    /**
     *MDT 医生数据转换,根据手机号查询医生CODE
     */
    conversionAarticipant(participants) {
        let doctorProto = DoctorRepo;
        for (let j in participants) {
            doctorProto.findByMobile(participants[j][0], function (err, oDoctor) {
                if(oDoctor.length>0){
                    participants[j][0] = oDoctor.id;
                }
            });
        }
        return participants;
    }
    /**
     * 创建会话。REDIS
     * @param sessionId
@ -402,6 +386,25 @@ class Sessions extends RedisModel {
        })
    }
    /**
     *MDT 医生数据转换,根据手机号查询医生CODE
     */
    conversionAarticipant(doctorMobile, callback) {
        let doctorProto = DoctorRepo;
            doctorProto.findByMobile(doctorMobile, function (err, oDoctor) {
                if(oDoctor.length>0 && oDoctor[0].id){
                    if(callback){
                        callback(oDoctor[0].id)
                    }
                }else {
                    if(callback){
                        logger.error("Get doctoc code failed: mobile:", doctorMobile);
                        callback(doctorMobile)
                    }
                }
            });
    }
     /**
     * 根据用户ID获取用户的session列表
     * @param userId

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

@ -278,7 +278,7 @@ class Topics extends RedisModel {
            pars.push(j + ":" + users[j]);
        }
        let sessions = new Sessions();
        sessions.createSession(sessionId, messages.sender_name, sessionType, pars, function (err, session) {
        sessions.createSession(sessionId, messages.sender_name, sessionType, pars,"IM",function (err, session) {
            sessionId = session.id;
            let datetime  = session.create_date;
            //新增判断是否有未结束的咨询,用户网络差,会多次点击造成同时存在多个咨询

+ 1 - 1
src/server/repository/mysql/doctor.repo.js

@ -22,7 +22,7 @@ class DoctorRepo {
    static findByMobile(mobile, handler) {
        ImDb.execQuery({
            "sql": "select id, name, sex, birthdate, photo from doctors where mobile = ? ",
            "sql": "select id, name, sex, birthdate, avatar from doctors where mobile = ? ",
            "args": [mobile],
            "handler": handler
        });

+ 15 - 0
src/server/start.sh

@ -0,0 +1,15 @@
#ps -ef | grep push_server | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep node | grep -v grep | awk '{print $2}' | xargs kill -9
#chmod 777 ./push_server/dispatch/dispatch_svr
#chmod 777 ./push_server/access/access_svr
#chmod 777 ./push_server/authorsvr/author_svr
#chmod 777 ./push_server/msgsvr/msg_svr
#chmod 777 ./im_server/node
#./push_server/dispatch/dispatch_svr -d
#./push_server/access/access_svr -d
#./push_server/authorsvr/author_svr -d
#./push_server/msgsvr/msg_svr -d
#cd im_server
#nohup /usr/local/ssgg_im/im_server/node server.js > log.txt &
#cd doctor
nohup /usr/local/ichat/src/server/node app.armour.js > log.txt &