Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/im.doctor into dev

Sand 8 years ago
parent
commit
199f68276e

+ 1 - 1
src/doctor/include/wlyy.endpoints.js

@ -9,7 +9,7 @@
exports.WLYY_ENPOINTS = {
    Doctor: {
        MessageCount: {
            Path: '/wlyy/doctor/message/amount',
            Path: '/wlyy/doctor/message/messages',
            Method: 'POST'
        }
    }

+ 9 - 1
src/doctor/models/doctor.js

@ -458,6 +458,8 @@ class Doctor extends BaseModel {
            var amount = 0;
            for (let i = 0; i < doctors.length; i++) {
                let doctor = doctors[i];
                //过滤结束的咨询
                //if(doctor.last_content_type==7)continue;
                amount = doctor.new_msg_count+amount;
            }
            // 再获取医生间的组
@ -469,6 +471,8 @@ class Doctor extends BaseModel {
                for (let i = 0; i < groups.length; i++) {
                    let group = groups[i];
                    //过滤结束的咨询
                    //if(group.last_content_type==7)continue;
                    amount =   group.new_msg_count+amount;
                }
                chats.doctor = amount;
@ -481,6 +485,8 @@ class Doctor extends BaseModel {
                    }
                    for (let i = 0; i < patients.length; i++) {
                             let patient = patients[i];
                            //过滤结束的咨询
                            // if(patient.last_content_type==7)continue;
                             patientAmount =patientAmount+ patient.new_msg_count;
                    }
@ -494,6 +500,8 @@ class Doctor extends BaseModel {
                            let group = groups[i];
                            // 过滤掉医生间的求助团队
                            if (group.group_type === 2) continue;
                            //过滤结束的咨询
                            //if(group.last_content_type==7)continue;
                            patientAmount = patientAmount+ group.new_msg_count;
                        }
                        chats.patient = patientAmount;
@ -518,7 +526,7 @@ class Doctor extends BaseModel {
    getPrivateMessages(userId, peerId, contentType, msgStartId, msgEndId, count, closedInterval) {
        let self = this;
        pmRepo.findAllMessages(userId, peerId, contentType === undefined ? "1,2,3,4,5,6" : contentType, msgStartId, msgEndId, count, closedInterval, function (err, rows) {
        pmRepo.findAllMessages(userId, peerId, contentType === undefined ? "0,1,2,3,4,5,6" : contentType, msgStartId, msgEndId, count, closedInterval, function (err, rows) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get private message failed', err);
                return;

+ 9 - 1
src/doctor/models/group.js

@ -92,7 +92,15 @@ class GroupMessage extends BaseModel {
                                        new Patient().pushGroupMessage(msg);
                                    },
                                    function () {
                                        Doctor.pushMessage(message, 'group_msg');
                                        let msg = {
                                            from: message.from,
                                            to: userId,
                                            contentType: message.contentType,
                                            content: message.content,
                                            msgId: groupMsg[0].msg_id,
                                            group: message.group
                                        };
                                        Doctor.pushMessage(msg, 'group_msg');
                                        // 更新用户组内消息摘要
                                        let at = message.at == userId ? 1 : 0;

+ 17 - 6
src/doctor/models/patient.js

@ -22,6 +22,7 @@ const CONTENT_TYPES = require('../include/commons').CONTENT_TYPE;
let clientCache = require('./socket.io/client.cache').clientCache();
let doctorRepo = require('../repository/doctor.repo');
let groupRepo = require('../repository/group.repo');
let wechatUtil = require('../util/wechatUtil');
@ -72,7 +73,7 @@ class Patient extends BaseModel {
            }
            // 结束网络连接,后续操作继续执行
            pmRepo.findOneMessage(result.insertId, function (err, msg) {
            pmRepo.findOnePatientMessage(result.insertId, function (err, msg) {
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, 'Save private message success, but return last message failed', err);
                    return;
@ -88,8 +89,9 @@ class Patient extends BaseModel {
                    self.sendConsultWechatReplyTempMsg(message);
                    return;
                }
                patientClient.socketServer.sockets.emit('message', message);
                let row = msg[0];
                row.timestamp = objectUtil.timestampToLong(row.timestamp);
                patientClient.socketServer.sockets.emit('message', row);
            });
            // 更新自身的聊天统计信息
@ -119,8 +121,17 @@ class Patient extends BaseModel {
            self.sendConsultWechatReplyTempMsg(message);
            return;
        }
        groupRepo.getOnGroupMsg(message.msgId, function (err, result) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, "get group msg info failed", err);
            }
        patientClient.socketServer.sockets.emit('message', message);
            var msg = result ? result[0] : "";
            if (msg) {
                patientClient.socketServer.sockets.emit('message', msg);
            }
        })
    };
    /**
@ -142,9 +153,8 @@ class Patient extends BaseModel {
                case CONTENT_TYPES.Audio:
                    replyContent = "[语音]";
                    break;
                case 0:
                case CONTENT_TYPES.Article:
                    replyContent = "[文章]";
                    break;
                case CONTENT_TYPES.GoTo:
                case CONTENT_TYPES.SessionBegin:
                case CONTENT_TYPES.SessionEnd:
@ -153,6 +163,7 @@ class Patient extends BaseModel {
                    break;
            }
            // 模板消息数据
            var msg = {
                touser: openid,

+ 2 - 1
src/doctor/models/search.js

@ -341,7 +341,8 @@ class Search extends BaseModel {
                        content: t.content,
                        type: t.type,
                        msg_id: t.msg_id,
                        groupType: t.group_type
                        groupType: t.group_type,
                        avatar:t.photo
                    };
                    data.push(message);
                }

+ 14 - 12
src/doctor/models/socket.io/client.cache.js

@ -11,46 +11,48 @@ var log = require('../../util/log');
var clientCache = null;
class ClientCache {
    constructor(){
    constructor() {
        this._clientsBySocket = new Map();
        this._clientsByUserId = new Map();
    }
    get clients(){
    get clients() {
        return this._clientsByUserId;
    }
    addClient(client){
    addClient(client) {
        this._clientsByUserId.set(client.userId, client);
        this._clientsBySocket.set(client.socket, client);
        //log.info('Current clients: ', this.clients);
    }
    removeByUserId(userId){
    removeByUserId(userId) {
        var socket = this.findById(userId);
        this._clientsByUserId.delete(userId);
        this._clientsBySocket.delete(socket);
    }
    removeByUserSocket(socket){
        var userId = this.findBySocket(socket);
    removeByUserSocket(socket) {
        var client = this.findBySocket(socket);
        this._clientsByUserId.delete(userId);
        this._clientsBySocket.delete(socket);
        if (client) {
            this._clientsByUserId.delete(client.userId);
            this._clientsBySocket.delete(socket);
        }
    }
    findById(userId){
    findById(userId) {
        return this._clientsByUserId.get(userId);
    }
    findBySocket(socket){
    findBySocket(socket) {
        return this._clientsBySocket.get(socket);
    }
    static clientCache(){
        if(clientCache === null){
    static clientCache() {
        if (clientCache === null) {
            clientCache = new ClientCache();
        }

+ 2 - 2
src/doctor/public/html/socket/test.html

@ -42,7 +42,7 @@
<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect();
    socket.emit('login', {userId: $('#patient_id').val(), password: $('#password').val()});
    socket.on('message', function (data) {
        console.log(data.message);
    });
@ -60,7 +60,7 @@
    });
    $('#login').click(function () {
        socket.emit('login', {userId: $('#patient_id').val(), password: $('#password').val()});
    });
    $('#logout').click(function () {

File diff suppressed because it is too large
+ 3 - 8
src/doctor/repository/group.msg.repo.js


+ 9 - 1
src/doctor/repository/group.repo.js

@ -9,6 +9,14 @@
var wlyyRepo = require("./database/wlyy.db.js");
var GROUP_TYPE = require('../include/commons').GROUP_TYPE;
exports.getOnGroupMsg=function(msgid,handler){
    wlyyRepo.execQuery({
        "sql": " select g.*,d.`name`,d.photo from msg_group g,wlyy.wlyy_doctor d where g.msg_id=? and g.from_uid=d.code;",
        "args": [msgid],
        "handler": handler
    });
}
/**
 * 判断是否为团队成员。
 *
@ -87,7 +95,7 @@ exports.getMembersAvatar = function (groups, handler) {
};
exports.getGroupConsultInfo = function (code, handler) {
    var sql = "select t.* from wlyy_talk_group g join wlyy_consult_team t on g.consult_code = t.consult where g.code = ? and g.type = 1";
    var sql = "select t.* from wlyy_talk_group g join wlyy_consult_team t on g.consult_code = t.consult where g.code = ? and g.type = 1 and t.status = 0 and t.del = '1'";
    wlyyRepo.execQuery({
        "sql": sql,

+ 2 - 2
src/doctor/repository/notify.msg.repo.js

@ -21,8 +21,8 @@ let imRepo = require("./database/im.db.js");
 */
exports.save = function(to, contentType, title, content, message, has_pushed, delay, handler) {
    imRepo.execQuery({
        "sql": "INSERT INTO push_notify (to_uid, type, title, content, data, delay, has_pushed) VALUES (?,?,?,?,?,?)",
        "args": [to, contentType, title, content, message, has_pushed],
        "sql": "INSERT INTO push_notify (to_uid, type, title, content, data, delay, has_pushed) VALUES (?,?,?,?,?,?,?)",
        "args": [to, contentType, title, content, message,delay, has_pushed],
        "handler": handler
    });
};

+ 19 - 3
src/doctor/repository/private.msg.repo.js

@ -27,6 +27,15 @@ exports.findOneMessage = function (messageId, handler) {
  });
};
exports.findOnePatientMessage = function (messageId,handler) {
    imRepo.execQuery({
        "sql": "SELECT m.*,d.name,d.photo FROM msg_p2p m, wlyy.wlyy_doctor d, wlyy.wlyy_patient p WHERE m.from_uid = d. CODE AND m.to_uid = p. CODE AND m.msg_id =?",
        "args": [messageId],
        "handler": handler
    });
};
/**
 * 查找所有消息。
 *
@ -93,11 +102,18 @@ exports.findAllP2PWithPatient = function (userId, handler) {
    var sql="SELECT p1. CODE as code , p1. NAME as name, p1.birthday, p1.sex, p1.photo, w.last_content, w.last_content_type, w. TIMESTAMP as timestamp, w.new_msg_count " +
             "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w " +
             "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " +
             "AND p.type IN (1, 2, 3, 5, 6) AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL " +
        "GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo"
             "AND w.last_content_type IN (1, 2, 3, 5, 6) AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL " +
            "GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo " +
            "union all " +
            "SELECT p1. CODE AS code, p1. NAME AS name, p1.birthday, p1.sex, p1.photo, w.last_content, t.type, w. TIMESTAMP AS timestamp, w.new_msg_count " +
            "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w, wlyy.wlyy_consult_team t " +
            "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " +
            "AND w.last_content_type = 7 AND t.type = 6 " +
            "AND (( t.patient = p.from_uid AND t.doctor = p.to_uid ) OR ( t.patient = p.to_uid AND t.doctor = p.from_uid )) " +
            "AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo;";
    imRepo.execQuery({
        "sql": sql,
        "args": [userId, userId,userId],
        "args": [userId, userId,userId,userId, userId,userId],
        "handler": handler
    });
};

+ 15 - 10
src/doctor/repository/search.repo.js

@ -183,7 +183,7 @@ module.exports.searchDoctorsContentDetail = function(userId,keyword,groupcode,ty
            imRepo.execQuery({
                "sql": p2psql,
                "args": [userId,groupcode,userId,groupcode,"%" + keyword + "%"],
                "args": [groupcode,userId,groupcode,userId,"%" + keyword + "%"],
                "handler": handler
            });
        }
@ -195,17 +195,22 @@ module.exports.searchDoctorsContentDetail = function(userId,keyword,groupcode,ty
 * 搜索聊天过的医生(仅限群组聊天)
 */
module.exports.searchGroupDoctors = function(userId,keyword,handler){
    var sql ="SELECT g.`code`, g.`name`,g.type as group_type, (( SELECT group_concat(temp.member_name) FROM wlyy.wlyy_talk_group_member temp WHERE temp.group_code = g. CODE and  t.type<4 AND temp.member_name LIKE ? )) AS con " +
        "FROM msg_group w, wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member t " +
        "WHERE w.to_gid = g.`code` and  t.type<4 " +
        "AND t.group_code = g. CODE " +
        "AND w.to_gid IN ( SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.member_code = ? ) " +
        "AND W.to_gid NOT IN (SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.group_code = g.code and  w1. STATUS = 1  AND w1.TYPE =4) "+
        "AND ( g.`name` LIKE ? OR t.member_name LIKE ?) " +
        "GROUP BY g. NAME, g.`code` order by w.msg_id desc";
    var sql ="SELECT g.`code`, g.`name`,'2' as group_type, (( SELECT group_concat(temp.member_name) FROM wlyy.wlyy_talk_group_member temp WHERE temp.group_code = g. CODE and  t.type<4 AND temp.member_name LIKE ? )) AS con " +
            "FROM msg_group w, wlyy.wlyy_talk_group g, wlyy.wlyy_talk_group_member t " +
            "WHERE w.to_gid = g.`code` and  t.type<4 " +
            "AND t.group_code = g. CODE " +
            "AND w.to_gid IN ( SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.member_code = ? ) " +
            "AND W.to_gid NOT IN (SELECT w1.group_code FROM wlyy.wlyy_talk_group_member w1 WHERE w1.group_code = g.code and  w1. STATUS = 1  AND w1.TYPE =4) "+
            "AND ( g.`name` LIKE ? OR t.member_name LIKE ?) " +
            "GROUP BY g. NAME, g.`code` " +
            " UNION ALL" +//下面是行政团队信息
            " SELECT g.id CODE, g. NAME NAME, '1' AS group_type, " +
            "( SELECT group_concat(temp. NAME) FROM wlyy.wlyy_admin_team_member m1, wlyy.wlyy_doctor temp WHERE temp. CODE = m1.doctor_code AND m1.team_id = g.id AND temp.`name` LIKE ? ) AS con " +
            " FROM wlyy.wlyy_admin_team g, wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d, msg_statistic ms " +
            " WHERE d. CODE = m.doctor_code AND m.team_id = g.id AND g.id = ms.from_gid AND ms.uid = ? AND ms.last_content_type IN (1, 2, 3, 5, 6) AND (d. NAME LIKE ? OR g. NAME LIKE ?) GROUP BY g.id, g. NAME";
    imRepo.execQuery({
        "sql": sql,
        "args": ["%" + keyword + "%",userId,  "%" + keyword + "%", "%" + keyword + "%"],
        "args": ["%" + keyword + "%",userId,  "%" + keyword + "%", "%" + keyword + "%", "%" + keyword + "%",userId, "%" + keyword + "%", "%" + keyword + "%"],
        "handler": handler
    });
}

+ 29 - 11
src/doctor/repository/stats.msg.repo.js

@ -36,7 +36,7 @@ exports.getChatList = function (userId, handler) {
 * @param userId
 * @param handler
 */
exports.getChatAllUnReadCount = function (userId, handler) {
  exports.getChatAllUnReadCount = function (userId, handler) {
    imRepo.execQuery({
        "sql": "SELECT new_msg_count from msg_statistic WHERE uid=? AND new_msg_count>0",
        "args": [userId],
@ -50,6 +50,7 @@ exports.updatePrivateChatSummary = function (userId, peerId, from, type, content
    if (userId == from) {
        //userId  = from ,peerId = to from = from
        // 更新自身的统计信息
        var sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content,new_msg_count) " +
            "VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE peer_uid=?,last_content_type=?,last_content=?";
@ -59,15 +60,29 @@ exports.updatePrivateChatSummary = function (userId, peerId, from, type, content
            "handler": handler
        });
    } else {
        var sql ="";
        if(type==7){//结束的咨询
            //userId  = to ,peerId = from, from = from
            sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content) " +
                "VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE peer_uid=?,last_content_type=?,last_content=?";
            // 更新对端的统计信息
            imRepo.execQuery({
                "sql": sql,
                "args": [userId, uuid, from, peerId, 1, type, content, peerId, type, content],
                "handler": handler
            });
        }else{
        //userId  = to ,peerId = from, from = from
        var sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content,new_msg_count) " +
         sql = "INSERT INTO msg_statistic (uid,uuid,from_uid,peer_uid,msg_type,last_content_type,last_content,new_msg_count) " +
            "VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE peer_uid=?,last_content_type=?,last_content=?,new_msg_count=new_msg_count+1";
        // 更新对端的统计信息
        imRepo.execQuery({
            "sql": sql,
            "args": [userId, uuid, from, peerId, 1, type, content, 1, peerId, type, content],
            "handler": handler
        });
            // 更新对端的统计信息
            imRepo.execQuery({
                "sql": sql,
                "args": [userId, uuid, from, peerId, 1, type, content, 1, peerId, type, content],
                "handler": handler
            });
        }
    }
};
@ -246,9 +261,12 @@ exports.getBadgeNumber = function (userId, handler) {
                    } else {
                        var count = 0;
                        try {
                            count += result.data.healthIndex;
                            count += result.data.sign;
                            count += result.data.consultTeam;
                            count += parseInt(result.data.healthIndex.amount);
                            count += parseInt(result.data.sign.amount);
                            count += parseInt(result.data.system.amount);
                            var immsg = JSON.parse(result.data.imMsgCount);
                            count+=parseInt(immsg.patient);
                            count+=parseInt(immsg.doctor);
                            callback(null, count);
                        } catch (e) {
                            callback(null, 0);

+ 22 - 34
src/doctor/resources/config/config.test.js

@ -1,23 +1,23 @@
"use strict";
let wlyyDbConfig = {
    host: '120.41.251.85',
    user: 'root',
    password: 't_s_6_7$1',
    database: 'wlyy_test',
var wlyyDbConfig = {
    host: '172.17.110.160',
    user: 'ssgg',
    password: 'ssgg',
    database: 'wlyy',
    connectionLimit: '100'
};
let imDbConfig = {
    host: 'localhost',
    user: 'root',
    password: '19991120',
    database: 'im_test',
var imDbConfig = {
    host: '172.17.110.160',
    user: 'ssgg',
    password: 'ssgg',
    database: 'im_new',
    connectionLimit: '100'
};
// 企业版的推送配置
let geTuiConfig = {
var geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'qWmRh2X88l7HuE36z3qBe8',
    APPKEY: 'EzERfV8c849lBkZqHWzQG1',
@ -25,44 +25,32 @@ let geTuiConfig = {
};
//AppStore版的推送App配置
let geTuiAppStoreCfg = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'H6FYbDejks6VjMmW3uH7V6',
    APPKEY: '0PFWlKmLBN9YzhCfFWVgYA',
    MASTERSECRET: 'pvjCGtRZJx9SRVODkxc816'
var geTuiAppStoreCfg = {
    HOST : 'https://api.getui.com/apiex.htm',
    APPID : 'H6FYbDejks6VjMmW3uH7V6',
    APPKEY : '0PFWlKmLBN9YzhCfFWVgYA',
    MASTERSECRET : 'pvjCGtRZJx9SRVODkxc816'
};
// 三师后台
let wlyyServerConfig = {
    host: '172.19.103.87',
    port: 9090
var wlyyServerConfig = {
    host: '172.19.103.88',
    port: 9092
};
// 透传服务
let transServerConfig = {
var transServerConfig = {
    host: '172.19.103.76',
    port: 8000
};
// 微信配置
let wechatConfig = {
    appId: 'wx1f129f7b51701428'
    , appSecret: '988f005d8309ed1795939e0f042431fb'
    , token: '27eb3bb24f149a7760cf1bb154b08040'
    , baseUrl: 'ehr.yihu.com/wlyy'
    , template: {
        // 咨询回复模板
        consultTemplate: '-dr4QNyFoRvVsf8uWxXMC1dRyjwnbUuJwJ21vBLhf18'
    }
};
exports.app = 'im.server';
exports.version = '1.2.7';
exports.version = '1.0.2.20160805';
exports.debug = true;
exports.serverPort = 3000;
exports.sessionExpire = 1800;
exports.showSQL = true;
exports.showSQL= true;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;