Parcourir la source

成员变化的时候时间更新为空问题处理

il y a 8 ans
Parent
commit
39bc818460

+ 12 - 4
src/server/models/search/object.searcher.js

@ -40,6 +40,14 @@ class ObjectSearcher extends RedisModel {
                    }
                },
                function (sessionIdList, keyword, targetRole, entityType, callback) {
                    var sessionList=[];
                    for(var j in sessionIdList){
                        sessionList.push(sessionIdList[j].id);
                    }
                    if(sessionList.length==0){
                        callback(null, "");
                        return;
                    }
                    if (targetRole !== 'doctor' && targetRole !== 'patient') {
                        ModelUtil.emitError(self.eventEmitter, "Unknown target role: " + targetRole);
                    }
@ -48,25 +56,25 @@ class ObjectSearcher extends RedisModel {
                    // 综合搜索与分类搜索
                    if (entityType === 'all') {
                        SearchRepo.searchAll(sessionIdList, keyword, userTable, function (err, res) {
                        SearchRepo.searchAll(sessionList, keyword, userTable, function (err, res) {
                            if (err) return callback(err, null);
                            callback(null, res);
                        });
                    } else if (entityType === 'user') {
                        SearchRepo.searchUser(sessionIdList, keyword, userTable, page, size, function (err, res) {
                        SearchRepo.searchUser(sessionList, keyword, userTable, page, size, function (err, res) {
                            if (err) return callback(err, null);
                            callback(null, {users: SearchRepo.userForge(res)});
                        });
                    } else if (entityType === 'session') {
                        SearchRepo.searchSessions(sessionIdList, keyword, page, size, function (err, res) {
                        SearchRepo.searchSessions(sessionList, keyword, page, size, function (err, res) {
                            if (err) return callback(err, null);
                            callback(null, {sessions: SearchRepo.sessionForge(res, keyword)});
                        });
                    } else if (entityType === 'message') {
                        SearchRepo.searchMessages(sessionIdList, keyword, page, size, function (err, res) {
                        SearchRepo.searchMessages(sessionList, keyword, page, size, function (err, res) {
                            if (err) return callback(err, null);
                            callback(null, {messages: SearchRepo.messageForge(res)});

+ 12 - 2
src/server/models/sessions/sessions.js

@ -353,6 +353,7 @@ class Sessions extends RedisModel {
                            .zscore(sessionParticipantsKey, userId)    // 用户在此会话中最后一次获取未读消息的时间
                            .zrange(sessionParticipantsKey, 0, -1)
                            .zrange(sessionParticipantsKey, 0,-1,'withscores')  // 所有用户在此会话中最后一次获取未读消息的时间
                            .hgetall(participantsRoleKey)  // 所有用户在此会话中最后一次获取未读消息的时间
                            .execAsync()
                            .then(function (res) {
                                let session = res[0];
@ -360,7 +361,15 @@ class Sessions extends RedisModel {
                                let lastFetchTime = res[2];
                                let users = res[3];
                                let participantsTimeArray = res[4];
                                let userRoles = res[5];
                                let participantsTime = [];
                                let isInvite = true;
                                for(var j in userRoles){
                                    if(userRoles[j]==1){
                                        isInvite = false;
                                        break;
                                    }
                                }
                                for(var j = 0 ;j<participantsTimeArray.length;j++){
                                    if(j%2!=0)continue;
                                    let participantsTimeJson = {};
@ -415,7 +424,8 @@ class Sessions extends RedisModel {
                                                sender_sex: sex,
                                                sender_birthday: bir,
                                                participantsTimeArray:participantsTime,
                                                status:session.status
                                                status:session.status,
                                                is_invite:isInvite
                                            });
                                            index = (parseInt(index) + 1);
@ -1228,7 +1238,7 @@ class Sessions extends RedisModel {
                logger.info("cancelStickSession:" + sessionId);
                ModelUtil.emitOK(self.eventEmitter, {});
            }).then(function () {
                SessionRepo.unstickSession(sessionId, user);
                SessionRepo.unStickySession(sessionId, user);
            });
        })
    }

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

@ -87,7 +87,7 @@ class Users extends RedisModel {
    login(userId, platform, deviceToken, clientId) {
        let self = this;
        let loginFromApp = platform !== PLATFORMS.Wechat;
        log.error(userId+"  "+ platform+"  "+deviceToken+"  "+clientId);
        let usersKey = REDIS_KEYS.Users;
        let userKey = RedisModel.makeRedisKey(REDIS_KEYS.User, userId);
        let userStatusKey = RedisModel.makeRedisKey(loginFromApp ? REDIS_KEYS.UserAppStatus : REDIS_KEYS.UserWechatStatus, userId);
@ -114,10 +114,10 @@ class Users extends RedisModel {
                     'birthdate', userInfo.birthdate ? ObjectUtil.timestampToLong(userInfo.birthdate) : '',
                     'name', userInfo.name,
                     'role', loginFromApp ? 'doctor' : 'patient');*/
                    console.error(loginFromApp);
                    if (loginFromApp) {
                        AppStatusRepo.save(userId, deviceToken, clientId, platform, function (err, res) {
                            if (err) log.error();
                            if (err) log.error(err);
                        });
                        // cache app status
@ -145,7 +145,7 @@ class Users extends RedisModel {
                },
                // cache sessions, participants, topics, messages
                function (callback) {
                    SessionRepo.findAll(userId, function (err, sessions) {
                    SessionRepo.findAllIgnoreRole(userId, function (err, sessions) {
                        if (err) {
                            ModelUtil.emitError(self.eventEmitter, err.message);
                            return;

+ 4 - 1
src/server/repository/mysql/app.status.repo.js

@ -49,7 +49,10 @@ class AppStatusRepo {
        ImDb.execQuery({
            sql: sql,
            args: [userId, platform, deviceToken, client_id, platform, deviceToken, client_id],
            handler: handler
            handler: function(err,res){
                console.error(sql);
                handler(err,res);
            }
        });
    };

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

@ -20,7 +20,7 @@ class SearchRepo {
    static findTopicEndedSessionIdList(userId, handler) {
        let sql = "SELECT s.id " +
            "FROM sessions s, topics t, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NOT NULL AND s.`type` IN (1) " +
            "WHERE p.participant_id = ? AND p.session_id = s.id AND s.id = t.session_id AND t.end_message_id IS NOT NULL AND s.`type` IN (1,2) " +
            " UNION " +
            "SELECT s.id " +
            "FROM sessions s, participants p " +
@ -92,7 +92,7 @@ class SearchRepo {
            " 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 += " AND s.type in (2,3) ";
        }
        sql += " limit ?, ? ";

+ 21 - 2
src/server/repository/mysql/session.repo.js

@ -31,7 +31,7 @@ class SessionRepo {
    }
    /**
     * 获取用户全部会话
     * 获取用户全部会话不包含角色未1的会话
     *
     * @param userId
     * @param handler
@ -49,6 +49,25 @@ class SessionRepo {
            }
        });
    }
    /**
     * 获取用户全部会话忽略角色
     *
     * @param userId
     * @param handler
     */
    static findAllIgnoreRole(userId, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
        let sys_session = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = 'system' and participant_role =0  group by w.session_id";
        let sessionSQL = "select id, name, type, create_date,business_type, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time,status from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and s.id not in ("+sys_session+")";
        ImDb.execQuery({
            "sql": sessionSQL,
            "args": [userId],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
    /**
     * 获取用户全部会话
@ -226,7 +245,7 @@ class SessionRepo {
     * @param sessionId
     * @param userId
     */
    static unstickSession(sessionId, userId) {
    static unStickySession(sessionId, userId) {
        let sql = "delete from " + DB_TABLES.StickySessions + " where user_id=? and session_id=? ";
        ImDb.execQuery({
            "sql": sql,

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

@ -19,8 +19,8 @@ let redisConfig = {
// 三师后台
let wlyyServerConfig = {
    host: '192.168.131.102',
    port: 8080,
    host: '192.168.131.104',
    port: 8090,
    model:""
};