Просмотр исходного кода

Merge branch 'feature-1.2.6' of Amoy/im.doctor into dev

linzhuo 8 лет назад
Родитель
Сommit
5e723eb037

+ 1 - 1
src/doctor/app.js

@ -45,7 +45,7 @@ app.set('view engine', 'jade');
app.use(favicon(__dirname + '/public/favicon.ico', null));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.urlencoded({extended: true}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

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

@ -208,6 +208,19 @@ router.get(APIv1.Chats.ListWithDoctor, function (req, res) {
    doctor.getChatListWithDoctor(userId);
});
router.get(APIv1.Chats.MsgAmount, 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.getChatListMsgAmount(userId);
});
/**
 * 获取最近聊天对象:包括患者,医生与讨论组。客户端自行根据需要提取患者、医生或讨论组数据。
 *

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

@ -16,7 +16,7 @@ const APIv1 = {
        List: "/list",
        ListWithPatient: "/list/patient",
        ListWithDoctor: "/list/doctor",
        MsgAmount:"/msg/amount",
        Recent: '/recent',
        SearchAboutPatient: '/search/patient',
        SearchAboutPatientList:'/search/patient/list',

+ 63 - 0
src/doctor/models/doctor.js

@ -427,6 +427,69 @@ class Doctor extends BaseModel {
        });
    }
    /**
     * 获取与医生,患者的聊天列表,包括:点对点,参与的讨论组。消息数量
     *
     * @param userId
     */
    getChatListMsgAmount(userId) {
        let self = this;
        let chats = {doctor: {}, patient: {}};
        // 先获取医生间的私聊
        pmRepo.findAllP2PWithDoctor(userId, function (err, doctors) {
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get chat list with doctor failed', err);
                return;
            }
            var amount = 0;
            for (let i = 0; i < doctors.length; i++) {
                let doctor = doctors[i];
                amount = doctor.new_msg_count+amount;
            }
            // 再获取医生间的组
            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];
                    amount =   group.new_msg_count+amount;
                }
                chats.doctor = amount;
                var patientAmount =0;
                //获取患者记录数量
                pmRepo.findAllP2PWithPatient(userId, function (err, patients) {
                    if (err) {
                        modelUtil.emitDbError(self.eventEmitter, 'Get chat list with patient failed', err);
                        return;
                    }
                    for (let i = 0; i < patients.length; i++) {
                             let patient = patients[i];
                             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;
                            patientAmount = patientAmount+ group.new_msg_count;
                        }
                        chats.patient = patientAmount;
                        modelUtil.emitData(self.eventEmitter, chats);
                    });
                });
            });
        });
    }
    /**
     * 获取与指定用户的聊天记录。
     *

+ 12 - 8
src/doctor/models/search.js

@ -127,7 +127,7 @@ class Search extends BaseModel{
                modelUtil.emitData(self.eventEmitter, data);
            });
        }
        if(type==2){
        if(type==3){
            searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
                if (err) {
                    log.error("Search patient on private messages failed: ", err);
@ -152,7 +152,7 @@ class Search extends BaseModel{
                modelUtil.emitData(self.eventEmitter, data);
            });
        }
        if(type==3){
        if(type==2){
            searchRepo.searchGroupPatients(userId, keyword, function (err, groups) {
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, "Search talk group failed", err);
@ -186,7 +186,7 @@ class Search extends BaseModel{
        searchRepo.searchPatientPMList(userId, keyword,groupId,type, function (err, chats) {
            var data = [];
            if (err) {
                log.error("Search patient on private messages failed: ", err);
                log.error("Search searchPatientPMList on private messages failed: ", err);
                res.status(500).send({message: "Search patient on private messages failed."});
                return;
            }
@ -226,7 +226,7 @@ class Search extends BaseModel{
                data.doctors.push({
                    code: doctor.code,
                    name: doctor.name,
                    hospitalName:doctor.name,
                    hospitalName:doctor.hospital_name,
                    sex: doctor.sex,
                    avatar: doctor.photo === null ? "" : doctor.photo
                });
@ -246,6 +246,7 @@ class Search extends BaseModel{
                            code: t.code,
                            name: t.name,
                            members: t.con,
                            groupType:t.group_type
                        };
                        data.groups.push(group);
                }
@ -264,7 +265,8 @@ class Search extends BaseModel{
                            amount: t.amount,
                            content:t.content,
                            type:t.type,
                            msg_id:t.msg_id
                            msg_id:t.msg_id,
                            groupType:t.group_type
                        };
                        data.content.push(message);
@ -309,6 +311,7 @@ class Search extends BaseModel{
                        code: t.code,
                        name: t.name,
                        members: t.con,
                        groupType:t.group_type
                    };
                    data.push(group);
                }
@ -329,8 +332,8 @@ class Search extends BaseModel{
                        amount: t.amount,
                        content:t.content,
                        type:t.type,
                        msg_id:t.msg_id
                        msg_id:t.msg_id,
                        groupType:t.group_type
                    };
                    data.push(message);
                }
@ -360,7 +363,8 @@ class Search extends BaseModel{
                        code: doctor.code,
                        name: doctor.name,
                        content:doctor.content,
                        msg_id:t.msg_id
                        msg_id:t.msg_id,
                        groupType:t.group_type
                    });
                }
                modelUtil.emitData(self.eventEmitter, data);

Разница между файлами не показана из-за своего большого размера
+ 12 - 11
src/doctor/repository/search.repo.js