Преглед на файлове

Merge branch 'im-internet-hospital' of http://192.168.1.220:10080/Amoy/im.doctor into im-internet-hospital

# Conflicts:
#	src/server/models/client/wechat.client.js
wangzhinan преди 5 години
родител
ревизия
a65a55cc1c

+ 31 - 5
src/server/handlers/socket.handler.js

@ -40,6 +40,7 @@ class SocketHandler {
            log.info('one user connection...');
            // 客户端注册
            socket.on('login', function (data) {
                log.info("启用事件监听")
                if (!data.userId) {
                    socketServer.sockets.emit('error', {message: 'Missing fields(s): userId.'});
                } else {
@ -310,6 +311,7 @@ class SocketHandler {
            });
            socket.on('error',function(errMsg){
                log.info("error"+errMsg);
                let client = clientCache.findBySocket(socket);
                if (client) {
                    //修改居民在线状态
@ -345,16 +347,40 @@ class SocketHandler {
            // 客户端断开
            socket.on('disconnect', function (soc) {
                log.info("客户端断开:"+soc);
                let patientClient = clientCache.findBySocket(socket);
                log.info("客户端断开patientClient:");
                if (patientClient) {
                    //修改居民在线状态
                    // users.changUserRedisLoginStatus(original_login_userid,client.clientType,0);
                    //通知会话的其他成员离线消息
                    log.info('User ' + patientClient.userId + ' login');
                    if(!patientClient.clientType||patientClient.clientType=="patient"||patientClient.clientType=="patient_system"){//新增居民微信端外层-登陆类型-20191012-huangnwenjie
                        let participants = new Participants();
                        participants.changUserRedisLoginStatus(patientClient.userId,patientClient.clientType,0,patientClient.sessionId);
                        socket.emit('ack', {});
                    }else if("pc_patient"===patientClient.clientType || "pc_patient_system"===patientClient.clientType){////新增居民PC外层-登陆类型-20191012-huangnwenjie
                        //修改居民在线状态
                        let participants = new Participants();
                        participants.changUserRedisLoginStatus(patientClient.userId,patientClient.clientType,0,patientClient.sessionId);
                        socket.emit('ack', {});
                        //MDT 登陆类型已迁移到上面的分支-20191012-huangnwenjie
                        // }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 participants = new Participants();
                        participants.changUserRedisLoginStatus(patientClient.userId,patientClient.clientType,0,patientClient.sessionId);
                    }
               /*     //通知会话的其他成员离线消息
                    if(patientClient.sessionId !=  "system"){
                        let participants = new Participants();
                        participants.emitSessionUsers(patientClient.sessionId,patientClient.userId,"offline");
                    }
                    }*/
                    log.info("User disconnect: ", patientClient.userId);
                    clientCache.removeByUserSocket(socket);
                }

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

@ -110,7 +110,7 @@ const CONTENT_TYPES = {
    PrescriptionReject: 33, //处方驳回消息
    ConsultSuggest: 34, //咨询建议
    PayMessage: 35, //支付消息
    surveyMessage: 36, //问卷消息
    surveyMessage: 36, //患者答完问卷
    ReservationDoorCardInfo: 2101,//上门服务-预约工单卡片信息
    ChangeDoorCardInfo: 2102,//上门服务-修改工单卡片信息
    ChangeDoorDoctor: 2103,//上门服务-变更工单医生信息

+ 3 - 2
src/server/models/client/wechat.client.js

@ -387,6 +387,7 @@ class WechatClient extends RedisModel {
     * @param message
     */
    static sendMDTSocketMessageToDoctor(doctorId, message) {
        log.info("doctor======="+doctorId)
        // let doctorMDTClient = clientCache.findByIdAndType("pcim_"+doctorId,SOCKET_TYPES.PCIM_DOCTOR);
        let doctorSYSTEMClient = clientCache.findByIdAndType("pc_system_"+doctorId,SOCKET_TYPES.PC_DOCTOR_SYSTEM);
        let doctorAPPSYSTEMClient = clientCache.findByIdAndType("doctor_system_"+doctorId,SOCKET_TYPES.DOCTOR_SYSTEM);
@ -397,7 +398,7 @@ class WechatClient extends RedisModel {
        }else{
            doctorSYSTEMClient.socket.emit('message', {
                id: message.id,
                session_id: message.session_id,
                session_id: 'system',
                sender_id: message.sender_id,
                sender_name: message.sender_name,
                content_type: 1,
@ -416,7 +417,7 @@ class WechatClient extends RedisModel {
        }else{
            doctorAPPSYSTEMClient.socket.emit('message', {
                id: message.id,
                session_id: message.session_id,
                session_id: 'system',
                sender_id: message.sender_id,
                sender_name: message.sender_name,
                content_type: 1,

+ 58 - 1
src/server/models/sessions/participants.js

@ -266,8 +266,40 @@ class Participants extends RedisModel {
        log.info("changUserRedisLoginStatus,userid:"+userid)
        log.info("changUserRedisLoginStatus,userid:"+userid)
        log.info("changUserRedisLoginStatus,userid:"+userid)
        if(sessionId != "system"){
            this.emitSessionUsers(sessionId,userid,"online");
            if(status==1){
                this.emitSessionUsers(sessionId,userid,"online");
            }else if(status==0) {
                this.emitSessionUsers(sessionId,userid,"offline");
            }
        }else {
            if(status==0){
                let arr = userid.split("_");
                let userId = arr[arr.length-1]
                //修改用户状态
                Users.isPatientId(userId, function (err, isPatient) {
                    if (isPatient) {
                        log.info("修改患者状态"+status+"======"+userId)
                        Users.updatePatientStatus(userId,status);
                    } else {
                        log.info("修改医生状态"+status+"======"+userId)
                        Users.updateDoctorStatus(userId,status);
                    }
                });
            }else {
                //修改用户状态
                Users.isPatientId(userid, function (err, isPatient) {
                    if (isPatient) {
                        log.info("修改患者状态"+status+"======"+userid)
                        Users.updatePatientStatus(userid,status);
                    } else {
                        log.info("修改医生状态"+status+"======"+userid)
                        Users.updateDoctorStatus(userid,status);
                    }
                });
            }
        }
    }
@ -306,6 +338,18 @@ class Participants extends RedisModel {
                            if(pc_patientClient){
                                pc_patientClient.socket.emit('message', message);
                            }
                            /*Users.updatePatientStatus(participant.id,status,function(err,sqlResult){
                                if(handler){
                                    handler(err,sqlResult);
                                    return;
                                }
                                if(err){
                                    logger.error("set session status to mysql is error !");
                                }else{
                                    logger.info("set session status is success");
                                    ModelUtil.emitOK(self.eventEmitter, []);
                                }
                            });*/
                        } else {
                            log.info("emitSessionUsers:isdoctor"+participant.id);
                            let doctorClient = clientCache.findByIdAndType(participant.id,SOCKET_TYPES.DOCTOR);
@ -316,6 +360,19 @@ class Participants extends RedisModel {
                            if(pc_doctorClient){
                                pc_doctorClient.socket.emit('message',message);
                            }
                            /*log.info("修改医生状态"+status+"======"+participant.id)
                            Users.updateDoctorStatus(participant.id,status,function(err,sqlResult){
                                if(handler){
                                    handler(err,sqlResult);
                                    return;
                                }
                                if(err){
                                    logger.error("set session status to mysql is error !");
                                }else{
                                    logger.info("set session status is success");
                                    ModelUtil.emitOK(self.eventEmitter, []);
                                }
                            });*/
                        }
                    });
                })

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

@ -2128,6 +2128,7 @@ class Sessions extends RedisModel {
                message.sessionType = sessionType;
                message.targetType = 'patient';
            } else {
                log.info("targetUserId1=="+targetUserId);
                if(sessionType==SESSION_TYPES.P2P){
                     WechatClient.sendReadDoctorByDoctorId(targetUserId, message);
                }

+ 38 - 0
src/server/models/user/users.js

@ -28,6 +28,7 @@ let log = require('../../util/log');
let configFile = require('../../include/commons').CONFIG_FILE;
let config = require('../../resources/config/' + configFile);
const DB_TABLES = require('../../include/commons').DB_TABLES;
const REDIS_KEYS = require('../../include/commons').REDIS_KEYS;
const PLATFORMS = require('../../include/commons').PLATFORM;
const SESSION_TYPE = require('../../include/commons').SESSION_TYPES;
@ -384,6 +385,43 @@ class Users extends RedisModel {
                callback(null, res !== 0);
            });
    }
    /**
     * 更新患者在线状态
     *
     * @param userId
     * @param callback
     */
    static updatePatientStatus(userId,online, handler) {
        let sql = "update " + DB_TABLES.Patients + " set online=? where id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [online, userId],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
    /**
     * 更新医生在线状态
     * @param userId
     * @param online
     * @param handler
     */
    static updateDoctorStatus(userId,online, handler) {
        let sql = "update " + DB_TABLES.Doctors + " set online=? where id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [online, userId],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
}
let Promises = require('bluebird');

+ 6 - 0
src/server/resources/config/config.test.js

@ -74,6 +74,12 @@ let topicConfig = {
    TERMINATING_CRON: "* 30 * * * *"        // 议题自动关闭的任务执行时间间隔
};
//IM 客户端医院参数配置
let imClientType = {
    id : "zsyy",
    url : "https://hlwyy.xmzsh.com"
}
exports.environment = 'test';
exports.pubChannel = 'test';
exports.subChannel = 'dev';