Jelajahi Sumber

查询未读数

wangzhinan 5 tahun lalu
induk
melakukan
34c0360069

+ 23 - 26
src/server/models/sessions/sessions.js

@ -1358,12 +1358,11 @@ class Sessions extends RedisModel {
        let patientCount = 0;
        let patientCount = 0;
        let doctorCount = 0;
        let doctorCount = 0;
        let patientEndCount = 0;
        let patientEndCount = 0;
        SessionRepo.findAll(userId, function (err, res) {
        // SessionRepo.findUnEndAll(userId, function (err, res) {
        SessionRepo.findAllByTypes(userId,type, function (err, res) {
            // SessionRepo.findUnEndAll(userId, function (err, res) {
            if (err) {
            if (err) {
                if(handler)
                {
                    handler(err,res);
                if (handler) {
                    handler(err, res);
                    return;
                    return;
                }
                }
                ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
                ModelUtil.logError("getAllSessionsUnreadMessageCount is failed", err);
@ -1371,33 +1370,31 @@ class Sessions extends RedisModel {
            }
            }
            if (res && res.length == 0) {
            if (res && res.length == 0) {
                if(handler)
                {
                    handler(err,count);
                if (handler) {
                    handler(err, count);
                    return;
                    return;
                }
                }
                ModelUtil.emitOK(self.eventEmitter, {count: count});
                ModelUtil.emitOK(self.eventEmitter, {count: count});
                return;
                return;
            }
            }
            let has = false;
            /*let has = false;*/
            for (let j in res) {
            for (let j in res) {
                has = false;
                //是否过滤指定类型
                if( type != null){
                    let typeString = type.split(",");
                    var str = res[j].type;
                    var str1 = str.toString();
                    if(typeString.indexOf(str1)<0){
                        continue;
                    }
                }
                /* has = false;
                 //是否过滤指定类型
                 if( type != null){
                     let typeString = type.split(",");
                     var str = res[j].type;
                     var str1 = str.toString();
                     if(typeString.indexOf(str1)<0){
                         continue;
                     }
                 }*/
                if (res[j].type == SESSION_TYPES.SYSTEM) {
                if (res[j].type == SESSION_TYPES.SYSTEM) {
                    if (j == res.length - 1) {
                    if (j == res.length - 1) {
                        if(handler){
                            handler(err,count);
                        if (handler) {
                            handler(err, count);
                            return;
                            return;
                        }
                        }
                        ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount, doctor: doctorCount});
                        ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount, doctor: doctorCount});
@ -1405,11 +1402,11 @@ class Sessions extends RedisModel {
                    continue;
                    continue;
                }
                }
                callback(res, j, res[j]);
                callback(res, j, res[j]);
                has = true
            }
            if(!has){
                ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: 0, doctor: doctorCount});
                /*      has = true*/
            }
            }
            /* if(!has){
                 ModelUtil.emitOK(self.eventEmitter, {count: count, patient: patientCount,patientEnd: 0, doctor: doctorCount});
             }*/
        });
        });
        /*function callback(res, j, session) {
        /*function callback(res, j, session) {

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

@ -114,6 +114,28 @@ class SessionRepo {
        });
        });
    }
    }
    /**
     * 根据type查询对话
     * @param userId
     * @param type 字符串
     * @param handler
     */
    static findAllByTypes(userId, type, handler) {
        let sql = "select session_id from " + DB_TABLES.Participants + " w where w.participant_id = ?  group by w.session_id";
        let sessionSQL = "select id, name, type, create_date, last_sender_id, last_sender_name, last_content_type, last_content, last_message_time from "
            + DB_TABLES.Sessions + " s where s.id in(" + sql + ") and type in(?) ";
        log.info("获取用户全部会话: sql :" + sessionSQL);
        log.info("userId"+userId+"=========type"+type);
        ImDb.execQuery({
            "sql": sessionSQL,
            "args": [userId, type],
            "handler": handler || function (err, res) {
                if(err) log.error(err);
            }
        });
    }
    /**
    /**
     * 查找某类型的用户的会话数量
     * 查找某类型的用户的会话数量
     * @param userId
     * @param userId