|
@ -8,6 +8,7 @@ let RedisModel = require('./../redis.model.js');
|
|
|
let ModelUtil = require('../../util/model.util');
|
|
|
let Messages = require('../messages/messages');
|
|
|
let Users = require('../user/users');
|
|
|
let DoctorRepo = require('../../repository/mysql/doctor.repo');
|
|
|
let Participants = require('./participants');
|
|
|
let SessionRepo = require('../../repository/mysql/session.repo');
|
|
|
let TopicRepo = require('../../repository/mysql/topics.repo');
|
|
@ -87,6 +88,23 @@ class Sessions extends RedisModel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
*MDT 医生数据转换,根据手机号查询医生CODE
|
|
|
*/
|
|
|
conversionAarticipant(participants) {
|
|
|
let doctorProto = DoctorRepo;
|
|
|
for (let j in participants) {
|
|
|
doctorProto.findByMobile(participants[j][0], function (err, oDoctor) {
|
|
|
if(oDoctor.length>0){
|
|
|
participants[j][0] = oDoctor.id;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
return participants;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建会话。REDIS
|
|
|
* @param sessionId
|
|
@ -384,7 +402,7 @@ class Sessions extends RedisModel {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 根据用户ID获取用户的session列表
|
|
|
* @param userId
|
|
|
* @param page
|
|
@ -393,7 +411,6 @@ class Sessions extends RedisModel {
|
|
|
*/
|
|
|
getUserSessions(userId, page, size, businessType) {
|
|
|
let userSessionKey = RedisModel.makeRedisKey(REDIS_KEYS.UserSessions, userId);
|
|
|
logger.info(userId);
|
|
|
let self = this;
|
|
|
if (page > 0) {
|
|
|
if (page == 1) {
|
|
@ -415,7 +432,7 @@ class Sessions extends RedisModel {
|
|
|
// },
|
|
|
function (callback) {
|
|
|
SessionRepo.findAllByType(userId,businessType,page,size,function(err,res){
|
|
|
if (res && res.length == 0) {
|
|
|
if (res.length == 0) {
|
|
|
ModelUtil.emitOK(self.eventEmitter, []);
|
|
|
return;
|
|
|
}
|
|
@ -430,14 +447,18 @@ class Sessions extends RedisModel {
|
|
|
function (sessionIds) {
|
|
|
let sessionList = [];
|
|
|
let functionList = [];
|
|
|
log.info("sessionIds.length:" + sessionIds.length);
|
|
|
for (let j = 0; j < sessionIds.length; j++) {
|
|
|
log.info("遍历会话 :" + sessionIds);
|
|
|
let fun = function (index, callback) {
|
|
|
log.info("!callback:" + !callback);
|
|
|
if (!callback) {
|
|
|
callback = index, index = 0
|
|
|
}
|
|
|
let sessionId = sessionIds[index];
|
|
|
let sessionKey = RedisModel.makeRedisKey(REDIS_KEYS.Session, sessionId);
|
|
|
|
|
|
log.info("sessionKey:" + sessionKey);
|
|
|
|
|
|
let participantsRoleKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipantsRole, sessionId);
|
|
|
let sessionParticipantsKey = RedisModel.makeRedisKey(REDIS_KEYS.SessionParticipants, sessionId);
|
|
|
redis.multi()
|
|
@ -450,6 +471,9 @@ class Sessions extends RedisModel {
|
|
|
.execAsync()
|
|
|
.then(function (res) {
|
|
|
let session = res[0];
|
|
|
log.info("top.session.id:" + session.id);
|
|
|
log.info("top.session.name:" + session.name);
|
|
|
log.info("tope.session.business_type:" + session.business_type);
|
|
|
let role = res[1];
|
|
|
let lastFetchTime = res[2];
|
|
|
let users = res[3];
|
|
@ -459,11 +483,19 @@ class Sessions extends RedisModel {
|
|
|
let isInvite = true;
|
|
|
|
|
|
//处理session未加入redis的bug
|
|
|
|
|
|
log.info("1.session==null:" + session==null);
|
|
|
|
|
|
if(session==null){
|
|
|
let lastLoginTime = new Date();
|
|
|
SessionRepo.findOne(sessionId, function (err, res) {
|
|
|
if(res){
|
|
|
session = res;
|
|
|
|
|
|
log.info("1.session.id:" + session.id);
|
|
|
log.info("1.session.name:" + session.name);
|
|
|
log.info("1.session.business_type:" + session.business_type);
|
|
|
|
|
|
let redisSession = [
|
|
|
"id", session.id,
|
|
|
"name", session.name,
|
|
@ -625,14 +657,19 @@ class Sessions extends RedisModel {
|
|
|
sessionName = res[0].name;
|
|
|
}
|
|
|
var bir = new Date().getTime();
|
|
|
if (res && res.length != 0 && res[0].birthdate) {
|
|
|
if (res.length != 0 && res[0].birthdate) {
|
|
|
bir = res[0].birthdate.getTime();
|
|
|
}
|
|
|
var sex = 1;
|
|
|
if (res && res.length != 0 && res[0].sex) {
|
|
|
if (res.length != 0 && res[0].sex) {
|
|
|
sex = res[0].sex;
|
|
|
}
|
|
|
//end
|
|
|
|
|
|
log.info("2.session.id:" + sessionId);
|
|
|
log.info("2.session.name:" + sessionName);
|
|
|
log.info("2.session.business_type:" + session.business_type);
|
|
|
|
|
|
sessionList.push({
|
|
|
id: sessionId,
|
|
|
name: sessionName,
|
|
@ -643,7 +680,8 @@ class Sessions extends RedisModel {
|
|
|
type: session.type,
|
|
|
sender_name: session.last_sender_name||"",
|
|
|
unread_count: count,
|
|
|
business_type: session.business_type,
|
|
|
// business_type: session.business_type,
|
|
|
business_type: businessType,
|
|
|
my_role: role,
|
|
|
sender_sex: sex,
|
|
|
sender_birthday: bir,
|
|
@ -2007,6 +2045,7 @@ class Sessions extends RedisModel {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// Expose class
|