Bladeren bron

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

LAPTOP-KB9HII50\70708 1 jaar geleden
bovenliggende
commit
9cf13b97e3

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

@ -685,4 +685,21 @@ router.get(APIv2.Sessions.SessionUnreadMessageCount, function (req, res) {
});
/**
 * 获取所有会话未读消息数。
 *
 * 请求URL:/sessions/unread_message_count?user_id=xyz&type=1
 */
router.get(APIv2.Sessions.SessionsUnreadMessageCountByBussinessType, function (req, res) {
    let userId = req.query.user_id;
    let businessType = req.query.business_type;
    let status= req.query.status
    let sessions = new Sessions();
    ControllerUtil.regModelEventHandler(sessions, res);
    sessions.getAllSessionsUnreadMessageCountByStatus(userId,businessType,status);
});
module.exports = router;

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

@ -202,6 +202,7 @@ const CONTENT_TYPES = {
    KnowSymptomsDiseaseQ:3006,//知识库-疾病症状问题
    KnowSymptomsDiseaseA:3007,//知识库-疾病症状回答
    KnowCommonCustomer:3008,//知识库-客服欢迎
    ForwardChat:3009,//转发聊天
    typeToDescription: function (type, defaultDescription) {
        if (CONTENT_TYPES.Image == type) {
            return '[图片]';

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

@ -64,6 +64,7 @@ const APIv2 = {
        MessageUpdate: '/:session_id/messages/:message_id/update',      // 更新消息内容(消息里有i健康业务状态时)
        SessionsUnreadMessageCount: '/unread_message_count',            // 所有会话的未读消息数
        SessionsUnreadMessageCountByBussinessType: '/unread_message_count_business_type',            // 所有会话的未读消息数
        SessionUnreadMessageCount: '/:session_id/unread_message_count', // 指定会话的未读消息数
        SessionUnreadMessages: '/:session_id/messages/unread',          // 会话未读消息

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

@ -97,7 +97,8 @@ class WechatClient extends RedisModel {
            message.content_type==CONTENT_TYPES.KnowSymptomsDisease||
            message.content_type==CONTENT_TYPES.KnowSymptomsDiseaseQ||
            message.content_type==CONTENT_TYPES.KnowSymptomsDiseaseA||
            message.content_type==CONTENT_TYPES.KnowCommonCustomer
            message.content_type==CONTENT_TYPES.KnowCommonCustomer||
            message.content_type==CONTENT_TYPES.ForwardChat
            )) {
            let patientClient = clientCache.findById(targetUserId);
            let pc_patientClient = clientCache.findById("pcpatient_"+targetUserId);

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

@ -1952,6 +1952,131 @@ class Sessions extends RedisModel {
        }
    }
    /**
     * 获取所有会话的未读消息数。
     */
    getAllSessionsUnreadMessageCountByStatus(userId,businessType,status,handler) {
        let self = this;
        let count = 0;
        let patientCount = 0;
        let doctorCount = 0;
        let patientEndCount = 0;
        SessionRepo.findAllByTypeAndStatusAndNoPage(userId,businessType, status,function (err, res) {
            // SessionRepo.findUnEndAll(userId, function (err, res) {
            if (err) {
                if (handler) {
                    handler(err, res);
                    return;
                }
                ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
                return;
            }
            if (res && res.length == 0) {
                if (handler) {
                    handler(err, count);
                    return;
                }
                ModelUtil.emitOK(self.eventEmitter, {count: count});
                return;
            }
            /*let has = false;*/
            for (let j in res) {
                /* has = false;
                 //是否过滤指定类型
                 if( type != null){
                     let typeString = type.split(",");
                     var str = res[j].type;
                     var str1 = str.toString();
                     if(typeString.indexOf(str1)<0){
                         continue;
                     }
                 }*/
                //logger.info("type==="+res[j].type);
                if (res[j].type == SESSION_TYPES.SYSTEM) {
                    if (j == res.length - 1) {
                        if (handler) {
                            handler(err, count);
                            return;
                        }
                        ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount, doctor: doctorCount});
                    }
                    continue;
                }
                callback(res, j, res[j]);
                /*      has = true*/
            }
            /* if(!has){
                 ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: 0, doctor: doctorCount});
             }*/
        });
        /*function callback(res, j, session) {
            self.getSessionUnreadMessageCount(res[j].id, userId, function (err, con) {
                if (err) {
                    if(handler)
                    {
                        handler(err,count);
                        return;
                    }
                    ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
                }
                count = count + con;
                if (session.business_type == SESSION_BUSINESS_TYPE.PATIENT) {
                    if(session.status == SESSION_STATUS.ENDED){//新增判断是否咨询结束
                        patientEndCount = patientEndCount + con;
                    }else{
                        patientCount = patientCount + con;
                    }
                } else {
                    doctorCount = doctorCount + con;
                }
                if (j == res.length - 1) {
                    if(handler)
                    {
                        handler(err,count)
                        return;
                    }
                    ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: patientEndCount, doctor: doctorCount});
                }
            })
        }*/
        function callback(res, j, session) {
            self.getSessionUnreadMessageCount(res[j].id, userId, function (err, con) {
                if (err) {
                    if(handler)
                    {
                        handler(err,count);
                        return;
                    }
                    ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
                }
                count = count + con;
                if (session.business_type == SESSION_BUSINESS_TYPE.PATIENT) {
                    if(session.status == SESSION_STATUS.ENDED){//新增判断是否咨询结束
                        patientEndCount = patientEndCount + con;
                    }else{
                        patientCount = patientCount + con;
                    }
                } else {
                    doctorCount = doctorCount + con;
                }
                if (j == res.length - 1) {
                    if(handler)
                    {
                        handler(err,count)
                        return;
                    }
                    ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: patientEndCount, doctor: doctorCount});
                }
            })
        }
    }
    /**
     * 获取会话的未读消息数。根据成员最后一次获取消息的时候与当前时间。
     *

+ 56 - 0
src/server/repository/mysql/session.repo.js

@ -317,6 +317,62 @@ class SessionRepo {
    }
    static findAllByTypeAndStatusAndNoPage(userId, businessType,status,handler) {
        let sessionSQL ="";
        let sql ="";
        if(status == SESSION_STATUS.ENDED){
            if(businessType == SESSION_BUSINESS_TYPE.PATIENT){//区分居民,有未读消息的置顶排列
                //找出已经结束的咨询
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select s.* from " + DB_TABLES.Sessions + " s, " + DB_TABLES.Participants + " p " +
                    " where ((s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)) " +
                    // " and s.id = p.session_id and p.participant_id = ? ORDER BY (p.last_fetch_time - s.last_message_time+1)>0,s.create_date desc limit "+page+","+pagesize;
                    " and s.id = p.session_id and p.participant_id = ? ORDER BY s.last_message_time desc ";
                ImDb.execQuery({
                    "sql": sessionSQL,
                    "args": [userId, businessType,userId,businessType,userId],
                    "handler": handler || function (err, res) {
                        if(err) log.error(err);
                    }
                });
            }else{
                //找出已经结束的咨询
                sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
                //找出角色讨论组中为旁听且未结束的咨询
                let sql1 = ("select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.REGULAR+" group by w.session_id")
                sessionSQL =  "select * from "
                    + DB_TABLES.Sessions + " s where (s.id in(" + sql + ") and s.business_type = ? and s.status = 1) or (s.id in(" + sql1 + ") and s.business_type = ? and s.status = 0)  ";
                log.info("findAllByTypeAndStatus: sql " + sessionSQL);
                log.info("findAllByTypeAndStatus: args " + [userId, businessType,userId,businessType]);
                ImDb.execQuery({
                    "sql": sessionSQL,
                    "args": [userId, businessType,userId,businessType],
                    "handler": handler || function (err, res) {
                        if(err) log.error(err);
                    }
                });
            }
        }else{
            sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ? and participant_role ="+PARTICIPANT_ROLES.HOST+" group by w.session_id";
            sessionSQL =  "select * from "
                + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.business_type in (?) and s.status = ? ";
            log.info("findAllByTypeAndStatus: sql : "+sessionSQL);
            log.info("findAllByTypeAndStatus: args : "+[userId, businessType,status]);
            ImDb.execQuery({
                "sql": sessionSQL,
                "args": [userId, businessType.split(","),status],
                "handler": handler || function (err, res) {
                    if(err) log.error(err);
                }
            });
        }
    }
    static findAllByType(userId, businessType,page,pagesize, handler) {
        if (page > 0) {
            if (page == 1) {

+ 147 - 0
src/server/resources/config/config.prod_mlwyy.js

@ -0,0 +1,147 @@
"use strict";
let imDbConfig = {
    host: '172.26.0.114',
    user: 'root',
    port:3306,
    password: '4D^tK%!4',
    database: 'im',
    connectionLimit: '100',
    charset : 'utf8mb4'
};
// Redis
let redisConfig = {
    host: '172.26.0.253',
    port: 6390,
    db: 1,
    password:'Kb6wKDQP1W4'
};
// let redisConfig = {
//     host: '192.0.33.26',
//     port: 6380,
//     db: 1,
//     password:'Kb6wKDQP1W4'
// };
// 内网Redis
let innerRedisConfig = {
    host: '172.26.0.253',
    port: 6390,
    db: 1,
    password:'Kb6wKDQP1W4'
};
// 三师后台
let wlyyServerConfig = {
    host: 'www.xmtyw.cn',
    port: 80,
    model:"/wlyy"
};
//医生助手配置
let wlyyDAServerConfig = {
    host: '192.168.120.167',
    port: 5550,
    model:"/assistant"
};
// 个推AppStore版参数
let getTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'qWmRh2X88l7HuE36z3qBe8',
    APPKEY: 'EzERfV8c849lBkZqHWzQG1',
    MASTERSECRET: 'veXiajQrId6iojy7Qv8kZ2'
};
// 微信配置
let wechatConfig = {
    appId: 'wxad04e9c4c5255acf',
    appSecret: 'ae77c48ccf1af5d07069f5153d1ac8d3',
    token: '27eb3bb24f149a7760cf1bb154b08040',
    accId: 'gh_ffd64560fb21',
    baseUrl: 'www.xmtyw.cn/wlyy',
    template: {
        consultTemplate: '0mF_vHj-ILx8EH8DwzmAi7LqzjqYiU9IrSRRmziTZyc'  // 咨询回复模板
    }
};
//  第三方微信(模版消息/个推消息)接口配置
//中山医院
let thirdApiMessageConfig = {
    host: '172.16.1.42',
    port: 10023,
    model:"/mqsdk",
    enpoint :"/ehospitalNotice"
};
//  第三方微信(模版消息/个推消息)接口配置
// 厦门i健康模板消息
let xmIjkTemplateConfig = {
    host: 'www.xmtyw.cn',
    port: 80,
    model:"/wlyy",
    enpoint :"/im/common/message/sendWxTemple"
};
//企业微信模版消息
let hlwyyDAServerConfig = {
    host: '172.16.1.42',
    port: 10023,
    model:"/enterprise",
    enpoint :"/sendMKMesByDoctor"
};
// 会话配置
let sessionConfig = {
    maxMessageCount: 1000,                  // 会话缓存的消息数量
    maxMessageTimespan: 7 * 24 * 3600,      // 会话缓存的最大时间跨度
    expireTime: 3 * 60 * 60 * 1000,         // 会话过期时间,以毫秒计
    expireSessionCleanCount: 10             // 每次清理多少个过期会话
};
// 议题配置
let topicConfig = {
    TTL: 24,                                // 议题的存活时间,TTL = Time To Live
    TERMINATING_CRON: "* 59 * * * *"        // 议题自动关闭的任务执行时间间隔
};
//IM 客户端医院参数配置
let imClientType = {
    id : "xm_mlwyy_wx",
    url : "https://hlwyy.xmzsh.com"
}
let httpsConfig = {
    key : "./https/zsyy/server.key",
    pem: "./https/zsyy/xmzsh.pem"
}
exports.environment = 'prod';
exports.pubChannel = 'phone_to_pc';
exports.subChannel = 'pc_to_phone';
exports.pubSubSwitch = true;
exports.app = 'im.server';
exports.version = '2.0.0';
exports.debug = true;
exports.serverPort = 3000;
exports.sessionExpire = 1800;
exports.showSQL = false;
exports.httpsOpen = true;
exports.imDbConfig = imDbConfig;
exports.redisConfig = redisConfig;
exports.innerRedisConfig = innerRedisConfig;
exports.getTuiConfig = getTuiConfig;
exports.wlyyServerConfig = wlyyServerConfig;
exports.wlyyDAServerConfig = wlyyDAServerConfig;
exports.hlwyyDAServerConfig = hlwyyDAServerConfig;
exports.wechatConfig = wechatConfig;
exports.thirdApiMessageConfig = thirdApiMessageConfig;
exports.sessionConfig = sessionConfig;
exports.topicConfig = topicConfig;
exports.imClientType = imClientType;
exports.xmIjkTemplateConfig = xmIjkTemplateConfig
exports.httpsConfig = httpsConfig