Browse Source

代码修改

yeshijie 6 years ago
parent
commit
2669c37566

+ 12 - 0
readme.md

@ -258,3 +258,15 @@ select m.`timestamp` as begin_date,m2.`timestamp` as end_date,t.session_id from
###更改NODE插件数据源在安装完成NODE及配置完成环境变量后执行
    npm config set registry https://registry.npm.taobao.org
    设置完成后执行npm install 即可安装相对于的插件。
##专科医生的业务
1、专科医生和家庭医生聊天
 session_id : 居民code+"_"+专科医生行政团队code
 session_name : 某居民-共管对话
 session_type : 5
2.修改会话名称
/api/v2/sessions/:session_id/name
post请求
入参:sessionId:会话id
     name:新的会话名称

+ 22 - 3
src/server/endpoints/v2/session.endpoint.js

@ -177,6 +177,25 @@ router.post(APIv2.Sessions.SessionStatus, function (req, res) {
    sessions.updateSessionStatus(sessionId, status);
});
/**
 * 修改会话名称(修改redis和数据库)
 *
 * 请求URL /name?name=哈哈&sessionId=testsessionmsg1
 */
router.post(APIv2.Sessions.SessionName, function (req, res) {
    let sessionId = req.body.sessionId;
    let name = req.body.name;
    if (!sessionId) {
        throw {httpStatus: 406, message: 'Missing sessionId.'};
    }
    if (!name) {
        throw {httpStatus: 406, message: 'Missing name.'};
    }
    let sessions = new Sessions();
    ControllerUtil.regModelEventHandler(sessions, res);
    sessions.updateSessionName(sessionId, name);
});
/**
 * 取消置顶
@ -268,18 +287,18 @@ router.post(APIv2.Sessions.ParticipantUpdate, function (req, res) {
 * sessionId 会话ID
 */
router.delete(APIv2.Sessions.Participant, function (req, res) {
    let user = req.query.user;
    let user = req.params.participant_id;
    if (!user) {
        throw {httpStatus: 406, message: 'Missing user.'};
    }
    let sessionId = req.query.sessionId;
    let sessionId = req.params.session_id;
    if (!sessionId) {
        throw {httpStatus: 406, message: 'Missing sessionId.'};
    }
    let participants = new Participants();
    ControllerUtil.regModelEventHandler(sessions, res);
    ControllerUtil.regModelEventHandler(participants, res);
    participants.removeUser(sessionId, user);
});

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

@ -18,7 +18,7 @@ if (process.env.IM_PROFILE === "prod") {
} else if (process.env.IM_PROFILE === "test") {
    configFile += "test";
} else {
    configFile += "dev";
    configFile += "test";
}
exports.CONFIG_FILE = configFile;
@ -32,6 +32,7 @@ const SESSION_TYPES = {
    P2P: 2,             // P2P
    GROUP: 3,           // 固定组
    DISCUSSION: 4,       // 临时讨论组
    SPECIALISTGROUP: 5,       // 专科医生和家庭医生的固定组
    PRESCRIPTION: 8       // 续方
};
@ -226,6 +227,8 @@ const DB_TABLES = {
            return DB_TABLES.DiscussionMessages;
        else if (sessionType == SESSION_TYPES.PRESCRIPTION)
            return DB_TABLES.MucMessages;
        else if (sessionType == SESSION_TYPES.SPECIALISTGROUP)
            return DB_TABLES.GroupMessages;
        else throw {message: "Unknown session type"};
    }
};

+ 5 - 4
src/server/include/endpoints.js

@ -26,13 +26,14 @@ const APIv2 = {
    Sessions: {
        Base: '/api/v2/sessions',
        Session: '/:session_id/session',                                //获取会话
        Session: '/:session_id/session',                                // 获取会话
        SessionSticky: '/:session_id/sticky',                           // 会话置顶,置顶使用PUT,取消置顶使用DELETE
        SessionStatus: '/:session_id/status',                           //更新状态
        SessionStatus: '/:session_id/status',                           // 更新状态
        SessionName: '/:session_id/name',                               // 更新会话名称
        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话
        IsExist: '/isExist',                                            // 判断会话是否存在(i健康发送muc的im消息会话前会先调用创建会话的方法,这个方法会更新redis中每个成员的最后获取时间,导致未读消息不准)
        Topics: '/:topic_id/topics',                                    //获取单个议题
        Topics: '/:topic_id/topics',                                    // 获取单个议题
        Topic: '/topics/:topic_id',                                     // 议题,指定ID的议题将返回其信息
        TopicEnded: '/:session_id/topics/:topic_id/ended',              // 议题是否已结束,若top_id为current,则检查最后一个议题的状态
        TopicInto: '/:session_id/topics/:topic_id/into',                // 居民进入议题
@ -54,7 +55,7 @@ const APIv2 = {
        ParticipantUpdate:'/:session_id/participant/update',            //更新成员=删除旧成员,新增新成员
        Participants: '/:session_id/participants',                      // 会话所有成员
        ParticipantsAvatar: '/:session_id/participants/avatars',        // 会话所有成员头像
        Participant: '/:session_id/participants/:participant_id',       // 会话单个成员
        Participant: '/:session_id/participants/:participant_id',       // 会话单个成员(多个participant_id 用英文逗号间隔)
        ParticipantAvatar: '/:session_id/participants/:participant_id/avatars'  // 会话单个成员头像
    },
    Search: {

+ 10 - 10
src/server/models/client/app.client.js

@ -19,6 +19,7 @@ let redisConn = RedisClient.redisClient().connection;
const CONTENT_TYPES = require('../../include/commons').CONTENT_TYPES;
const SESSION_TYPES = require('../../include/commons').SESSION_TYPES;
const MESSAGE_BUSSINESS_TYPE = require('../../include/commons').MESSAGE_BUSSINESS_TYPE;
const REDIS_KEYS = require('../../include/commons').REDIS_KEYS;
const PLATFORMS = require('../../include/commons').PLATFORM;
@ -39,7 +40,8 @@ class AppClient extends RedisModel {
        let userStatusKey = RedisModel.makeRedisKey(REDIS_KEYS.UserAppStatus, userId);
        redisConn.hgetAsync(userStatusKey, 'app_in_bg').then(function (res) {
            if (res !== null) {
                redisConn.hsetAsync(userStatusKey, 'app_in_bg', appInBg ? 1 : 0).then(function (res) {
                // redisConn.hsetAsync(userStatusKey, 'app_in_bg', appInBg ? 1 : 0).then(function (res) {
                redisConn.hsetAsync(userStatusKey, 'app_in_bg', appInBg).then(function (res) {
                    if (handler) {
                        handler(null, true);
                    } else {
@ -170,12 +172,16 @@ class AppClient extends RedisModel {
                }
                var session_type = isNaN(Number(sessionType))?sessionType:Number(sessionType);
                if(session_type==SESSION_TYPES.SYSTEM||
                    session_type==SESSION_TYPES.MUC||
                if( session_type==SESSION_TYPES.MUC||
                    session_type==SESSION_TYPES.P2P||
                    session_type==SESSION_TYPES.GROUP||
                    session_type==SESSION_TYPES.DISCUSSION||
                    session_type==SESSION_TYPES.PRESCRIPTION){
                    session_type==SESSION_TYPES.SPECIALISTGROUP||
                    session_type==SESSION_TYPES.PRESCRIPTION||
                    message.business_type == MESSAGE_BUSSINESS_TYPE.D_CT_01||
                    message.business_type == MESSAGE_BUSSINESS_TYPE.D_CT_02||
                    message.business_type == MESSAGE_BUSSINESS_TYPE.D_CT_03||
                    message.business_type == MESSAGE_BUSSINESS_TYPE.D_CT_04){
                    //是否发送消息
                    MessageNoticeSettingRepo.findOne(targetId,'1',function (err,res) {
                        if(res&&res.length>0){
@ -203,12 +209,6 @@ class AppClient extends RedisModel {
                    AppClient.sendNotice(targetId, message, sessionType,badge,userStatus)
                }
                // let pc_doctorClient = clientCache.findByIdAndType("pc_"+targetId,SOCKET_TYPES.PC_DOCTOR);
                // if(pc_doctorClient){
                //     log.warn("User's pc is online, user id: " + targetId + ", we cannot send getui.");
                //     return;
                // }
            });
        }
    }

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

@ -210,7 +210,16 @@ class Participants extends RedisModel {
    addUser(sessionId, user,role,handler) {
        let self = this;
        if(!role)role = 0;
        let users = [user+":"+role];
        let users = [];
        if(user.split(",").length==1){
            users = [user+":"+role];
        }else {
            //添加多个成员
            let participants = user.split(",");
            for (let j in participants) {
                users.push( participants[j] +":0");
            }
        }
        Participants.saveParticipantsToRedis(sessionId, users, new Date(), function (res) {
            if (res) {
                Participants.saveParticipantsToMysql(sessionId, users,function(err,res){

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

@ -66,6 +66,7 @@ class Sessions extends RedisModel {
                }
                ModelUtil.emitError(self.eventEmitter, {message: err, status: -1}, null);
            } else {
                name = res.name;
                //创建session到redis
                self.createSessionToRedis(sessionId, name, type, participantArray, messageId, function (err, res) {
                    if (err) {
@ -196,6 +197,8 @@ class Sessions extends RedisModel {
        function callBusinessType() {
            if(type==SESSION_TYPES.MUC||type==SESSION_TYPES.PRESCRIPTION){
                callCreateSession(SESSION_BUSINESS_TYPE.PATIENT);
            }else if(type==SESSION_TYPES.SPECIALISTGROUP){
                callCreateSession(SESSION_BUSINESS_TYPE.DOCTOR);
            }else{
                ParticipantRepo.getBusinessType(participantIdArray, function (err, businessType) {
                    if (err) {
@ -212,6 +215,8 @@ class Sessions extends RedisModel {
            //查找该sessionId是否存在存在则直接返回实例
            SessionRepo.findOne(sessionId, function (err, res) {
                if (res.length > 0) {//已经存在
                    //已存在的会话不修改名称
                    name = res[0].name;
                    //更新成员
                    Participants.saveParticipantsToMysql(sessionId, participantArray, function (err, update) {
                        handler(null, res[0]);
@ -1721,6 +1726,32 @@ class Sessions extends RedisModel {
    }
    /**
     * 针对专科医生和家医模式更新会话的名称
     * @param sessionId
     * @param name
     */
    updateSessionName(sessionId,name,handler){
        let self = this;
        let sessionKey  =  RedisModel.makeRedisKey(REDIS_KEYS.Session,sessionId);
        redis.hsetAsync(sessionKey,"name",name).then(function(res){
            SessionRepo.updateSessionName(sessionId,name,function(err,sqlResult){
                if(handler){
                    handler(err,sqlResult);
                    return;
                }
                if(err){
                    logger.error("set session name to mysql is error !");
                    ModelUtil.emitError(self.eventEmitter,"set session name to mysql is error !",err)
                }else{
                    logger.info("set session name is success");
                    ModelUtil.emitOK(self.eventEmitter, []);
                }
            });
        });
    }
}
// Expose class

+ 3 - 3
src/server/repository/mysql/search.repo.js

@ -115,7 +115,7 @@ class SearchRepo {
            " u,sessions s WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or u.idcard like ?) ";
        if (userTable === DB_TABLES.Doctors) {
            sql += " AND s.type in (2) and s.business_type = 1 ";
            sql += " AND s.type = 2 and s.business_type = 1 ";
        }else{
            sql += " AND s.type in (1,2,8)  and s.business_type = 2 ";
        }
@ -141,7 +141,7 @@ class SearchRepo {
        let sql = "SELECT * FROM(" +
            "SELECT s.id, s.name, s.type, s.create_date, s.business_type,GROUP_CONCAT(u. NAME) as participant_name " +
            "FROM sessions s,  doctors u ,participants p " +
            "WHERE s.id IN (?) and s.type = 3 AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or s.name like ?) group by s.id " +
            "WHERE s.id IN (?) and s.type in (3,5) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or s.name like ?) group by s.id " +
            ") X LIMIT ?, ?";
        keyword = '%' + keyword + '%';
@ -167,7 +167,7 @@ class SearchRepo {
            " UNION " +
            "SELECT s.id session_id, s.name session_name, s.type session_type, s.business_type session_business_type, m.id message_id, m.sender_id, m.sender_name, m.timestamp, m.content " +
            "FROM sessions s, group_messages m " +
            "WHERE s.id IN (?) AND s.id = m.session_id AND s.`type` = 3 AND m.content_type = 1 AND m.content LIKE ? ) X " +
            "WHERE s.id IN (?) AND s.id = m.session_id AND s.`type` in (3,5) AND m.content_type = 1 AND m.content LIKE ? ) X " +
            "ORDER BY X.session_id, X.message_id LIMIT ?, ?";
        keyword = '%' + keyword + '%';

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

@ -333,6 +333,17 @@ class SessionRepo {
            }
        });
    }
    static updateSessionName(sessionId,name,handler){
        let sql = "update " + DB_TABLES.Sessions + " set name=? where id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [name, sessionId],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
}
module.exports = SessionRepo;

+ 25 - 53
src/server/resources/config/config.dev.js

@ -1,53 +1,43 @@
"use strict";
// IM数据库配置
let imDbConfig = {
    host: '172.19.103.85',
    user: 'linzhou',
    password: 'linzhou',
    host: '172.19.103.77',
    user: 'root',
    password: '123456',
    database: 'im_new',
    connectionLimit: '50',
    charset: 'utf8mb4'
};
// let imDbConfig = {
//     host: '172.19.103.77',
//     user: 'root',
//     password: '123456',
//     database: 'im_new',
//     connectionLimit: '50',
//     charset: 'utf8mb4'
// };
// Redis
let redisConfig = {
    host: '172.19.103.88',
    port: 6379,
    db: 1
    db: 6
};
// let redisConfig = {
//     host: '192.168.1.220',
//     port: 6379,
//     db: 1
// };
// 内网Redis
let innerRedisConfig = {
    host: '172.19.103.88',
    port: 6379,
    db: 1
    db: 6
};
// 三师后台
let wlyyServerConfig = {
    host: '172.19.103.88',
    port: 9092,
    model:"/wlyy"
    host: '172.19.103.72',
    port: 9096,
    model:"/csijk"
};
// let wlyyServerConfig = {
//     host: '192.168.131.24',
//     port: 8086,
//     model:"/"
// };
//医生助手配置
let wlyyDAServerConfig = {
    host: '192.168.131.113',
    port: 8080,
    model:"/"
    host: '172.19.103.88',
    port: 9092,
    model:"/wlyy"
};
// 个推AppStore版参数
@ -58,29 +48,12 @@ let getTuiConfig = {
    MASTERSECRET: 'pvjCGtRZJx9SRVODkxc816'
};
// let getTuiConfig = {
//     HOST: 'https://api.getui.com/apiex.htm',
//     APPID: 'DKgbGvbacm74nJJzen5ilA',
//     APPSECRET: '4kGcL7e7kU6mbSqfEGZFW7',
//     APPKEY: 'ArZfS2qvoA7N3hawOAGVC5',
//     MASTERSECRET: '9lpy5vEss46tVzP1RCJiC4'
// };
// 微信配置
// let wechatConfig = {
//     appId: 'wxd03f859efdf0873d',
//     appSecret: '2935b54b53a957d9516c920a544f2537',
//     token: '27eb3bb24f149a7760cf1bb154b08040',
//     baseUrl: 'weixin.xmtyw.cn/wlyy',
//     template: {
//         consultTemplate: 'qSOW0DBxO3qEBm4ucG0Ial0jxsOyD7_f2TFK5e-mQEc'  // 咨询回复模板
//     }
// };
// 微信配置
let wechatConfig = {
    appId: 'wx1f129f7b51701428',
    appSecret: '988f005d8309ed1795939e0f042431fb',
    token: '27eb3bb24f149a7760cf1bb154b08040',
    accId: 'gh_ffd64560fb21',
    baseUrl: 'ehr.yihu.com/wlyy',
    template: {
        consultTemplate: '-dr4QNyFoRvVsf8uWxXMC1dRyjwnbUuJwJ21vBLhf18'  // 咨询回复模板
@ -89,25 +62,24 @@ let wechatConfig = {
// 会话配置
let sessionConfig = {
    maxMessageCount: 2000,                  // 会话缓存的消息数量
    maxMessageCount: 1000,                  // 会话缓存的消息数量
    maxMessageTimespan: 7 * 24 * 3600,      // 会话缓存的最大时间跨度
    expireTime: 3 * 60 * 60 * 1000,         // 会话过期时间,以毫秒计
    expireSessionCleanCount: 10              // 每次清理多少个过期会话
    expireSessionCleanCount: 10             // 每次清理多少个过期会话
};
// 议题配置
let topicConfig = {
    TTL: 24,                                 // 议题的存活时间,TTL = Time To Live
    TERMINATING_CRON: "* 44 * * * *"     // 议题自动关闭的任务执行时间间隔
    TTL: 24,                                // 议题的存活时间,TTL = Time To Live
    TERMINATING_CRON: "* 30 * * * *"        // 议题自动关闭的任务执行时间间隔
};
exports.environment = 'dev';
exports.pubChannel = 'dev';
exports.subChannel = 'test';
exports.environment = 'test';
exports.pubChannel = 'test';
exports.subChannel = 'dev';
exports.pubSubSwitch = false;
exports.app = 'IM.Server';
exports.app = 'im.server';
exports.version = '2.0.0';
exports.debug = true;
exports.serverPort = 3000;

+ 1 - 0
src/server/resources/config/config.prod.js

@ -58,6 +58,7 @@ let wechatConfig = {
    appId: 'wxad04e9c4c5255acf',
    appSecret: 'ae77c48ccf1af5d07069f5153d1ac8d3',
    token: '27eb3bb24f149a7760cf1bb154b08040',
    accId: 'gh_ffd64560fb21',
    baseUrl: 'www.xmtyw.cn/wlyy',
    template: {
        consultTemplate: '0mF_vHj-ILx8EH8DwzmAi7LqzjqYiU9IrSRRmziTZyc'  // 咨询回复模板

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

@ -1,11 +1,11 @@
"use strict";
let imDbConfig = {
    host: '172.17.110.160',
    user: 'ssgg',
    password: 'ssgg',
    host: '172.19.103.85',
    user: 'linzhou',
    password: 'linzhou',
    database: 'im_new',
    connectionLimit: '100',
    connectionLimit: '50',
    charset: 'utf8mb4'
};
@ -53,6 +53,7 @@ let wechatConfig = {
    appId: 'wx1f129f7b51701428',
    appSecret: '988f005d8309ed1795939e0f042431fb',
    token: '27eb3bb24f149a7760cf1bb154b08040',
    accId: 'gh_ffd64560fb21',
    baseUrl: 'ehr.yihu.com/wlyy',
    template: {
        consultTemplate: '-dr4QNyFoRvVsf8uWxXMC1dRyjwnbUuJwJ21vBLhf18'  // 咨询回复模板
@ -76,7 +77,7 @@ let topicConfig = {
exports.environment = 'test';
exports.pubChannel = 'test';
exports.subChannel = 'dev';
exports.pubSubSwitch = true;
exports.pubSubSwitch = false;
exports.app = 'im.server';
exports.version = '2.0.0';