Browse Source

Merge branch 'feature-refactor' of http://192.168.1.220:10080/Amoy/im.doctor into feature-refactor

8 years ago
parent
commit
d5a31443cb

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

@ -46,7 +46,7 @@ class SocketHandler {
                    users.login(data.userId, 10, '', '');
                    socketServer.sockets.emit('ack', {});
                    socket.emit('ack', {});
                }
            });

+ 16 - 10
src/server/models/client/wechat.client.js

@ -50,18 +50,24 @@ class WechatClient extends RedisModel {
    /**
     * 向微信端用户发送消息。若用户微信端在线,通过Web Socket推送给患者,如果不在线则通过微信的模板消息。
     *
     * 只推送文本、图片及语音消息
     *
     * @param targetUserId
     * @param message 消息
     * @param message 消息体
     */
    static sendMessage(targetUserId, message) {
        let patientClient = clientCache.findById(targetUserId);
        if (patientClient) {
            WechatClient.sendViaWebSocket(patientClient.socket, message);
        } else {
            log.info("User's wechat endpoint is not online, sending via wechat template message. User id: ", targetUserId);
            WechatClient.sendViaTemplateMessage(targetUserId, message);
        if (message.content_type == CONTENT_TYPES.PlainText ||
            message.content_type == CONTENT_TYPES.Image ||
            message.content_type == CONTENT_TYPES.Audio) {
            let patientClient = clientCache.findById(targetUserId);
            if (patientClient) {
                WechatClient.sendViaWebSocket(patientClient.socket, message);
            } else {
                log.info("User's wechat endpoint is not online, sending via wechat template message. User id: ", targetUserId);
                WechatClient.sendViaMessageTemplate(targetUserId, message);
            }
        }
    };
@ -83,7 +89,7 @@ class WechatClient extends RedisModel {
     * @param targetUserId
     * @param message
     */
    static sendViaTemplateMessage(targetUserId, message) {
    static sendViaMessageTemplate(targetUserId, message) {
        async.waterfall([
                // 获取微信openid
                function (callback) {

+ 11 - 11
src/server/models/user/users.js

@ -60,7 +60,7 @@ class Users extends RedisModel {
                        user.birthdate = res[0].birthdate;
                        user.avatar = res[0].avatar;
                        if(res[0].openid) user.openid = res[0].openid;
                        if (res[0].openid) user.openid = res[0].openid;
                    }
                    outCallback(null, user);
@ -108,11 +108,11 @@ class Users extends RedisModel {
                function (userInfo, callback) {
                    let multi = redisConn.multi()
                        .zadd(usersKey, lastLoginTime.getTime(), userId);
                        /*.hmset(userKey,
                            'avatar', userInfo.avatar ? userInfo.avatar : '',
                            'birthdate', userInfo.birthdate ? ObjectUtil.timestampToLong(userInfo.birthdate) : '',
                            'name', userInfo.name,
                            'role', loginFromApp ? 'doctor' : 'patient');*/
                    /*.hmset(userKey,
                     'avatar', userInfo.avatar ? userInfo.avatar : '',
                     'birthdate', userInfo.birthdate ? ObjectUtil.timestampToLong(userInfo.birthdate) : '',
                     'name', userInfo.name,
                     'role', loginFromApp ? 'doctor' : 'patient');*/
                    if (loginFromApp) {
                        // cache app status
@ -148,16 +148,16 @@ class Users extends RedisModel {
                        sessions.forEach(function (session) {
                            redisConn.zscore(REDIS_KEYS.Sessions, session.id, function (err, res) {
                                // 已经缓存过的会话不再缓存
                                if (res != null) return;
                                if (res != null) return;    // 已经缓存过的会话不再缓存
                                (function (sessionId, userId) {
                                    var business_type = session.business_type;
                                    if(!session.business_type&&session.type==SESSION_TYPE.MUC){
                                    let business_type = session.business_type;
                                    if (!session.business_type && session.type == SESSION_TYPE.MUC) {
                                        business_type = 2
                                    }else if(!session.business_type&&session.type!=SESSION_TYPE.MUC){
                                    } else if (!session.business_type && session.type != SESSION_TYPE.MUC) {
                                        business_type = 1
                                    }
                                    let redisSession = [
                                        "id", session.id,
                                        "name", session.name,

+ 7 - 2
src/server/repository/mysql/search.repo.js

@ -89,8 +89,13 @@ class SearchRepo {
    static searchUser(sessionIdList, keyword, userTable, page, size, handler) {
        let sql = "SELECT DISTINCT s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id, u.name user_name, u.sex, u.birthdate, u.avatar %s" +
            " FROM sessions s, participants p, " + userTable +
            " u WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id AND u.name like ? limit ?, ?";
            " u WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id AND u.name like ? ";
        if (userTable === DB_TABLES.Doctors) {
            sql += " AND s.type = 2 ";
        }
        sql += " limit ?, ? ";
        sql = vsprintf(sql, [userTable == DB_TABLES.Doctors ? ', hospital_name' : '']);
        keyword = '%' + keyword + '%';
@ -183,7 +188,7 @@ class SearchRepo {
                result.push(tempSession);
            }
            if(session.participant_name.indexOf(keyword) >= 0) tempSession.participants.push({name: session.participant_name});
            if (session.participant_name.indexOf(keyword) >= 0) tempSession.participants.push({name: session.participant_name});
        });
        return result;

+ 1 - 1
src/server/resources/config/config.dev.js

@ -62,7 +62,7 @@ let sessionConfig = {
// 议题配置
let topicConfig = {
    TTL: 24,                            // 议题的存活时间,TTL = Time To Live
    TERMINATING_CRON: "* 0 * * * *"     // 议题自动关闭的任务执行时间间隔
    TERMINATING_CRON: "* 30 * * * *"     // 议题自动关闭的任务执行时间间隔
};
exports.app = 'IM.Server';