Browse Source

用户退出时,删除REDIS与MYSQL中的APP状态数据

Sand 8 years ago
parent
commit
e00b277ef6

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

@ -105,7 +105,7 @@ class AppClient extends RedisModel {
                }
                if (!userStatus) {
                    log.warn("User's app status is not found, user id: " + targetId + ", MAYBE user never login yet?");
                    log.warn("User's app status is not found, user id: " + targetId + ", maybe user never login yet or logout?");
                    return;
                }

+ 4 - 4
src/server/models/push/pusher.js

@ -89,7 +89,7 @@ class Pusher extends RedisModel {
        }
    }
    _pushAndroidNotify(clientid, title, msg, data, handler) {
    _pushAndroidNotify(clientId, title, msg, data, handler) {
        let transmissionContent = {
            pushtype: 'notify',
            data: data
@ -118,7 +118,7 @@ class Pusher extends RedisModel {
        //接收方
        let target = new Target({
            appId: this.getuiConfig.APPID,
            clientId: clientid
            clientId: clientId
        });
        this.gt.pushMessageToSingle(message, target, function (err, res) {
@ -134,7 +134,7 @@ class Pusher extends RedisModel {
        });
    }
    _pushAndroidTransmission(clientid, customData, handler) {
    _pushAndroidTransmission(clientId, customData, handler) {
        let transmissionContent = {
            pushtype: 'transmission',
            data: customData
@ -158,7 +158,7 @@ class Pusher extends RedisModel {
        // 接收方
        let target = new Target({
            appId: this.getuiConfig.APPID,
            clientId: clientid
            clientId: clientId
        });
        this.gt.pushMessageToSingle(message, target, function (err, res) {

+ 8 - 3
src/server/models/user/users.js

@ -321,6 +321,12 @@ class Users extends RedisModel {
                        .catch(function (ex) {
                            log.error("Logout failed: ", ex);
                        });
                    AppStatusRepo.destroy(userId, function (err, res) {
                        if(err) log.error("Delete user status failed: " + err);
                    });
                    callback(null, null);
                }],
            function (err, res) {
            }
@ -336,10 +342,8 @@ class Users extends RedisModel {
    static isPatientId(userId, callback) {
        async.waterfall([
                function (callback) {
                    var sql = "select case when count(*) > 0 then true else false end 'is_patient' from patients where id = ?";
                    ImDb.execQuery({
                        "sql": sql,
                        "sql": "select case when count(*) > 0 then true else false end 'is_patient' from patients where id = ?",
                        "args": [userId],
                        "handler": function (err, res) {
                            if (err) callback(err, res);
@ -357,6 +361,7 @@ class Users extends RedisModel {
            function (err, res) {
                if (err) {
                    log.error("User id check failed: ", err);
                    callback(null, false);
                    return;
                }

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

@ -62,11 +62,25 @@ class AppStatusRepo {
     */
    static updateStatus(userId, appInBg, handler) {
        ImDb.execQuery({
            "sql": "UPDATE user SET app_in_bg = ? WHERE user_id = ",
            "sql": "UPDATE app_status SET app_in_bg = ? WHERE user_id = ",
            "args": [appInBg, userId],
            "handler": handler
        });
    };
    /**
     * 销毁用户状态
     *
     * @param userId
     * @param handler
     */
    static destroy(userId, handler) {
        ImDb.execQuery({
            "sql": "DELETE FROM app_status WHERE user_id = ?",
            "args": [userId],
            "handler": handler
        });
    };
}
module.exports = AppStatusRepo;