Browse Source

ydf项目处理

8 năm trước cách đây
mục cha
commit
985064e71f

+ 25 - 4
src/doctor/models/doctor.js

@ -314,7 +314,7 @@ class Doctor extends BaseModel {
                return;
            }
            let chats = {patients: {p2p:[],group:[]}, doctors: {p2p:[],group:[]}};
            let chats = {patients: {p2p:[],group:[]}, doctors: {p2p:[],group:[]},system:{system:[],appo:[]}};
            for (let i = 0; i < patients.length; i++) {
                let patient = patients[i];
                chats.patients.p2p.push({
@ -368,8 +368,21 @@ class Doctor extends BaseModel {
                                timestamp: objectUtil.timestampToLong(group.timestamp)
                            });
                        }
                        modelUtil.emitData(self.eventEmitter, chats);
                        smRepo.getAppoList(userId,function(err,appo){
                            if (err) {
                                modelUtil.emitDbError(self.eventEmitter, 'Get group list with doctor failed', err);
                                return;
                            }
                            chats.system.appo = appo;
                            smRepo.getSystemList(userId,function(err,sys){
                                if (err) {
                                    modelUtil.emitDbError(self.eventEmitter, 'Get group list with doctor failed', err);
                                    return;
                                }
                                chats.system.system = sys;
                                modelUtil.emitData(self.eventEmitter, chats);
                            })
                        })
                    });
            });
        });
@ -535,7 +548,15 @@ class Doctor extends BaseModel {
                    }
                    chats.patient  = patientAmount;
                    modelUtil.emitData(self.eventEmitter, chats);
                    pmRepo.countAppo(userId,function(err, res){
                        if (err) {
                            modelUtil.emitDbError(self.eventEmitter, 'Get chat list with patient failed', err);
                            return;
                        }else{
                            chats.appo  = chats.patient+res[0].cou;
                        }
                        modelUtil.emitData(self.eventEmitter, chats);
                    })
                });
            });
        });

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

@ -13,7 +13,7 @@ exports.save = function (from, groupId, at, contentType, content, handler) {
exports.findAllMessages = function (groupId, contentType, start, end, count, handler) {
    var sql = "SELECT to_gid, msg_id, from_uid, at_uid, type, content, timestamp " +
        "FROM msg_group " +
        "WHERE to_gid = ? AND type in(" + contentType + ") AND msg_id BETWEEN ? AND ? ORDER BY timestamp DESC LIMIT ?";
        "WHERE to_gid = ? AND type in(" + contentType + ") AND msg_id BETWEEN ? AND ? ORDER BY timestamp,msg_id DESC LIMIT ?";
    imRepo.execQuery({
        "sql": sql,

+ 22 - 4
src/doctor/repository/private.msg.repo.js

@ -100,10 +100,10 @@ exports.findAllP2PWithPatient = function (userId, handler) {
    //    "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. 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 " ;
        "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],
@ -129,4 +129,22 @@ exports.findUnread = function(from, to, start, count, handler) {
        "args": [from, to, start, count],
        "handler": handler
    });
};
/**
 * 统计预约数量
 * @param userId
 * @param handler
 */
exports.countAppo = 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, 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 count(1) as cou FROM ydf_message m,ydf_appointment a where m.appointment_id = a.id and a.`status` = 0 and m.type=201 and m.receiver = ? " ;
    imRepo.execQuery({
        "sql": sql,
        "args": [userId],
        "handler": handler
    });
};

+ 31 - 12
src/doctor/repository/stats.msg.repo.js

@ -12,6 +12,9 @@ var config = require('../resources/config/' + configFile);
var log = require('../util/log');
var wlyyRepo = require("./database/wlyy.db.js");
var imRepo = require("./database/im.db.js");
let doctorRepo = require('../repository/doctor.repo.js');
let gmRepo = require('../repository/group.msg.repo');
let pmRepo = require('../repository/private.msg.repo');
var WLYY_ENPOINTS = require('../include/endpoints').WLYY_ENPOINTS;
@ -208,7 +211,33 @@ exports.clearGroupChatSummary = function clearGroupChatInfo(userId, groupId, han
//--------------------Others--------------------
exports.getAppMsgAmount = function (userId, handler) {
        let new_msg_count =0;
        // 先获取医生间的私聊
        pmRepo.findAllP2PWithDoctor(userId, function (err, doctors) {
            for (let i = 0; i < doctors.length; i++) {
                let doctor = doctors[i];
                new_msg_count = doctor.new_msg_count+new_msg_count;
            }
            // 再获取医生间的组
            gmRepo.findAllGroupsWithDoctor(userId, function (err, groups) {
                for (let i = 0; i < groups.length; i++) {
                    let group = groups[i];
                    new_msg_count =   group.new_msg_count+new_msg_count;
                }
                //获取患者记录数量
                pmRepo.findAllP2PWithPatient(userId, function (err, patients) {
                    for (let i = 0; i < patients.length; i++) {
                        let patient = patients[i];
                        new_msg_count =new_msg_count+ patient.new_msg_count;
                    }
                    pmRepo.countAppo(userId,function(err, res){
                        new_msg_count  = new_msg_count+res[0].cou;
                        return new_msg_count;
                    })
                });
            });
        });
};
exports.getBadgeNumber = function (userId, handler) {
@ -223,18 +252,8 @@ exports.getBadgeNumber = function (userId, handler) {
                    if (err) {
                        callback(null, 0);
                    } else {
                        var count = 0;
                        try {
                            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);
                        }
                        var count = result;
                        callback(null, count);
                    }
                });
            }],

+ 18 - 0
src/doctor/repository/system.msg.repo.js

@ -10,3 +10,21 @@ exports.save = function(to, contentType, title, summary, content, handler) {
        "handler": handler
    });
};
exports.getSystemList=function(userId, handler){
    let sql ="select count(1) as newMessageCount,max(m.content) as lastContent FROM ydf_message m  where  m.receiver = ? and m.type in(301,302,303,304,305) and m.readonly =1;";
    imRepo.execQuery({
        "sql": sql,
        "args": [userId],
        "handler": handler
    });
}
exports.getAppoList = function (userId, handler) {
    var sql="select count(1) as newMessageCount,max(m.content) as lastContent FROM ydf_message m,ydf_appointment a where m.appointment_id = a.id and a.`status` = 0 and m.type=201 and m.receiver = ? " ;
    imRepo.execQuery({
        "sql": sql,
        "args": [userId],
        "handler": handler
    });
};