浏览代码

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

8 年之前
父节点
当前提交
3927b12c7e
共有 2 个文件被更改,包括 35 次插入5 次删除
  1. 21 1
      src/server/models/client/wechat.client.js
  2. 14 4
      src/server/repository/mysql/participant.repo.js

+ 21 - 1
src/server/models/client/wechat.client.js

@ -10,7 +10,7 @@ let ModelUtil = require('../../util/model.util');
let WechatSDK = require('../../util/wechat.sdk');
let WechatSDK = require('../../util/wechat.sdk');
let PatientRepo = require('../../repository/mysql/patient.repo');
let PatientRepo = require('../../repository/mysql/patient.repo');
let TopicRepo = require("../../repository/mysql/topics.repo.js");
let TopicRepo = require("../../repository/mysql/topics.repo.js");
let ParticipantRepo = require("../../repository/mysql/participant.repo");
let redisConn = RedisClient.redisClient().connection;
let redisConn = RedisClient.redisClient().connection;
let clientCache = require('../socket.io/client.cache').clientCache();
let clientCache = require('../socket.io/client.cache').clientCache();
let configFile = require('../../include/commons').CONFIG_FILE;
let configFile = require('../../include/commons').CONFIG_FILE;
@ -71,6 +71,7 @@ class WechatClient extends RedisModel {
                    log.error("patient sessionid "+patientClient.sessionId);
                    log.error("patient sessionid "+patientClient.sessionId);
                    if(patientClient.sessionId==doctorClient.sessionId){
                    if(patientClient.sessionId==doctorClient.sessionId){
                    //用户socket在线,推送给用户后,告知医生此消息已读
                    //用户socket在线,推送给用户后,告知医生此消息已读
                        WechatClient.updateParticipantLastFetchTime(doctorClient.sessionId, targetUserId, ObjectUtil.timestampToLong(message.timestamp));
                        WechatClient.sendReadDoctor(doctorClient.socket, message);
                        WechatClient.sendReadDoctor(doctorClient.socket, message);
                    }
                    }
                }else{
                }else{
@ -156,6 +157,7 @@ class WechatClient extends RedisModel {
        }
        }
        let sendDoctorClient = clientCache.findByIdAndType(message.sender_id,SOCKET_TYPES.DOCTOR);
        let sendDoctorClient = clientCache.findByIdAndType(message.sender_id,SOCKET_TYPES.DOCTOR);
        if(sendDoctorClient&&sendDoctorClient.sessionId==doctorClient.sessionId){
        if(sendDoctorClient&&sendDoctorClient.sessionId==doctorClient.sessionId){
            WechatClient.updateParticipantLastFetchTime(doctorClient.sessionId, doctorId, ObjectUtil.timestampToLong(message.timestamp));
            sendDoctorClient.socket.emit('message', {
            sendDoctorClient.socket.emit('message', {
                id: message.id,
                id: message.id,
                session_id: message.session_id,
                session_id: message.session_id,
@ -184,6 +186,7 @@ class WechatClient extends RedisModel {
            sendDoctorClient = clientCache.findByIdAndType(doctorId,SOCKET_TYPES.PATIENT);
            sendDoctorClient = clientCache.findByIdAndType(doctorId,SOCKET_TYPES.PATIENT);
        }
        }
        if(sendDoctorClient&&sendDoctorClient.sessionId==doctorClient.sessionId){
        if(sendDoctorClient&&sendDoctorClient.sessionId==doctorClient.sessionId){
            WechatClient.updateParticipantLastFetchTime(doctorClient.sessionId, doctorId, ObjectUtil.timestampToLong(message.timestamp));
            doctorClient.socket.emit('message', {
            doctorClient.socket.emit('message', {
                id: message.id,
                id: message.id,
                session_id: message.session_id,
                session_id: message.session_id,
@ -282,6 +285,23 @@ class WechatClient extends RedisModel {
                }
                }
            });
            });
    };
    };
    static updateParticipantLastFetchTime(sessionId, userId, score) {
        score = score + 1000;
        let participantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
        redisConn.zaddAsync(participantsKey, score, userId)
            .then(function (res) {
                ParticipantRepo.updateLastFetchTime(new Date(score), sessionId, userId, function (err, res) {
                    if (err) {
                        log.error("Update participant last fetch time failed: ", err);
                    }
                });
            })
            .catch(function (err) {
                log.error("Update participant last fetch time failed: ", err);
            });
    }
}
}
module.exports = WechatClient;
module.exports = WechatClient;

+ 14 - 4
src/server/repository/mysql/participant.repo.js

@ -213,17 +213,27 @@ class ParticipantRepo {
        let sql = "INSERT INTO " + DB_TABLES.Participants + " (session_id,participant_id,participant_role,last_fetch_time) VALUES ";
        let sql = "INSERT INTO " + DB_TABLES.Participants + " (session_id,participant_id,participant_role,last_fetch_time) VALUES ";
        let args = [];
        let args = [];
        let nowDate = new Date();
        let nowDate = new Date();
        console.error("user",users.join(","));
        for (let j in users) {
        for (let j in users) {
            let tokens = users[j].split(":");
            let tokens = users[j].split(":");
            if(tokens.length > 1&&tokens[1]==2)continue;
            if(tokens.length > 1&&tokens[1]==2){
                continue;
            }
            sql += "(?,?,?,?)";
            sql += "(?,?,?,?)";
            args.push(sessionId);
            args.push(sessionId);
            args.push(tokens[0]);
            args.push(tokens[0]);
            args.push(tokens.length > 1 ? tokens[1] : '0');
            if(tokens.length > 1&&tokens[1]==2){
            }else{
                args.push(tokens.length > 1 ? tokens[1] : '0');
            }
            args.push(nowDate);
            args.push(nowDate);
            if (j != users.length - 1) sql += ", ";
            sql += ",";
        }
        if(sql.lastIndexOf(",")==sql.length-1){
            sql = sql.substring(0,sql.lastIndexOf(","));
        }
        }
        sql += " ON DUPLICATE KEY UPDATE participant_role = VALUES(participant_role)";
        sql += " ON DUPLICATE KEY UPDATE participant_role = VALUES(participant_role)";
        ImDb.execQuery({
        ImDb.execQuery({