Browse Source

修复议题bug

Sand 8 years ago
parent
commit
532b4ce246

+ 1 - 1
src/server/endpoints/v2/session.endpoint.js

@ -191,7 +191,7 @@ router.delete(APIv2.Sessions.Participant, function (req, res) {
    let participants = new Participants();
    ControllerUtil.regModelEventHandler(sessions, res);
    participants.deleteUser(sessionId, user);
    participants.removeUser(sessionId, user);
});
/**

+ 0 - 1
src/server/models/client/app.client.js

@ -6,7 +6,6 @@
let RedisClient = require('../../repository/redis/redis.client');
let RedisModel = require('./../redis.model');
let AppStatusRepo = require('../../repository/mysql/app.status.repo');
let ObjectUtil = require("../../util/object.util.js");
let ModelUtil = require('../../util/model.util');
let log = require("../../util/log.js");

+ 2 - 2
src/server/models/messages/messages.js

@ -56,7 +56,7 @@ class Messages extends RedisModel {
     * @param sessionId
     * @param page
     * @param pagesize
     * @param handler
     * @param messageType
     */
    getMessageByType(sessionId, page, pagesize, messageType) {
        let self = this;
@ -64,7 +64,7 @@ class Messages extends RedisModel {
        pagesize = parseInt(pagesize);
        MessageRepo.findBySessionId(sessionId, page, pagesize, messageType, function (err, res) {
            if (err) {
                ModelUtil.emitError(self.eventEmitter, {message: "Error get message by session and type : " + err});
                ModelUtil.emitError(self.eventEmitter, {message: "Get message by session and type failed: " + err});
            } else {
                ModelUtil.emitOK(self.eventEmitter, {data: res});
            }

+ 20 - 26
src/server/models/sessions/participants.js

@ -80,6 +80,7 @@ class Participants extends RedisModel {
     *
     * @param patient
     * @param doctor
     * @param handler
     */
    getSessionIdByParticipants(patient, doctor, handler) {
        ParticipantRepo.findSessionIdByParticipantIds(patient, doctor, handler);
@ -144,28 +145,23 @@ class Participants extends RedisModel {
     * @param sessionId
     * @param userId
     */
    deleteUser(sessionId, userId) {
    removeUser(sessionId, userId) {
        let self = this;
        let participants_key = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
        let user_session_key = RedisModel.makeRedisKey(REDIS_KEYS.UsersSessions, userId);
        //1.移除SESSION成员表中的成员信息
        redis.zremAsync(participants_key, userId).then(function (res) {
            log.info("remove participants:" + res);
            //2.删除对应人员的Session列表
            redis.zremAsync(user_session_key, sessionId).then(function (res) {
                log.info("remove user_session:" + res);
                //3.移除数据库中的人员记录
        // 移除会话中的成员信息,用户的Session信息及MySQL中的记录
        redis.multi()
            .zrem(participants_key, userId)
            .zrem(user_session_key, sessionId)
            .execAsync()
            .then(function (res) {
                self.deleteUserFromMysql(sessionId, userId);
                ModelUtil.emitOK(self.eventEmitter, {"status": 200, "msg": "人员删除成功!"});
            }).catch(function (err) {
                ModelUtil.emitOK(self.eventEmitter, {"status": -1, "msg": "人员删除失败!" + err});
                ModelUtil.emitOK(self.eventEmitter, {});
            })
        }).catch(function (err) {
            ModelUtil.emitOK(self.eventEmitter, {"status": -1, "msg": "人员删除失败!" + err});
        })
            .catch(function (err) {
                ModelUtil.emitError(self.eventEmitter, {message: "成员删除失败: " + err});
            });
    }
    /**
@ -175,12 +171,12 @@ class Participants extends RedisModel {
     * @param role 变更状态
     */
    updateUser(sessionId, user, role) {
        let participants_role_key = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
        redis.hsetAsync(sessionId, user, role).then(function (res) {
            ParticipantRepo.updateParticipant(sessionId, user, role, function (err, res) {
            });
        })
        let participantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
        redis.hsetAsync(participantsRoleKey, user, role)
            .then(function (res) {
                ParticipantRepo.updateParticipant(sessionId, user, role, function (err, res) {
                });
            })
    }
    /**
@ -190,13 +186,12 @@ class Participants extends RedisModel {
     */
    addUser(sessionId, user) {
        let self = this;
        let users = [];
        users.push(user);
        let users = [user];
        self.saveParticipantsToRedis(sessionId, users, new Date(), function (res) {
            if (res) {
                self.saveParticipantsToMysql(sessionId, users);
            } else {
                ModelUtil.emitOK(self.eventEmitter, {"status": -1, "msg": "人员添加失败!"});
                ModelUtil.emitOK(self.eventEmitter, {message: "成员添加失败"});
            }
        })
    }
@ -209,7 +204,6 @@ class Participants extends RedisModel {
    deleteUserFromMysql(sessionId, user) {
        ParticipantRepo.deleteUserFromMysql(sessionId, user);
    }
}
// Expose class

+ 10 - 8
src/server/models/sessions/sessions.js

@ -340,9 +340,10 @@ class Sessions extends RedisModel {
        let participants = new Participants();
        let offset = (page - 1 < 0 ? 0 : page - 1) * size;
        let count = size;
        if (page > 1 || isoffset == 1) {//翻页由于闭区间,需跳过本身数据
            offset += 1;
        if (page > 1 || isoffset == 1) {
            offset += 1;    // 翻页由于闭区间,需跳过本身数据
        }
        participants.existsParticipant(sessionId, userId, function (err, res) {
            if (!res) {
                handler(Error("User not found in session " + sessionId), null);
@ -374,9 +375,10 @@ class Sessions extends RedisModel {
                                }).then(function () {
                                    Sessions.updateParticipantLastFetchTime(sessionId, userId, new Date().getTime());
                                })
                            }).catch(function (res) {
                            handler(res, false);
                        })
                            })
                            .catch(function (res) {
                                handler(res, false);
                            })
                    })
            }
        })
@ -623,7 +625,7 @@ class Sessions extends RedisModel {
                    //初始化置顶
                    redis.zaddAsync(user_session_key, STICKY_SESSION_BASE_SCORE, sessionId).then(function (res) {
                        logger.info("stickSession:" + sessionId + ",res:" + res);
                        ModelUtil.emitOK(self.eventEmitter, {"status": 200, "msg": "置顶成功!"});
                        ModelUtil.emitOK(self.eventEmitter, {});
                    }).then(function () {
                        SessionRepo.saveStickySession(sessionId, user, STICKY_SESSION_BASE_SCORE);
                    })
@ -632,7 +634,7 @@ class Sessions extends RedisModel {
                    scoreres = Number(scoreres) + 1;
                    redis.zaddAsync(user_session_key, scoreres, sessionId).then(function () {
                        logger.info("stickSession:" + sessionId + ",res:" + res);
                        ModelUtil.emitOK(self.eventEmitter, {"status": 200, "msg": "置顶成功!"});
                        ModelUtil.emitOK(self.eventEmitter, {});
                    }).then(function () {
                        SessionRepo.saveStickySession(sessionId, user, scoreres);
                    })
@ -654,7 +656,7 @@ class Sessions extends RedisModel {
            }
            redis.zaddAsync(user_session_key, res, sessionId).then(function (res) {
                logger.info("cancelStickSession:" + sessionId);
                ModelUtil.emitOK(self.eventEmitter, {"status": 200, "msg": "取消置顶成功!"});
                ModelUtil.emitOK(self.eventEmitter, {});
            }).then(function () {
                SessionRepo.unstickSession(sessionId, user);
            });

+ 1 - 1
src/server/repository/mysql/topics.repo.js

@ -45,7 +45,7 @@ class TopicRepo {
    }
    static findTopicStatus(topicId, handler) {
        let sql = "select status from " + DB_TABLES.Topics + " where id = ?";
        let sql = "select id, status from " + DB_TABLES.Topics + " where id = ?";
        ImDb.execQuery({
            sql: sql,