8 лет назад
Родитель
Сommit
ecea21c570

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

@ -36,7 +36,7 @@ router.get('/', function (req, res) {
    let targetRole = req.query.target_role;
    let targetRole = req.query.target_role;
    let entityType = req.query.entity_type;
    let entityType = req.query.entity_type;
    let keyword = req.query.keyword;
    let keyword = req.query.keyword;
    let excludeTopicEndedSessions = req.query.exclude_topic_ended_sessions === 'true';
    let excludeTopicEndedSessions = req.query.exclude_topic_ended_sessions;
    let page = req.query.page;
    let page = req.query.page;
    let size = req.query.size;
    let size = req.query.size;

+ 8 - 2
src/server/models/search/object.searcher.js

@ -23,13 +23,19 @@ class ObjectSearcher extends RedisModel {
        async.waterfall([
        async.waterfall([
                // 获取会话ID列表,根据参数过滤应该议题已结束的会话
                // 获取会话ID列表,根据参数过滤应该议题已结束的会话
                function (callback) {
                function (callback) {
                    if (excludeTopicEndedSessions) {
                    if (excludeTopicEndedSessions=="true") {
                        SearchRepo.findTopicEndedSessionIdList(userId, function (err, sessionIdList) {
                        SearchRepo.findTopicEndedSessionIdList(userId, function (err, sessionIdList) {
                            if (err) return callback(err, null);
                            if (err) return callback(err, null);
                            callback(null, sessionIdList, keyword, targetRole, entityType);
                            callback(null, sessionIdList, keyword, targetRole, entityType);
                        })
                        })
                    } else {
                    }else if(excludeTopicEndedSessions=="false"){
                        SearchRepo.findTopicActiveSessionIdList(userId, function (err, sessionIdList) {
                            if (err) return callback(err, null);
                            callback(null, sessionIdList, keyword, targetRole, entityType);
                        })
                    }else {
                        redis.zrangeAsync(RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId), 0, -1)
                        redis.zrangeAsync(RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId), 0, -1)
                            .then(function (sessionIdList) {
                            .then(function (sessionIdList) {
                                callback(null, sessionIdList, keyword, targetRole, entityType);
                                callback(null, sessionIdList, keyword, targetRole, entityType);

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

@ -1040,7 +1040,7 @@ class Sessions extends RedisModel {
                                                            message.content_type == CONTENT_TYPES.Video)){
                                                            message.content_type == CONTENT_TYPES.Video)){
                            TopicRepo.findLastBySessionId(sessionId,function(err,res){
                            TopicRepo.findLastBySessionId(sessionId,function(err,res){
                                if(res&&res.length>0&&res[0].reply==0){
                                if(res&&res.length>0&&res[0].reply==0){
                                    TopicRepo.updateTopics(res[0].id,{reply:1},function(err,res){
                                    TopicRepo.updateTopics(res[0].id,{reply:1,reply_time:message.timestamp,reply_user:message.sender_id,reply_message_id:message.id},function(err,res){
                                        if(err){
                                        if(err){
                                            logger.error("update topic reply error");
                                            logger.error("update topic reply error");
                                        }else{
                                        }else{
@ -1300,7 +1300,6 @@ class Sessions extends RedisModel {
                        let data = res.data;
                        let data = res.data;
                        count = parseInt(JSON.parse(data.imMsgCount).count) + parseInt(data.system.amount) + parseInt(data.healthIndex.amount) + parseInt(data.sign.amount);
                        count = parseInt(JSON.parse(data.imMsgCount).count) + parseInt(data.system.amount) + parseInt(data.healthIndex.amount) + parseInt(data.sign.amount);
                    }
                    }
                    console.error("sessionType:"+sessionType+"-->res:"+res)
                    AppClient.sendNotification(targetUserId, message,sessionType,count);
                    AppClient.sendNotification(targetUserId, message,sessionType,count);
                });
                });
            }
            }

+ 0 - 1
src/server/models/user/users.js

@ -114,7 +114,6 @@ class Users extends RedisModel {
                     'birthdate', userInfo.birthdate ? ObjectUtil.timestampToLong(userInfo.birthdate) : '',
                     'birthdate', userInfo.birthdate ? ObjectUtil.timestampToLong(userInfo.birthdate) : '',
                     'name', userInfo.name,
                     'name', userInfo.name,
                     'role', loginFromApp ? 'doctor' : 'patient');*/
                     'role', loginFromApp ? 'doctor' : 'patient');*/
                    console.error(loginFromApp);
                    if (loginFromApp) {
                    if (loginFromApp) {
                        AppStatusRepo.save(userId, deviceToken, clientId, platform, function (err, res) {
                        AppStatusRepo.save(userId, deviceToken, clientId, platform, function (err, res) {
                            if (err) log.error(err);
                            if (err) log.error(err);

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

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

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

@ -33,6 +33,29 @@ class SearchRepo {
        });
        });
    }
    }
    /**
     * 查询正常会话及议题已结束的会话(P2P, MUC)
     *
     * @param userId
     * @param handler
     */
    static findTopicActiveSessionIdList(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 NULL  AND s.`type` IN (1,2) " +
            " UNION " +
            "SELECT s.id " +
            "FROM sessions s, participants p " +
            "WHERE p.participant_id = ? AND p.session_id = s.id  AND s.`type` IN (2,3)  and s.id not in(" +
            " select DISTINCT p1.session_id from  participants p1 ,topics t where p1.participant_id = ? and  t.session_id = p1.session_id  " +
            ") ";
        ImDb.execQuery({
            sql: sql,
            args: [userId, userId,userId],
            handler: handler
        });
    }
    /**
    /**
     * 全部搜索
     * 全部搜索
     *
     *
@ -87,14 +110,14 @@ class SearchRepo {
     * @param handler
     * @param handler
     */
     */
    static searchUser(sessionIdList,userId, keyword, userTable, page, size, handler) {
    static searchUser(sessionIdList,userId, keyword, userTable, page, size, handler) {
        let sql = "SELECT DISTINCT u.name user_name,s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id,u.sex, u.birthdate, u.avatar %s " +
        let sql = "SELECT DISTINCT u.name user_name,s.id session_id, s.name session_name, s.type session_type, s.business_type, u.id user_id,u.sex, u.birthdate, u.avatar,u.idcard %s " +
            " FROM  participants p, " + userTable +
            " FROM  participants p, " + userTable +
            " u,sessions s WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND u.name like ? ";
            " u,sessions s WHERE s.id in (?) AND s.id = p.session_id AND p.participant_id = u.id and p.participant_id<>? AND (u.name like ? or u.idcard like ?) ";
        if (userTable === DB_TABLES.Doctors) {
        if (userTable === DB_TABLES.Doctors) {
            sql += " AND s.type in (2) ";
            sql += " AND s.type in (2) and s.business_type = 1 ";
        }else{
        }else{
            sql += " AND s.type in (1,2) ";
            sql += " AND s.type in (1,2)  and s.business_type = 2 ";
        }
        }
        sql += " limit ?, ? ";
        sql += " limit ?, ? ";
        sql = vsprintf(sql, [userTable == DB_TABLES.Doctors ? ', hospital_name' : '']);
        sql = vsprintf(sql, [userTable == DB_TABLES.Doctors ? ', hospital_name' : '']);
@ -102,7 +125,7 @@ class SearchRepo {
        keyword = '%' + keyword + '%';
        keyword = '%' + keyword + '%';
        ImDb.execQuery({
        ImDb.execQuery({
            sql: sql,
            sql: sql,
            args: [sessionIdList,userId, keyword, page * size, size],
            args: [sessionIdList,userId, keyword,keyword, page * size, size],
            handler: handler
            handler: handler
        });
        });
    }
    }
@ -158,8 +181,7 @@ class SearchRepo {
    static userForge(res) {
    static userForge(res) {
        res.forEach(function (user) {
        res.forEach(function (user) {
            if (!user.avatar) user.avatar = "";
            if (!user.avatar) user.avatar = "";
            user.birthdate = user.birthdate ? ObjectUtil.timestampToLong(user.birthdate) : "";
                user.birthdate = user.birthdate ? user.birthdate.getTime():"";
        });
        });
        return res;
        return res;

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

@ -146,7 +146,8 @@ class SessionRepo {
        "AND UNIX_TIMESTAMP(s.last_message_time) > UNIX_TIMESTAMP(NOW()) - ? " +
        "AND UNIX_TIMESTAMP(s.last_message_time) > UNIX_TIMESTAMP(NOW()) - ? " +
        "AND p.participant_id <> ? AND s.type <> 1 AND s.business_type = 1 " +
        "AND p.participant_id <> ? AND s.type <> 1 AND s.business_type = 1 " +
        "AND s.id in (select s.id from sessions s, participants p where s.id = p.session_id and p.participant_id = ?) " +
        "AND s.id in (select s.id from sessions s, participants p where s.id = p.session_id and p.participant_id = ?) " +
        "ORDER BY s.last_message_time DESC";
         "AND s.id in (select s.id from participants p1, topics t where t.end_message_id is null and  p1.session_id = t.session_id and p1.participant_id = ?) " +
         "ORDER BY s.last_message_time DESC";
        ImDb.execQuery({
        ImDb.execQuery({
            sql: sql,
            sql: sql,