소스 검색

增加医生model

Sand 8 년 전
부모
커밋
ae6585875d

+ 2 - 2
src/server/models/patient.js

@ -23,7 +23,7 @@ const CONTENT_TYPES = require('../include/commons').CONTENT_TYPE;
let clientCache = require('./socket.io/client.cache').clientCache();
let doctorRepo = require('../repository/doctor.repo');
let DoctorRepo = require('../repository/doctor.repo');
let groupRepo = require('../repository/group.repo');
let wechatUtil = require('../util/wechatUtil');
@ -194,7 +194,7 @@ class Patient extends BaseModel {
            if (openid) {
                // 查询医生信息
                doctorRepo.getDoctorInfo(message.from, function (err, result) {
                DoctorRepo.findOne(message.from, function (err, result) {
                    if (err) {
                        modelUtil.emitDbError(self.eventEmitter, "get doctor info failed", err);
                        return;

+ 50 - 0
src/server/models/sync/user.synchronizer.js

@ -0,0 +1,50 @@
/**
 * 用户同步器,同步医生与患者数据。
 *
 * author: Sand
 * since: 12/9/2016
 */
"use strict";
let wlyyUserRepo = require('./../../repository/wlyy/wlyy.user.repo');
let SyncLog = require('./../../repository/sync.log');
let log = require("../../util/log");
class UserSynchronizer{
    constructor(){
    }
    /**
     * 同步用户列表。
     */
    static synchronizeUser(){
        let syncLog = new SyncLog();
        syncLog.getLastUserSynchronizeTime(function (err, res) {
            if(err) {
                log.error("User synchronize failed: ", err);
                return;
            }
            wlyyUserRepo.getUpdatedUsers(res.last_sync_time, function (err, res) {
                if(err) {
                    log.error("User synchronize failed: ", err);
                    return;
                }
                for(let i = 0; i < res.length; ++i){
                    let user = res[i];
                    if(user.type  === 'doctor'){
                    } else {
                    }
                }
                syncLog.updateUserSynchorizeLog(function (err, res) {
                    if(err) log.error("User synchronize failed: ", err);
                });
            });
        });
    }
}
module.exports = Users;

+ 67 - 56
src/server/repository/doctor.repo.js

@ -8,65 +8,76 @@ var log = require('../util/log');
var imRepo = require("./mysql/im.db.js");
var wlyyRepo = require("./mysql/wlyy.db.js");
/**
 * 判断用户是否存在。数据从家庭医生平台获取,而不是IM库的user表。
 *
 * @param user
 * @param handler
 */
exports.isExist = function(user, handler) {
    wlyyRepo.execQuery({
        "sql": "SELECT count(*) from wlyy_doctor WHERE code=?",
        "args": [user],
        "handler": handler
    });
};
class DoctorRepo {
    constructor() {
    }
    static update() {
    }
    static findOne(code, handler) {
        wlyyRepo.execQuery({
            "sql": "select code, name from doctors where code = ? ",
            "args": [code],
            "handler": handler
        });
    };
    /**
     * 判断用户是否存在。数据从家庭医生平台获取,而不是IM库的user表。
     *
     * @param user
     * @param handler
     */
    static isExist(user, handler) {
        wlyyRepo.execQuery({
            "sql": "SELECT count(*) from wlyy_doctor WHERE code=?",
            "args": [user],
            "handler": handler
        });
    };
exports.getUserStatus = function(userId, handler) {
    imRepo.execQuery({
        "sql": "SELECT platform,token,client_id,is_online,status from user WHERE user_id = ?",
        "args": [userId],
        "handler": handler
    });
};
    static getUserStatus(userId, handler) {
        imRepo.execQuery({
            "sql": "SELECT platform,token,client_id,is_online,status from user WHERE user_id = ?",
            "args": [userId],
            "handler": handler
        });
    };
exports.login = function(userId, token, client_id, platform, handler) {
    imRepo.execQuery({
        "sql": "INSERT INTO user (user_id,token,client_id,platform,is_online,status) VALUES (?,?,?,?,1,1) ON" +
        " DUPLICATE KEY UPDATE token=?,client_id=?,platform=?,is_online=1,status=1",
        "args": [userId, token, client_id, platform, token, client_id, platform],
        "handler": handler
    });
};
    static login(userId, token, client_id, platform, handler) {
        imRepo.execQuery({
            "sql": "INSERT INTO user (user_id,token,client_id,platform,is_online,status) VALUES (?,?,?,?,1,1) ON" +
            " DUPLICATE KEY UPDATE token=?,client_id=?,platform=?,is_online=1,status=1",
            "args": [userId, token, client_id, platform, token, client_id, platform],
            "handler": handler
        });
    };
exports.logout = function(userId, handler) {
    imRepo.execQuery({
        "sql": "UPDATE user SET is_online='0',status='0' WHERE user_id=?",
        "args": [userId],
        "handler": handler
    });
};
    static logout(userId, handler) {
        imRepo.execQuery({
            "sql": "UPDATE user SET is_online='0',status='0' WHERE user_id=?",
            "args": [userId],
            "handler": handler
        });
    };
exports.deleteToken = function(token, handler) {
    imRepo.execQuery({
        "sql": "DELETE FROM user WHERE token=?",
        "args": [token],
        "handler": handler
    });
};
    static deleteToken(token, handler) {
        imRepo.execQuery({
            "sql": "DELETE FROM user WHERE token=?",
            "args": [token],
            "handler": handler
        });
    };
exports.updateStatus = function(userId, status, handler) {
    imRepo.execQuery({
        "sql": "UPDATE user SET status=? WHERE user_id=?",
        "args": [status, userId],
        "handler": handler
    });
};
    static updateStatus(userId, status, handler) {
        imRepo.execQuery({
            "sql": "UPDATE user SET status=? WHERE user_id=?",
            "args": [status, userId],
            "handler": handler
        });
    };
}
exports.getDoctorInfo = function (code, handler) {
    wlyyRepo.execQuery({
        "sql":"select code,name from wlyy_doctor where code = ? ",
        "args":[code],
        "handler":handler
    });
};
module.exports = DoctorRepo;

+ 5 - 4
src/server/repository/redis/redis.client.js

@ -1,14 +1,15 @@
/**
 * 控制器辅助函数。
 * Redis客户端封装。
 *
 * author: linzhuo
 * since: 2016/11/22
 * since: 2016/12/09
 */
"use strict";
let redis = require('redis');
let configFile = require('../../include/commons').CONFIG_FILE;
let config = require('../../resources/config/' + configFile);
let redis = require('redis');
var log = require("../../util/log.js");
let log = require("../../util/log.js");
let redisClient = null;

+ 34 - 0
src/server/repository/sync.log.js

@ -0,0 +1,34 @@
/**
 *
 * author: Sand
 * since: 12/9/2016
 */
"use strict";
let imDb = require('./mysql/im.db');
class SyncLog{
    constructor(){}
    /**
     * 获取用户更新
     * @param handler
     */
    getLastUserSynchronizeTime(handler){
        imDb.execQuery({
            "sql": "select last_sync_time from sync_log where event = 'user_sync'",
            "args": [],
            "handler": handler
        });
    }
    updateUserSynchorizeLog(handler){
        imDb.execQuery({
            "sql": "update sync_log set last_sync_time = now()",
            "args": [],
            "handler": handler
        });
    }
}
module.exports = SyncLog;

+ 29 - 0
src/server/repository/wlyy/wlyy.user.repo.js

@ -0,0 +1,29 @@
/**
 * 家庭医生平台-用户,包含医生与患者。
 */
"use strict";
var log = require('../../util/log');
var wlyyRepo = require("./../mysql/wlyy.db.js");
class WlyyDoctorRepo{
    constructor(){
    }
    /**
     * 获取指定时间之后更新的医生数据。
     *
     * @param timestamp
     */
    static getUpdatedUsers(timestamp, handler){
        wlyyRepo.execQuery({
            "sql": "SELECT code, name, sex, birthday, photo, level, 'doctor' 'type' FROM wlyy.wlyy_doctor d where d.czrq > ? UNION " +
            "SELECT code, name, sex, birthday, photo, '', 'patient' 'type' FROM wlyy.wlyy_patient p where p.czrq > ?",
            "args": [timestamp, timestamp],
            "handler": handler
        });
    }
}
module.exports = WlyyDoctorRepo;

+ 8 - 0
src/server/resources/config/config.prod.js

@ -18,6 +18,13 @@ let imDbConfig = {
    charset : 'utf8mb4'
};
// Redis
let redisConfig = {
    host: '192.168.1.220',
    port: 6379,
    db: 1
};
// 企业版的推送配置
let geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
@ -67,6 +74,7 @@ exports.sessionExpire = 1800;
exports.showSQL = false;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;
exports.redisConfig = redisConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiAppStoreCfg = geTuiAppStoreCfg;

+ 8 - 0
src/server/resources/config/config.test.js

@ -18,6 +18,13 @@ var imDbConfig = {
    charset : 'utf8mb4'
};
// Redis
let redisConfig = {
    host: '192.168.1.220',
    port: 6379,
    db: 1
};
// 企业版的推送配置
var geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
@ -55,6 +62,7 @@ exports.sessionExpire = 1800;
exports.showSQL= true;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;
exports.redisConfig = redisConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiAppStoreCfg = geTuiAppStoreCfg;

+ 4 - 0
src/server/resources/schema/ichat_import_users.1.2.8.sql

@ -0,0 +1,4 @@
insert into doctors(id, name, sex, birthdate, avatar, level, locked) select code, name, sex, birthday, photo, level, 0 from wlyy.wlyy_doctor;
insert into patients(id, name, sex, birthdate, avatar) select distinct code, name, sex, birthday, photo from wlyy.wlyy_patient;
insert into sync_log(event, last_sync_time, succeed, message) values('user_sync', now(), 1, 'ok');

+ 71 - 70
src/server/resources/schema/ichat_schema.1.2.8.sql

@ -1,4 +1,12 @@
SET FOREIGN_KEY_CHECKS=0
/* ---------------------------------------------------- */
/*  Generated by Enterprise Architect Version 12.0 		*/
/*  Created On : 09-Dec-2016 10:34:58 AM 				*/
/*  DBMS       : MySql 						*/
/* ---------------------------------------------------- */
SET FOREIGN_KEY_CHECKS=0;
/* Drop Tables */
DROP TABLE IF EXISTS `topics` CASCADE
;
@ -27,111 +35,112 @@ DROP TABLE IF EXISTS `doctors` CASCADE
DROP TABLE IF EXISTS `patients` CASCADE
;
/* Create Tables */
CREATE TABLE `topics`
(
	`id` INTEGER NOT NULL,
	`session_id` VARCHAR(50) NOT NULL,
	`name` VARCHAR(50),
	`create_time` TIMESTAMP(0),
	`end_by` VARCHAR(50),
	`start_message_id` INTEGER,
	`end_message_id` INTEGER,
	`id` INTEGER NOT NULL COMMENT 'ID',
	`session_id` VARCHAR(50) NOT NULL COMMENT 'MUC会话ID',
	`name` VARCHAR(50) COMMENT '议题名称',
	`create_time` TIMESTAMP(0) COMMENT '创建时间',
	`end_by` VARCHAR(50) COMMENT '结束人ID',
	`start_message_id` INTEGER COMMENT '消息起始ID',
	`end_message_id` INTEGER COMMENT '消息结束ID',
	CONSTRAINT `PK_topics` PRIMARY KEY (`id`)
)
) COMMENT='议题,仅MUC模式使用。'
;
CREATE TABLE `p2p_messages`
(
	`id` INTEGER NOT NULL,
	`session_id` VARCHAR(50) NOT NULL,
	`sender_id` VARCHAR(50) NOT NULL,
	`content_type` INTEGER NOT NULL,
	`content` VARCHAR(1024),
	`timestamp` TIMESTAMP(0),
	`id` INTEGER NOT NULL COMMENT '消息ID',
	`session_id` VARCHAR(50) NOT NULL COMMENT '所属会话',
	`sender_id` VARCHAR(50) NOT NULL COMMENT '消息发送者',
	`content_type` INTEGER NOT NULL COMMENT '消息类型,1文本,2图片,3语音,4文章,5跳转,6咨询开始,7咨询结束',
	`content` VARCHAR(1024) COMMENT '消息内容',
	`timestamp` TIMESTAMP(0) COMMENT '发送时间',
	CONSTRAINT `PK_messages` PRIMARY KEY (`id`)
)
) COMMENT='P2P会话消息'
;
CREATE TABLE `group_messages`
(
	`id` INTEGER NOT NULL,
	`session_id` VARCHAR(50) NOT NULL,
	`sender_id` VARCHAR(50) NOT NULL,
	`content_type` INTEGER NOT NULL,
	`content` VARCHAR(1024),
	`timestamp` TIMESTAMP(0),
	`id` INTEGER NOT NULL COMMENT '消息ID',
	`session_id` VARCHAR(50) NOT NULL COMMENT '所属会话',
	`sender_id` VARCHAR(50) NOT NULL COMMENT '消息发送者',
	`content_type` INTEGER NOT NULL COMMENT '消息类型,1文本,2图片,3语音,4文章,5跳转,6咨询开始,7咨询结束',
	`content` VARCHAR(1024) COMMENT '消息内容',
	`timestamp` TIMESTAMP(0) COMMENT '发送时间',
	CONSTRAINT `PK_messages` PRIMARY KEY (`id`)
)
) COMMENT='群会话消息'
;
CREATE TABLE `sync_log`
(
	`event` VARCHAR(50) NOT NULL,
	`last_sync_time` DATE NOT NULL,
	`is_success` TINYINT,
	`message` VARCHAR(50)
)
	`event` VARCHAR(50) NOT NULL COMMENT '事件名称',
	`last_sync_time` TIMESTAMP NOT NULL COMMENT '最近更新时间',
	`succeed` TINYINT COMMENT '是否成功',
	`message` VARCHAR(50) COMMENT '消息'
) COMMENT='用户同步日志'
;
CREATE TABLE `muc_messages`
(
	`id` INTEGER NOT NULL,
	`session_id` VARCHAR(50) NOT NULL,
	`sender_id` VARCHAR(50) NOT NULL,
	`content_type` INTEGER NOT NULL,
	`content` VARCHAR(1024),
	`timestamp` TIMESTAMP(0),
	`id` INTEGER NOT NULL COMMENT '消息ID',
	`session_id` VARCHAR(50) NOT NULL COMMENT '所属会话',
	`sender_id` VARCHAR(50) NOT NULL COMMENT '消息发送者',
	`content_type` INTEGER NOT NULL COMMENT '消息类型,1文本,2图片,3语音,4文章,5跳转,6咨询开始,7咨询结束',
	`content` VARCHAR(1024) COMMENT '消息内容',
	`timestamp` TIMESTAMP(0) COMMENT '发送时间',
	CONSTRAINT `PK_messages` PRIMARY KEY (`id`)
)
) COMMENT='MUC会话消息'
;
CREATE TABLE `participants`
(
	`session_id` VARCHAR(50) NOT NULL,
	`participaint_id` VARCHAR(50) NOT NULL,
	`member_type` INTEGER NOT NULL,
	`receiving` TINYINT,
	`session_id` VARCHAR(50) NOT NULL COMMENT '会话ID',
	`participaint_id` VARCHAR(50) NOT NULL COMMENT '参与者ID',
	`member_type` INTEGER NOT NULL COMMENT '成员类型,1医生,2患者',
	`receiving` TINYINT COMMENT '当前是否正在接收',
	CONSTRAINT `PK_participants` PRIMARY KEY (`session_id`,`participaint_id`)
)
) COMMENT='会话参与者'
;
CREATE TABLE `sessions`
(
	`id` VARCHAR(50) NOT NULL,
	`name` VARCHAR(50) NOT NULL,
	`type` INTEGER NOT NULL,
	`create_date` DATE NOT NULL,
	`id` VARCHAR(50) NOT NULL COMMENT '会话标识。会话标识来源根据业务场景:1 医生间P2P会话使用随机生成的ID;2 医生间的群会话使用行政团队的ID;3 医生与患者间的咨询以患者的ID+当前咨询次数为ID',
	`name` VARCHAR(50) NOT NULL COMMENT '会话名称',
	`type` INTEGER NOT NULL COMMENT '会话类型,1表示MUC会话,2表示P2P,3表示群会话,4表示临时讨论组',
	`create_date` DATE NOT NULL COMMENT '创建时间',
	CONSTRAINT `PK_sessions` PRIMARY KEY (`id`)
)
) COMMENT='会话'
;
CREATE TABLE `doctors`
(
	`id` VARCHAR(50) NOT NULL,
	`name` VARCHAR(30) NOT NULL,
	`sex` INTEGER NOT NULL,
	`birthdate` DATE,
	`avatar` VARCHAR(255),
	`level` INTEGER NOT NULL,
	`last_sync_time` TIMESTAMP(0) NOT NULL,
	`locked` TINYINT NOT NULL,
	`id` VARCHAR(50) NOT NULL COMMENT 'ID',
	`name` VARCHAR(30) NOT NULL COMMENT '姓名',
	`sex` INTEGER NOT NULL COMMENT '性别',
	`birthdate` DATE COMMENT '出生日期',
	`avatar` VARCHAR(255) COMMENT '头像',
	`level` INTEGER COMMENT '级别',
	`locked` TINYINT NOT NULL DEFAULT 0 COMMENT '是否禁用',
	CONSTRAINT `PK_doctors` PRIMARY KEY (`id`)
)
) COMMENT='医生'
;
CREATE TABLE `patients`
(
	`id` VARCHAR(50) NOT NULL,
	`name` VARCHAR(30),
	`sex` INTEGER,
	`avatar` VARCHAR(255),
	`birthdate` DATE,
	`general_dr` VARCHAR(50),
	`health_dr` VARCHAR(50),
	`id` VARCHAR(50) NOT NULL COMMENT 'ID',
	`name` VARCHAR(30) COMMENT '姓名',
	`sex` INTEGER COMMENT '性别',
	`avatar` VARCHAR(255) COMMENT '头像',
	`birthdate` DATE COMMENT '出生日期',
	CONSTRAINT `PK_users` PRIMARY KEY (`id`)
)
) COMMENT='患者'
;
/* Create Primary Keys, Indexes, Uniques, Checks */
ALTER TABLE `topics` 
 ADD INDEX `IXFK_topics_sessions` (`session_id` ASC)
;
@ -160,12 +169,4 @@ ALTER TABLE `muc_messages`
 ADD INDEX `IXFK_messages_sessions` (`session_id` ASC)
;
ALTER TABLE `participants` 
 ADD INDEX `IXFK_participants_doctors` (`participaint_id` ASC)
;
ALTER TABLE `participants` 
 ADD INDEX `IXFK_participants_patients` (`participaint_id` ASC)
;
SET FOREIGN_KEY_CHECKS=1