|
@ -196,21 +196,19 @@ class Topics extends RedisModel {
|
|
|
pars.push(j + ":" + users[j]);
|
|
|
}
|
|
|
let sessions = new Sessions();
|
|
|
let date = new Date();
|
|
|
sessions.createSession(sessionId, messages.sender_name, sessionType, pars, function (err, session) {
|
|
|
sessionId = session.id;
|
|
|
self.saveTopicToRedis(topicName, topicId, sessionId, messages, date, function (err, startMsgId) {
|
|
|
let datetime = session.create_date;
|
|
|
self.saveTopicToRedis(topicName, topicId, sessionId, messages, datetime, function (err, startMsgId) {
|
|
|
if (err) {
|
|
|
ModelUtil.emitOK(self.eventEmitter, {status: -1, message: "议题创建失败!"});
|
|
|
return;
|
|
|
}
|
|
|
//返回给前端
|
|
|
ModelUtil.emitOK(self.eventEmitter, {status: 200, message: "议题创建成功!", start_msg_id: startMsgId});
|
|
|
sessions.updateSessionStatus(sessionId,SESSION_STATUS.PROCEEDINGS,function(err,res){
|
|
|
|
|
|
});
|
|
|
sessions.updateSessionStatus(sessionId,SESSION_STATUS.PROCEEDINGS,function(err,res){});
|
|
|
//执行数据库操作
|
|
|
self.saveTopicToMySQL(topicName, topicId, sessionId, startMsgId, date, messages.description, TOPIC_STATUS.NEW, function (err, res) {
|
|
|
self.saveTopicToMySQL(topicName, topicId, sessionId, startMsgId, new Date(datetime), messages.description, TOPIC_STATUS.NEW, function (err, res) {
|
|
|
if (err) {
|
|
|
ModelUtil.logError("Save topic to mysql failed", err);
|
|
|
}
|
|
@ -220,15 +218,14 @@ class Topics extends RedisModel {
|
|
|
}
|
|
|
|
|
|
|
|
|
saveTopicToRedis(topicName, topicId, sessionId, messages, date, handler) {
|
|
|
saveTopicToRedis(topicName, topicId, sessionId, messages, datetime, handler) {
|
|
|
let topics_key = RedisModel.makeRedisKey(REDIS_KEYS.Topics, sessionId);
|
|
|
let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
|
|
|
let sessions = new Sessions();
|
|
|
|
|
|
//step1:创建topic到redis
|
|
|
redis.zaddAsync(topics_key, date.getTime(), topicId).then(function (res) {
|
|
|
redis.zaddAsync(topics_key, datetime, topicId).then(function (res) {
|
|
|
redis.hmsetAsync(topic_key, "name", topicName,
|
|
|
"session_id", sessionId, "create_time", date.getTime(),
|
|
|
"session_id", sessionId, "create_time", datetime,
|
|
|
"description", messages.description, "status", TOPIC_STATUS.NEW,
|
|
|
"end_time", "", "end_by", ""
|
|
|
).then(function (res) {
|
|
@ -249,29 +246,29 @@ class Topics extends RedisModel {
|
|
|
msg.sender_name = "系统";//messages.sender_name;发起和结束咨询的消息由系统发出,发送者ID记录操作人!
|
|
|
msg.content_type = 10;
|
|
|
msg.content = messages.sender_name + "发起了咨询";
|
|
|
msg.timestamp = date;
|
|
|
msg.timestamp = new Date(datetime);
|
|
|
sessions.saveMessageByTopic(msg, sessionId, function (err, msgId) {
|
|
|
if (err) {
|
|
|
handler(err, null);
|
|
|
} else {
|
|
|
sendQuesionMsg(msgId);
|
|
|
sendQuesionMsg();
|
|
|
handler(null, msgId);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//step3:发送求助内容的文本
|
|
|
function sendQuesionMsg(startMsgId) {
|
|
|
function sendQuesionMsg() {
|
|
|
let msg = {};
|
|
|
msg.sender_id = messages.sender_id;
|
|
|
msg.sender_name = messages.sender_name;
|
|
|
msg.content_type = 6;
|
|
|
msg.content = messages.description;
|
|
|
msg.timestamp = new Date();
|
|
|
msg.timestamp = new Date(datetime+200);
|
|
|
sessions.saveMessageByTopic(msg, sessionId, function (err, msgId) {
|
|
|
if (messages.img) {
|
|
|
setTimeout(function(){
|
|
|
sendQuesionImg(startMsgId);
|
|
|
sendQuesionImg();
|
|
|
},100);
|
|
|
}
|
|
|
if (err) {
|
|
@ -280,7 +277,7 @@ class Topics extends RedisModel {
|
|
|
});
|
|
|
}
|
|
|
//step4:发送求助内容的图片
|
|
|
function sendQuesionImg(startMsgId) {
|
|
|
function sendQuesionImg() {
|
|
|
let imgs = messages.img.split(",");
|
|
|
for (var j in imgs) {
|
|
|
let msgimg = {};
|
|
@ -288,7 +285,7 @@ class Topics extends RedisModel {
|
|
|
msgimg.sender_name = messages.sender_name;
|
|
|
msgimg.content_type = 2;
|
|
|
msgimg.content = imgs[j];
|
|
|
msgimg.timestamp = new Date();
|
|
|
msgimg.timestamp = new Date(datetime+(200*j));
|
|
|
sessions.saveMessageByTopic(msgimg, sessionId, function (err, msgId) {
|
|
|
if (err) {
|
|
|
log.info("send create img error " + imgs[j]);
|