Browse Source

代码修改

8 years ago
parent
commit
8b48744392

+ 5 - 60
src/server/models/sessions/participants.js

@ -8,10 +8,9 @@ let redisClient = RedisClient.redisClient();
let redis = redisClient.connection;
let RedisModel = require('./../redis.model.js');
let modelUtil = require('../../util/model.util');
let imDb = require('../../repository/mysql/db/im.db');
let ParticipantRepo = require('../../repository/mysql/participant.repo');
let log = require('../../util/log.js');
const RedisKey = require('../../include/commons').REDIS_KEYS;
const IMTABLE = require('../../include/commons').IM_DB;
class Participants extends RedisModel {
    constructor() {
@ -40,17 +39,7 @@ class Participants extends RedisModel {
                    handler(res);
                })
            }else{
                let sql ="select w.* from participants w where w.session_id =? ";
                imDb.execQuery({
                    "sql": sql,
                    "args": [sessionId],
                    "handler": function (err, res) {
                        if(err) {
                            log.error("getParticipantsBySessionId is fail error: "+err);
                        }
                        handler(res);
                    }
                });
                ParticipantRepo.getParticipantsBySessionId(sessionId,handler);
            }
        })
    }
@ -76,17 +65,7 @@ class Participants extends RedisModel {
                  handler(exists);
              })
          }else{//不存在从数据库中获取
              let sql ="select count(1) as count from participants w where w.session_id =? and w.participaint_id = ? ";
              imDb.execQuery({
                  "sql": sql,
                  "args": [sessionId,userId],
                  "handler": function (err, res) {
                      if(err) {
                          log.error("existsUser is fail error: "+err);
                      }
                      handler(res[0].count);
                  }
              });
              ParticipantRepo.existsUser(sessionId,userId,handler);
          }
      })
    }
@ -98,20 +77,7 @@ class Participants extends RedisModel {
     * @param doctor
     */
    getSessionIdByParticipants(patient,doctor,handler){
        let sql ="select session_id from "+IMTABLE.PARTICIPANTS+" p1 ,participants p2 " +
            "where p1.session_id = p2.session_id and " +
            "((p1.participaint_id = ? and p2.participaint_id = ?) or (p1.participaint_id = ? and p2.participaint_id = ?))"
        imDb.execQuery({
            "sql": sql,
            "args": [patient,doctor,doctor,patient],
            "handler": function (err, res) {
                if(err) {
                    log.error("getSessionIdByParticipants is fail error: "+err);
                }
                handler(err,res);
            }
        });
        ParticipantRepo.getSessionIdByParticipants(patient,doctor,handler);
    }
    /**
@ -140,28 +106,7 @@ class Participants extends RedisModel {
     * @param users
     */
    createParticipantsToMysql(session_id,users){
        let sql="insert into "+IMTABLE.PARTICIPANTS +" (session_id,participaint_id,participaint_role,receiving) VALUES "
        let args=[];
        for(var j in users){
            sql+="(?,?,?,?),";
            args.push(session_id);
            args.push(users[j]);
            args.push(0);
            args.push(0);
        }
        sql = sql.substring(0,sql.lastIndexOf(","));
        imDb.execQuery({
            "sql": sql,
            "args": args,
            "handler": function (err, res) {
                if(err) {
                    log.error("createParticipantsForMysql is fail error: "+err+",session_id:"+session_id+",users:"+users.join(","));
                }else{
                   return res;
                }
            }
        });
        return true;
        return createParticipantsToMysql(session_id,users);
    }
    /**

+ 2 - 2
src/server/repository/mysql/message.repo.js

@ -6,7 +6,7 @@
let ImDb = require('../mysql/db/im.db');
let log = require('../../util/log.js');
const IMTABLE = require('../../include/commons').IM_DB;
class SessionRepo {
class MessageRepo {
    constructor() {
    }
    /**
@ -118,4 +118,4 @@ class SessionRepo {
}
module.exports = SessionRepo;
module.exports = MessageRepo;

+ 104 - 0
src/server/repository/mysql/participant.repo.js

@ -0,0 +1,104 @@
/**
 * 搜索功能。
 */
"use strict";
let ImDb = require('../mysql/db/im.db');
let log = require('../../util/log.js');
const IMTABLE = require('../../include/commons').IM_DB;
class ParticipantRepo {
    constructor() {
    }
    /**
     * 获取某个会话中的成员信息
     * @param sessionId
     * @param handler
     */
    static getParticipantsBySessionId(sessionId,handler){
        let sql ="select w.* from participants w where w.session_id =? ";
        ImDb.execQuery({
            "sql": sql,
            "args": [sessionId],
            "handler": function (err, res) {
                if(err) {
                    log.error("getParticipantsBySessionId is fail error: "+err);
                }
                handler(res);
            }
        });
    }
    /**
     * 判断用户是否存在session中
     * @param sessionId
     * @param userId
     * @param handler
     */
    static existsUser(sessionId,userId,handler){
        let sql ="select count(1) as count from participants w where w.session_id =? and w.participaint_id = ? ";
        ImDb.execQuery({
            "sql": sql,
            "args": [sessionId,userId],
            "handler": function (err, res) {
                if(err) {
                    log.error("existsUser is fail error: "+err);
                }
                handler(res[0].count);
            }
        });
    }
     /**
     * 根据医生和患者
     * @param patient
     * @param doctor
     */
     static getSessionIdByParticipants(patient,doctor,handler){
        let sql ="select session_id from "+IMTABLE.PARTICIPANTS+" p1 ,participants p2 " +
            "where p1.session_id = p2.session_id and " +
            "((p1.participaint_id = ? and p2.participaint_id = ?) or (p1.participaint_id = ? and p2.participaint_id = ?))"
         ImDb.execQuery({
            "sql": sql,
            "args": [patient,doctor,doctor,patient],
            "handler": function (err, res) {
                if(err) {
                    log.error("getSessionIdByParticipants is fail error: "+err);
                }
                handler(err,res);
            }
        });
    }
    /**
     * mysql成员创建
     * @param users
     */
    createParticipantsToMysql(session_id,users){
        let sql="insert into "+IMTABLE.PARTICIPANTS +" (session_id,participaint_id,participaint_role,receiving) VALUES "
        let args=[];
        for(var j in users){
            sql+="(?,?,?,?),";
            args.push(session_id);
            args.push(users[j]);
            args.push(0);
            args.push(0);
        }
        sql = sql.substring(0,sql.lastIndexOf(","));
        ImDb.execQuery({
            "sql": sql,
            "args": args,
            "handler": function (err, res) {
                if(err) {
                    log.error("createParticipantsForMysql is fail error: "+err+",session_id:"+session_id+",users:"+users.join(","));
                }else{
                    return res;
                }
            }
        });
        return true;
    }
}
module.exports = ParticipantRepo;