Parcourir la source

ydf项目处理

il y a 8 ans
Parent
commit
e41f5914fa

+ 17 - 0
src/doctor/endpoints/chats.endpoint.js

@ -172,6 +172,23 @@ router.get(APIv1.Chats.List, function (req, res) {
    doctor.getChatList(userId);
});
/**
 * 获取参与的聊天列表,包括:点对点,@我,参与的讨论组,系统消息等。
 *
 * 请求URL:
 *  /chats/ydf/list?user_id=sand
 */
router.get(APIv1.Chats.YdfList, function (req, res) {
    let userId = req.query.user_id;
    if (userId === null) {
        throw {httpStatus: 406, message: 'Missing fields.'};
    }
    let doctor = new Doctor();
    controllerUtil.regModelEventHandler(doctor, res);
    doctor.getYdfList(userId);
});
/**
 * 获取与患者的聊天列表,包括:P2P,参与的讨论组和行政团队。

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

@ -12,7 +12,7 @@ const APIv1 = {
    Chats: {
        Base: "/api/v1/chats",
        YdfList:"/ydf/list",
        List: "/list",
        ListWithPatient: "/list/patient",
        ListWithDoctor: "/list/doctor",

+ 74 - 18
src/doctor/models/doctor.js

@ -98,6 +98,10 @@ class Doctor extends BaseModel {
     * @param channel
     */
    static pushMessage(message, channel){
        console.log(JSON.stringify(message));
        if(message.contentType ==CONTENT_TYPES.SessionEnd){
            return;
        }
        doctorRepo.getUserStatus(message.to, function (err, result) {
            if (err) {
                log.error('Lookup notify message receiver failed: ' + message.to);
@ -329,7 +333,74 @@ class Doctor extends BaseModel {
            })
        });
    }
    getYdfList(userId){
        let self = this;
        pmRepo.findAllP2PWithPatient(userId, function (err, patients) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get chat list with patient failed', err);
                return;
            }
            let chats = {patients: {p2p:[],group:[]}, doctors: {p2p:[],group:[]}};
            for (let i = 0; i < patients.length; i++) {
                let patient = patients[i];
                chats.patients.p2p.push({
                    code: patient.code,
                    name: patient.name,
                    birthday: patient.birthday,
                    sex: patient.sex,
                    avatar: patient.photo == null ? "" : patient.photo,
                    newMessageCount: patient.new_msg_count,
                    lastContentType: patient.last_content_type,
                    lastContent: patient.last_content,
                    timestamp: objectUtil.timestampToLong(patient.timestamp)
                });
            }
                // 先获取医生间的私聊
                pmRepo.findAllP2PWithDoctor(userId, function (err, doctors) {
                    if (err) {
                        modelUtil.emitDbError(self.eventEmitter, 'Get chat list with doctor failed', err);
                        return;
                    }
                    for (let i = 0; i < doctors.length; i++) {
                        let doctor = doctors[i];
                        chats.doctors.p2p.push({
                            code: doctor.code,
                            name: doctor.name,
                            sex: doctor.sex,
                            avatar: doctor.photo === null ? "" : doctor.photo,
                            newMessageCount: doctor.new_msg_count,
                            lastContentType: doctor.last_content_type,
                            lastContent: doctor.last_content,
                            timestamp: objectUtil.timestampToLong(doctor.timestamp)
                        });
                    }
                    // 再获取医生间的组
                    gmRepo.findAllGroupsWithDoctor(userId, function (err, groups) {
                        if (err) {
                            modelUtil.emitDbError(self.eventEmitter, 'Get group list with doctor failed', err);
                            return;
                        }
                        for (let i = 0; i < groups.length; i++) {
                            let group = groups[i];
                            chats.doctors.group.push({
                                code: group.code,
                                name: group.name,
                                groupType: group.group_type, // 行政团队 or 求助
                                newMessageCount: group.new_msg_count,
                                lastContentType: group.last_content_type,
                                lastContent: group.last_content,
                                timestamp: objectUtil.timestampToLong(group.timestamp)
                            });
                        }
                        modelUtil.emitData(self.eventEmitter, chats);
                    });
            });
        });
    }
    /**
     * 获取与患者的聊天列表。
     */
@ -490,23 +561,8 @@ class Doctor extends BaseModel {
                             patientAmount =patientAmount+ patient.new_msg_count;
                    }
                    //获取患者记录数量
                    gmRepo.findAllGroupsWithPatient(userId, function (err, groups) {
                        if (err) {
                            modelUtil.emitDbError(self.eventEmitter, 'Get group list with patient failed', err);
                            return;
                        }
                        for (let i = 0; i < groups.length; i++) {
                            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;
                        modelUtil.emitData(self.eventEmitter, chats);
                    });
                    chats.patient  = patientAmount;
                    modelUtil.emitData(self.eventEmitter, chats);
                });
            });
        });
@ -526,7 +582,7 @@ class Doctor extends BaseModel {
    getPrivateMessages(userId, peerId, contentType, msgStartId, msgEndId, count, closedInterval) {
        let self = this;
        pmRepo.findAllMessages(userId, peerId, contentType === undefined ? "0,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,8,9" : contentType, msgStartId, msgEndId, count, closedInterval, function (err, rows) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get private message failed', err);
                return;

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

@ -133,7 +133,7 @@ class GroupMessage extends BaseModel {
     */
    getMessages(groupId, memberId, contentType, msgStartId, msgEndId, count) {
        let self = this;
        gmRepo.findAllMessages(groupId, !contentType ? "1,2,3,5,6" : contentType, msgStartId, msgEndId, count, function (err, rows) {
        gmRepo.findAllMessages(groupId, !contentType ? "1,2,3,5,6,8,9" : contentType, msgStartId, msgEndId, count, function (err, rows) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get group message failed', err);
                return;

+ 25 - 0
src/doctor/models/redisTest.js

@ -0,0 +1,25 @@
/**
 * Created by 卓 on 2016/12/7.
 */
exports.redis = function () {
    var redis = require('redis'),
        RDS_PORT = 6379,		//端口号
        RDS_HOST = '127.0.0.1',	//服务器IP
        RDS_OPTS = {},			//设置项
        client = redis.createClient(RDS_PORT,RDS_HOST,RDS_OPTS);
        client.on('ready',function(res){
            console.log('ready连接请求完毕');
        });
        client.on('connect',function(res){
            client.set("test","content包括中文",function(err,res){
                console.log(res);
                console.log("begin开始取数据~");
                client.get('test', function(err,res){
                    console.log(res);
                    console.log("end结束数据请求~");
                });
            });
        })
}

+ 28 - 63
src/doctor/models/search.js

@ -46,57 +46,41 @@ class Search extends BaseModel {
                };
                data.patients.push(p);
            }
            searchRepo.searchGroupPatients(userId, keyword, function (err, groups) {
            searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, "Search talk group failed", err);
                    modelUtil.emitDbError(self.eventEmitter, "Search patient on private messages failed", err);
                    return;
                }
                var group = null;
                for (var i = 0; i < groups.length; ++i) {
                    var t = groups[i];
                    group = {
                        code: t.code,
                        name: t.name,
                        members: t.con,
                for (var i = 0; i < chats.length; ++i) {
                    var lastPatient = {
                        code: '',
                        name: '',
                        sex: '',
                        avatar: '',
                        amount: '',
                        content: '',
                        chat: '',
                        type: ''
                    };
                    data.group.push(group);
                    var chat = chats[i];
                    console.log(JSON.stringify(chat));
                    lastPatient.code = chat.code;
                    lastPatient.name = chat.name;
                    lastPatient.sex = chat.sex;
                    lastPatient.birthday = objectUtil.timestampToLong(chat.birthday);
                    lastPatient.avatar = chat.photo === null ? "" : chat.photo;
                    lastPatient.amount = chat.amount;
                    lastPatient.chat = chat.chat;
                    lastPatient.content = chat.content;
                    lastPatient.type = chat.type;
                    lastPatient.msg_id = chat.msg_id;
                    data.chats.push(lastPatient);
                }
                searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
                    if (err) {
                        modelUtil.emitDbError(self.eventEmitter, "Search patient on private messages failed", err);
                        return;
                    }
                    for (var i = 0; i < chats.length; ++i) {
                        var lastPatient = {
                            code: '',
                            name: '',
                            sex: '',
                            avatar: '',
                            amount: '',
                            content: '',
                            chat: '',
                            type: ''
                        };
                        var chat = chats[i];
                        console.log(JSON.stringify(chat));
                        lastPatient.code = chat.code;
                        lastPatient.name = chat.name;
                        lastPatient.sex = chat.sex;
                        lastPatient.birthday = objectUtil.timestampToLong(chat.birthday);
                        lastPatient.avatar = chat.photo === null ? "" : chat.photo;
                        lastPatient.amount = chat.amount;
                        lastPatient.chat = chat.chat;
                        lastPatient.content = chat.content;
                        lastPatient.type = chat.type;
                        lastPatient.msg_id = chat.msg_id;
                        data.chats.push(lastPatient);
                    }
                    modelUtil.emitData(self.eventEmitter, data);
                });
                modelUtil.emitData(self.eventEmitter, data);
            });
        });
    }
    /**
@ -160,25 +144,6 @@ class Search extends BaseModel {
                modelUtil.emitData(self.eventEmitter, data);
            });
        }
        if (type == 2) {
            searchRepo.searchGroupPatients(userId, keyword, function (err, groups) {
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, "Search talk group failed", err);
                    return;
                }
                var group = null;
                for (var i = 0; i < groups.length; ++i) {
                    var t = groups[i];
                    group = {
                        code: t.code,
                        name: t.name,
                        members: t.con,
                    };
                    data.push(group);
                }
                modelUtil.emitData(self.eventEmitter, data);
            });
        }
    }
    /**

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

@ -16,7 +16,7 @@ var wlyyRepo = require("./database/wlyy.db.js");
 */
exports.isExist = function(user, handler) {
    wlyyRepo.execQuery({
        "sql": "SELECT count(*) from wlyy_doctor WHERE code=?",
        "sql": "SELECT count(*) from ydf_doctor WHERE code=?",
        "args": [user],
        "handler": handler
    });
@ -65,7 +65,7 @@ exports.updateStatus = function(userId, status, handler) {
exports.getDoctorInfo = function (code, handler) {
    wlyyRepo.execQuery({
        "sql":"select code,name from wlyy_doctor where code = ? ",
        "sql":"select id,name from ydf_doctor where id = ? ",
        "args":[code],
        "handler":handler
    });

Fichier diff supprimé car celui-ci est trop grand
+ 3 - 40
src/doctor/repository/group.msg.repo.js


+ 7 - 37
src/doctor/repository/group.repo.js

@ -11,7 +11,7 @@ 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;",
        "sql": " select g.*,d.`name`,d.photo from msg_group g,wlyy_doctor d where g.msg_id=? and g.from_uid=d.code;",
        "args": [msgid],
        "handler": handler
    });
@ -28,13 +28,7 @@ exports.getOnGroupMsg=function(msgid,handler){
exports.isGroupMember = function (groupId, groupType, doctorId, handler) {
    if (groupType == GROUP_TYPE.AdminTeam) {
        wlyyRepo.execQuery({
            "sql": "SELECT doctor_code user_id from wlyy_admin_team_member WHERE team_id=? and doctor_code=?",
            "args": [groupId, doctorId],
            "handler": handler
        });
    } else {
        wlyyRepo.execQuery({
            "sql": "SELECT member_code user_id from wlyy_talk_group_member WHERE group_code=? and member_code=?",
            "sql": "SELECT doctor_code user_id from ydf_doctor_team_member WHERE team_id=? and doctor_code=?",
            "args": [groupId, doctorId],
            "handler": handler
        });
@ -51,13 +45,7 @@ exports.isGroupMember = function (groupId, groupType, doctorId, handler) {
exports.getMembers = function (groupId, groupType, handler) {
    if (groupType == GROUP_TYPE.AdminTeam) {
        wlyyRepo.execQuery({
            "sql": "SELECT doctor_code user_id from wlyy_admin_team_member WHERE team_id=? AND available = 1",
            "args": [groupId],
            "handler": handler
        });
    } else {
        wlyyRepo.execQuery({
            "sql": "SELECT member_code user_id from wlyy_talk_group_member WHERE group_code=?",
            "sql": "SELECT doctor_code user_id from ydf_doctor_team_member WHERE team_id=? AND available = 1",
            "args": [groupId],
            "handler": handler
        });
@ -66,24 +54,16 @@ exports.getMembers = function (groupId, groupType, handler) {
exports.getMembersAvatar = function (groups, handler) {
    /*var sql = "SELECT m.member_code g_code, COUNT(m.member_code) member_count, d.code dr_code, d.name dr_name, d.photo dr_photo " +
     "FROM wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d " +
     "FROM wlyy_talk_group_member m, wlyy_doctor d " +
     "WHERE m.member_code = d.code AND m.group_code IN (" + groups + ") " +
     "UNION " +
     "SELECT m.team_id g_code, COUNT(m.team_id) member_count, d.code dr_code, d.name dr_name, d.photo dr_photo " +
     "FROM wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d " +
     "FROM ydf_doctor_team_member m, wlyy_doctor d " +
     "WHERE m.doctor_code = d.code AND m.team_id IN (" + groups + ") GROUP BY m.team_id";*/
    var sql = "SELECT * FROM(" +
        "SELECT m.group_code g_code, d.code code, d.name name, d.photo photo, 'doctor' type FROM " +
        "wlyy.wlyy_talk_group_member m, wlyy.wlyy_doctor d " +
        "WHERE m.member_code = d.code AND m.group_code IN (" + groups + ") " +
        " UNION " +
        "SELECT m.group_code g_code, p.code code, p.name name, p.photo photo, 'patient' type " +
        "FROM  wlyy.wlyy_talk_group_member m, wlyy.wlyy_patient p " +
        "WHERE m.member_code = p.code AND m.group_code IN (" + groups + ")" +
        " UNION " +
    var sql = "SELECT * FROM("+
        "SELECT m.team_id g_code, d.code code, d.name name, d.photo photo, 'doctor' type " +
        "FROM wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d " +
        "FROM ydf_doctor_team_member m, wlyy_doctor d " +
        "WHERE m.doctor_code = d.code AND m.team_id IN (" + groups + ") " +
        ") x ORDER BY x.g_code";
@ -93,13 +73,3 @@ exports.getMembersAvatar = function (groups, handler) {
        "handler": 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 and t.status = 0 and t.del = '1'";
    wlyyRepo.execQuery({
        "sql": sql,
        "args": [code],
        "handler": handler
    });
}

+ 3 - 3
src/doctor/repository/patient.repo.js

@ -9,7 +9,7 @@
var wlyyDb = require('./database/wlyy.db');
exports.isPatientCode = function (code, handler) {
    var sql = "select count(*) c from wlyy_patient where code = '" + code + "'";
    var sql = "select count(*) c from ydf_patient where id = '" + code + "'";
    wlyyDb.execQuery({
        "sql": sql,
@ -19,7 +19,7 @@ exports.isPatientCode = function (code, handler) {
};
exports.getPatientOpenid = function (code, handler) {
    var sql = "select openid from wlyy_patient where code = ? ";
    var sql = "select openid from ydf_patient where id = ? ";
    wlyyDb.execQuery({
        "sql": sql,
@ -29,7 +29,7 @@ exports.getPatientOpenid = function (code, handler) {
};
exports.getPatientDoctorConsult = function (patient, doctor, handler) {
    var sql = "select * from wlyy_consult_team where patient = ? and doctor = ? and status = 0 and del = '1' ";
    var sql = "select * from ydf_consult_team where patient = ? and doctor = ? and status = 0 and del = '1' ";
    wlyyDb.execQuery({
        "sql": sql,

+ 13 - 31
src/doctor/repository/private.msg.repo.js

@ -30,7 +30,7 @@ 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 =?",
        "sql": "SELECT m.*,d.name,d.photo FROM msg_p2p m, ydf.ydf_doctor d, ydf.ydf_patient p WHERE m.from_uid = d.id AND m.to_uid = p.id AND m.msg_id =?",
        "args": [messageId],
        "handler": handler
    });
@ -71,15 +71,15 @@ exports.findAllP2PWithDoctor = function (userId, handler) {
    //    "FROM (SELECT DISTINCT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " +
    //    "      FROM msg_statistic ms1, msg_statistic ms2 " +
    //    "      WHERE ms1.from_gid IS NULL AND ms2.from_gid IS NULL " +
    //    "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, wlyy.wlyy_doctor d " +
    //    "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, ydf.ydf_doctor d " +
    //    "WHERE x.id = ms3.id AND ms3.last_content_type in (1,2,3,5,6) AND " +
    //    "(ms3.uid = ? AND ms3.peer_uid = d.code) GROUP BY d.code, d.name ORDER BY ms3.timestamp DESC";
    var sql ="SELECT d. CODE as code, d. NAME as name,  d.sex, d.photo, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count " +
        "FROM msg_p2p p, wlyy.wlyy_doctor d, msg_statistic s " +
        "WHERE (( p.from_uid = d. CODE AND p.to_uid = ? ) OR ( p.to_uid = d. CODE AND p.from_uid = ? )) " +
    var sql ="SELECT d. id as code, d. NAME as name,  d.sex, d.photo, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count " +
        "FROM msg_p2p p, ydf.ydf_doctor d, msg_statistic s " +
        "WHERE (( p.from_uid = d. id AND p.to_uid = ? ) OR ( p.to_uid = d. id AND p.from_uid = ? )) " +
        "AND s.from_gid IS NULL AND s.uid = ? " +
        "AND s.peer_uid = d. CODE " +
        "GROUP BY d. NAME, d. CODE, d.hospital_name, d.job_name, d.sex, d.photo ORDER BY p.msg_id DESC"
        "AND s.peer_uid = d. id " +
        "GROUP BY d. NAME, d. id, d.hospital_name, d.job_name, d.sex, d.photo ORDER BY p.msg_id DESC"
    imRepo.execQuery({
        "sql": sql,
@ -96,21 +96,14 @@ exports.findAllP2PWithDoctor = function (userId, handler) {
 */
exports.findAllP2PWithPatient = function (userId, handler) {
    //var sql = "SELECT p.code, p.name, p.birthday, p.sex, p.photo, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count " +
    //    "FROM msg_statistic ms, wlyy.wlyy_patient p " +
    //    "FROM msg_statistic ms, ydf.ydf_patient p " +
    //    "WHERE ms.msg_type = 1 AND ms.last_content_type in (1,2,3,5,6) " +
    //    "AND ((ms.from_uid = ? AND ms.uid = p.code) OR (ms.uid = ? AND ms.from_uid = p.code)) ORDER BY ms.timestamp";
    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 w.last_content_type IN (0,1, 2, 3, 4, 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;";
    var sql="SELECT p1. id 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, ydf.ydf_patient p1, msg_statistic w " +
             "WHERE (( p.to_uid = p1.`id` AND p.from_uid = ? ) OR ( p.from_uid = p1.`id` AND p.to_uid = ? )) " +
             "AND w.last_content_type IN (0,1, 2, 3, 4, 5, 6,7) AND w.uid = ? AND w.peer_uid = p1.`id` AND w.from_gid IS NULL " +
             "GROUP BY p1. id, p1. NAME, p1.birthday, p1.sex, p1.photo " ;
    imRepo.execQuery({
        "sql": sql,
        "args": [userId, userId,userId,userId, userId,userId],
@ -136,15 +129,4 @@ exports.findUnread = function(from, to, start, count, handler) {
        "args": [from, to, start, count],
        "handler": handler
    });
};
exports.isCurrentSessionFinished = function (doctorId, patientId, handler) {
    var sql = "SELECT c.consult consult_id, case when c.end_msg_id is not null then 1 else 0 end finished " +
        "FROM wlyy.wlyy_consult_team c where c.doctor=? and c.patient = ? ORDER BY id DESC LIMIT 1";
    imRepo.execQuery({
        "sql": sql,
        "args": [doctorId, patientId],
        "handler": handler
    });
};

Fichier diff supprimé car celui-ci est trop grand
+ 34 - 111
src/doctor/repository/search.repo.js


+ 7 - 43
src/doctor/repository/stats.msg.repo.js

@ -13,7 +13,7 @@ var log = require('../util/log');
var wlyyRepo = require("./database/wlyy.db.js");
var imRepo = require("./database/im.db.js");
var WLYY_ENPOINTS = require('../include/wlyy.endpoints').WLYY_ENPOINTS;
var WLYY_ENPOINTS = require('../include/endpoints').WLYY_ENPOINTS;
//--------------------About all chats--------------------
/**
@ -122,15 +122,15 @@ exports.getPrivateChatAllUnReadCount = function (userId, handler) {
exports.getRecentChats = function (userId, days, handler) {
    var timespan = 60 * 60 * 24 * days; // 多少天内的联系对象
    var sql = "SELECT * FROM(" +
        "SELECT DISTINCT p.code code, p.name name, p.birthday birthday, p.sex sex, p.photo photo, ms.timestamp timestamp, 'patient' type " +
        "FROM msg_statistic ms, wlyy.wlyy_patient p " +
        "WHERE ms.uid = ? AND ms.uid = p.code AND " +
        "SELECT DISTINCT p.id code, p.name name, p.birthday birthday, p.sex sex, p.photo photo, ms.timestamp timestamp, 'patient' type " +
        "FROM msg_statistic ms, ydf_patient p " +
        "WHERE ms.uid = ? AND ms.uid = p.id AND " +
        "UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(ms.timestamp) < ? AND msg_type = 1" +
        " UNION " +
        "SELECT DISTINCT d.code code, d.name name, d.birthday birthday, d.sex sex, d.photo photo, ms.timestamp timestamp,'doctor' type " +
        "FROM msg_statistic ms, wlyy.wlyy_doctor d, (SELECT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " +
        "SELECT DISTINCT d.id code, d.name name, d.birthday birthday, d.sex sex, d.photo photo, ms.timestamp timestamp,'doctor' type " +
        "FROM msg_statistic ms, ydf_doctor d, (SELECT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " +
        "                                                   FROM msg_statistic ms1, msg_statistic ms2 " +
        "                                                   WHERE ms1.from_gid IS NULL AND ms2.from_gid IS NULL AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x " +
        "WHERE x.id = ms.id AND ((ms.uid = ? AND ms.peer_uid = d.code) OR (ms.uid = d.code AND ms.peer_uid = ?)) AND UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(ms.timestamp) < ?" +
@ -138,7 +138,7 @@ exports.getRecentChats = function (userId, days, handler) {
        " UNION " +
        "SELECT g.id code, g.name name, '' birthday, '' sex, '' photo, max(ms.timestamp) timestamp, 'type' ':group' " +
        "FROM msg_statistic ms, wlyy.wlyy_admin_team g, wlyy.wlyy_admin_team_member m, wlyy.wlyy_doctor d " +
        "FROM msg_statistic ms, ydf_doctor_team g, ydf_doctor_team_member m, ydf_doctor d " +
        "WHERE d.code = ? AND d.code = m.doctor_code AND m.team_id = g.id AND g.id = ms.from_gid " +
        "   AND (ms.uid = d.code or ms.from_uid = d.code) AND UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(ms.timestamp) < ? group by g.id, g.name " +
        ") x ORDER BY timestamp DESC";
@ -208,43 +208,7 @@ exports.clearGroupChatSummary = function clearGroupChatInfo(userId, groupId, han
//--------------------Others--------------------
exports.getAppMsgAmount = function (userId, handler) {
    wlyyRepo.execQuery({
        "sql": "SELECT imei,token from wlyy_token WHERE user=?",
        "args": [userId],
        "handler": function (err, result) {
            if (err || result.length == 0) {
                handler(null, 0);
                return;
            }
            var options = {
                hostname: config.wlyyServerConfig.host,
                port: config.wlyyServerConfig.port,
                path: WLYY_ENPOINTS.Doctor.MessageCount.Path,
                method: WLYY_ENPOINTS.Doctor.MessageCount.Method,
                headers: {
                    'userAgent': '{"token":"' + result[0].token + '","uid":"' + userId + '","imei":"' + result[0].imei + '"}'
                }
            };
            var req = http.request(options, function (res) {
                res.setEncoding('utf8');
                log.info('请求家庭医生平台: http://', options.hostname + ":" + options.port + options.path);
                res.on('data', function (chunk) {
                    log.info('家庭医生平台返回: ', chunk);
                    handler(null, JSON.parse(chunk));
                });
            });
            req.on('error', function (e) {
                log.error('家庭医生平台接口调用出错: ', e.message);
                handler(e, null);
            });
            req.end();
        }
    });
};
exports.getBadgeNumber = function (userId, handler) {

+ 6 - 5
src/doctor/resources/config/config.dev.js

@ -5,7 +5,7 @@ let wlyyDbConfig = {
    host: '172.19.103.77',
    user: 'root',
    password: '123456',
    database: 'wlyy',
    database: 'ydf',
    connectionLimit: '50'
};
@ -14,14 +14,15 @@ let imDbConfig = {
    host: '172.19.103.77',
    user: 'root',
    password: '123456',
    database: 'im_new',
    connectionLimit: '50'
    database: 'ydf',
    connectionLimit: '50',
    charset : 'utf8mb4'
};
// 三师后台
let wlyyServerConfig = {
    host: '172.19.103.87',
    port: 9092
    host: '172.19.103.31',
    port: 10000
};
// 透传服务

+ 2 - 1
src/doctor/resources/config/config.prod.js

@ -13,7 +13,8 @@ let imDbConfig = {
    user: 'wlyy',
    password: 'jkzlehr@123',
    database: 'wlyy',
    connectionLimit: '100'
    connectionLimit: '100',
    charset : 'utf8mb4'
};
// 企业版的推送配置

+ 2 - 1
src/doctor/resources/config/config.test.js

@ -13,7 +13,8 @@ var imDbConfig = {
    user: 'ssgg',
    password: 'ssgg',
    database: 'im_new',
    connectionLimit: '100'
    connectionLimit: '100',
    charset : 'utf8mb4'
};
// 企业版的推送配置