浏览代码

错误代码修正,修改引用信息

8 年之前
父节点
当前提交
0db4de67ea

+ 11 - 0
src/server/endpoints/v2/topic.endpoint.js

@ -56,6 +56,15 @@ router.post(APIv2.Sessions.Topics, function (req, res) {
    topic.createTopics(payload.topicName, payload.topicId,payload.sessionId,JSON.parse(payload.participants), JSON.parse(payload.messages));
});
router.put(APIv2.Sessions.Topics, function (req, res) {
    let data = req.body;
    let topicId = data.topic_id;
    let jsonValue = data.data;
    let topic = new Topics();
    ControllerUtil.regModelEventHandler(topic, res);
    topic.updateTopic(topicId,jsonValue);
});
router.get(APIv2.Sessions.TopicEnded, function (req, res) {
    let data = req.body;
    let endUser = data.end_user;
@ -66,4 +75,6 @@ router.get(APIv2.Sessions.TopicEnded, function (req, res) {
    topic.endTopic(topicId, endUser, endUserName);
});
module.exports = router;

+ 2 - 1
src/server/include/endpoints.js

@ -31,7 +31,8 @@ const APIv2 = {
        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话
        Topics: '/:session_id/topics',
        Topic: '/:session_id/topics/:topic_id',                         // 议题,指定ID的议题将返回其信息
        Topic: '/:session_id/topics/:topic_id',
        Topic: '/:session_id/topics/:topic_id',                          // 议题,指定ID的议题将返回其信息
        TopicEnded: '/:session_id/topics/:topic_id/ended',              // 议题是否已结束,若top_id为current,则检查最后一个议题的状态
        Messages: '/:session_id/messages',                              // 会话消息

+ 23 - 10
src/server/models/sessions/topics.js

@ -16,7 +16,7 @@ let configFile = require('../../include/commons').CONFIG_FILE;
let config = require('../../resources/config/' + configFile);
const REDIS_KEYS = require('../../include/commons').REDIS_KEYS;
const SESSION_USER_STATUS = require('../../include/commons').SESSION_USER_STATUS;
const TOPIC_STATUS = require('../../include/commons').TOPIC_STATUS;
const SESSION_TYPES = require('../../include/commons').SESSION_TYPES;
class Topics extends RedisModel {
@ -74,7 +74,7 @@ class Topics extends RedisModel {
        let date = new Date();
        var pars=[];
        redis.zaddAsync(topics_key, date.getTime(), topicId).then(function (res) {
            redis.hmsetAsync(topic_key, "name", topicName, "end_by", "", "session_id", sessionId, "create_time", date.getTime(), "end_time", "", "description", messages.description).then(function (res) {
            redis.hmsetAsync(topic_key, "name", topicName, "end_by", "", "session_id", sessionId, "create_time", date.getTime(), "end_time", "", "description", messages.description, "status", TOPIC_STATUS.NEW).then(function (res) {
                sessions.getSessions(sessionId, function (err, res) {
                    //已经存在对应的会话更新全科为旁听
                    if (res && res.length > 0) {
@ -94,7 +94,7 @@ class Topics extends RedisModel {
                    }
                })
            })
        });
        }).catch();
        
        /**
         * 开始消息发送
@ -110,7 +110,7 @@ class Topics extends RedisModel {
                if (err) {
                    ModelUtil.emitOK(self.eventEmitter, err);
                } else {
                    self.saveTopicsToSql(topicName, topicId, sessionId, msgId, date);
                    self.saveTopicsToSql(topicName, topicId, sessionId, msgId, date,messages.description,TOPIC_STATUS.NEW);
                    callBeginMsg(msgId);
                }
            })
@ -148,8 +148,8 @@ class Topics extends RedisModel {
        }
    }
    saveTopicsToSql(topicName, topicId, sessionId, messageId, date) {
        TopicsRepo.saveTopic(topicName, topicId, sessionId, messageId, date);
    saveTopicsToSql(topicName, topicId, sessionId, messageId, date,description) {
        TopicsRepo.saveTopic(topicName, topicId, sessionId, messageId, date,description);
    }
    /**
@ -161,7 +161,7 @@ class Topics extends RedisModel {
        let endDate = new Date();
        let self = this;
        let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
        redis.hmsetAsync(topic_key, "end_time", endDate.getTime(), "end_by", endUser).then(function (res) {
        redis.hmsetAsync(topic_key, "end_time", endDate.getTime(), "end_by", endUser,"status",TOPIC_STATUS.FINISHED).then(function (res) {
            redis.hgetallAsync(topic_key).then(function (topic) {
                callEnd(topic.session_id);
            })
@ -172,9 +172,9 @@ class Topics extends RedisModel {
         */
        function callEnd(sessionId) {
            let msg = {};
            msg.senderId = endUser;
            msg.senderName = endUserName;
            msg.contentType = 7;
            msg.sender_id = endUser;
            msg.sender_name = endUserName;
            msg.content_type = 7;
            msg.content = endUserName + "结束了咨询"
            msg.timestamp = new Date();
            let sessions = new Sessions();
@ -188,6 +188,19 @@ class Topics extends RedisModel {
            })
        }
    }
    updateTopic(topicId,valueJson){
        let self = this;
        let topic_key = RedisModel.makeRedisKey(REDIS_KEYS.Topic, topicId);
        var dataArray = [];
        for(var j in valueJson){
            dataArray.push(j);
            dataArray.push(valueJson[j]);
        }
        redis.hmsetAsync(topic_key, dataArray).then(function (res) {
            TopicsRepo.updateTopis(topicId,valueJson);
        });
    }
}
// Expose class

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

@ -7,7 +7,6 @@ let ImDb = require('../mysql/db/im.db');
let DbUtil = require('../../util/db.util');
let log = require('../../util/log.js');
const DB_TABLES = require('../../include/commons').DB_TABLES;
class TopicRepo {
    constructor() {
    }
@ -17,11 +16,11 @@ class TopicRepo {
     * 保存议题
     * @param sessionId
     */
    static saveTopic(topicName,topicId,sessionId,messageId,date) {
        let sql = "insert into topics (id,session_id,name,create_time,start_message_id) VALUES (?,?,?,?,?)";
    static saveTopic(topicName,topicId,sessionId,messageId,date,description,status) {
        let sql = "insert into topics (id,session_id,name,create_time,start_message_id,description,status) VALUES (?,?,?,?,?,?,?)";
        ImDb.execQuery({
            "sql": sql,
            "args": [topicId,sessionId,topicName,date,messageId],
            "args": [topicId,sessionId,topicName,date,messageId,description,status],
            "handler": function (err, res) {
                if (err) {
                    log.error("saveTopic is fail error: " + err+"messageId:"+messageId);
@ -38,11 +37,11 @@ class TopicRepo {
     * @param sessionId
     * @param handler
     */
    static endTopic(topicId,endUser,date,messageId) {
        let sql = "update topics set end_by = ?,end_time=?,end_message_id=? where  id = ?";
    static endTopic(topicId,endUser,date,messageId,status) {
        let sql = "update topics set end_by = ?,end_time=?,end_message_id=?,status = ? where  id = ?";
        ImDb.execQuery({
            "sql": sql,
            "args": [endUser,date,messageId,topicId],
            "args": [endUser,date,messageId,status ,topicId],
            "handler": function (err, res) {
                if (err) {
                    log.error("endTopic is fail error: " + err);
@ -52,6 +51,29 @@ class TopicRepo {
            }
        });
    }
    static updateTopis(topicId,jsonValue){
        var values=[];
        let sql = "update topics set ";
        for(var j in jsonValue){
            sql=sql+j+"= ?,";
            values.push(jsonValue[j]);
        }
        sql =  sql.substring(0,sql.lastIndexOf(","));
        sql = sql + "where  id = ?";
        values.push(topicId);
        ImDb.execQuery({
            "sql": sql,
            "args": values,
            "handler": function (err, res) {
                if (err) {
                    log.error("updateTopis is fail error: " + err);
                }else{
                    log.info("updateTopis is success" );
                }
            }
        });
    }
}
module.exports = TopicRepo;