Browse Source

分离REST API与页面两个文件夹;修复对象引用错误问题与require错误

Sand 8 years ago
parent
commit
7342aaee65

+ 12 - 8
src/doctor/app.js

@ -7,14 +7,17 @@ var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
// server config dependencies
var endpoints = require('./include/endpoints');
var config = require('./include/commons');
var endpoints = require('./include/endpoints').END_POINTS;
var pages = require('./include/pages').PAGES;
var configFile = require('./include/commons').CONFIG_FILE;
var config = require('./resources/config/' + configFile);
// routers dependencies
var routes = require('./controllers/index');
var users = require('./controllers/users');
var messages = require('./controllers/messages');
var management = require('./controllers/management');
// routes dependencies
var index = require('./controllers/index');
var users = require('./endpoints/users');
var messages = require('./endpoints/messages');
var management = require('./endpoints/management');
console.log('==============================================');
console.log('');
@ -36,7 +39,8 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(endpoints.Home.Base, routes);
app.use(pages.Home.Index, index);
app.use(endpoints.Msg.Base, messages);
app.use(endpoints.Users.Base, users);
app.use(endpoints.Management.Base, management);

+ 5 - 2
src/doctor/controllers/index.js

@ -1,9 +1,12 @@
/**
 * 主页面控制器。
 */
var express = require('express');
var router = express.Router();
var endpoints = require('../include/endpoints');
var pages = require('../include/pages').PAGES;
router.get(endpoints.Home.Base, function(req, res) {
router.get(pages.Home.Index, function(req, res) {
  res.render('index', { title: 'IM.Doctor' });
});

+ 6 - 2
src/doctor/controllers/management.js

@ -1,6 +1,10 @@
/**
 * 管理控制器。
 */
var express = require('express');
var router = express.Router();
var commons = require('../include/commons');
var endpoints = require('../include/endpoints').END_POINTS;
var wlyyRepo = require("../repository/wlyy.repo");
var imRepo = require("../repository/im.repo");
@ -23,7 +27,7 @@ function getImTables(handler) {
/**
 * 数据库检查,包括所有表,连接状态。
 */
router.get(commons.END_POINT.Management.DbStatus, function(req, res, next) {
router.get(endpoints.Management.DbStatus, function(req, res, next) {
    getWlyyTables(function(err, result) {
        if (err) {
            res.send({errno: -1, errmsg: 'open wlyy db error'});

+ 4 - 4
src/doctor/controllers/messages.js

@ -7,7 +7,7 @@ var http = require('http');
var qs = require('querystring');
var getui = require('getui');
var endpoints = require('../include/endpoints');
var endpoints = require('../include/endpoints').END_POINTS;
var express = require('express');
var router = express.Router();
@ -662,7 +662,7 @@ router.get(endpoints.Users.ChatList, function (req, res, next) {
 * 参数:
 * uid:信息所有者id
 */
router.get(endpoints.Msg.Users.GroupUnreadMsgCount, function (req, res, next) {
router.get(endpoints.Users.GroupUnreadMsgCount, function (req, res, next) {
    if (req.query.uid == null) {
        res.send({errno: -1, errmsg: 'parameter error'});
        return;
@ -699,7 +699,7 @@ router.get(endpoints.Msg.Users.GroupUnreadMsgCount, function (req, res, next) {
 * 参数:
 * uid:信息所有者id
 */
router.get(endpoints.Msg.Users.PrivateUnreadMsgCount, function (req, res, next) {
router.get(endpoints.Users.PrivateUnreadMsgCount, function (req, res, next) {
    if (req.query.uid == null) {
        res.send({errno: -1, errmsg: 'parameter error'});
        return;
@ -736,7 +736,7 @@ router.get(endpoints.Msg.Users.PrivateUnreadMsgCount, function (req, res, next)
 * 参数:
 * uid:信息所有者id
 */
router.get(endpoints.Msg.Users.UnreadMsgCount, function (req, res, next) {
router.get(endpoints.Users.UnreadMsgCount, function (req, res, next) {
    if (req.query.uid == null) {
        res.send({errno: -1, errmsg: 'parameter error'});
        return;

+ 3 - 0
src/doctor/controllers/users.js

@ -1,3 +1,6 @@
/**
 * 用户控制器。
 */
var express = require('express');
var router = express.Router();
var user = require("../models/user");

+ 6 - 6
src/doctor/include/commons.js

@ -1,11 +1,11 @@
var configFile = "config";
var configFile = "config.";
if (process.env.prod != false) {
    configFile += "prod.js";
} else if (process.env.test != false) {
    configFile += "test.js";
if (process.env.prod !== undefined) {
    configFile += "prod";
} else if (process.env.test !== undefined) {
    configFile += "test";
} else {
    configFile += "dev.js";
    configFile += "dev";
}
exports.CONFIG_FILE = configFile;

+ 6 - 4
src/doctor/include/endpoints.js

@ -1,7 +1,9 @@
/**
 * REST API,以端点的形式提供。
 *
 * 若想访问包含页面的内容,请在相应的API后面添加.html。
 */
var endpoints = {
    "Home": {
        "Base": '/'
    },
    Msg: {
        Base: "/message",
@ -29,4 +31,4 @@ var endpoints = {
    }
};
exports.END_POINTS = endpoints;
module.exports.END_POINTS = endpoints;

+ 10 - 0
src/doctor/include/pages.js

@ -0,0 +1,10 @@
/**
 * 所有的页面URL。提供部分对REST API返回值的可视化展示或便捷操作页面入口。
 */
var pages = {
    Home: {
        Index: '/'
    }
};
exports.PAGES = pages;

+ 8 - 8
src/doctor/models/msg.group.js

@ -1,18 +1,18 @@
"use strict";
var log = require('../util/log');
var mysql_wlyy = require("../repository/mysql_wlyy");
var mysql_im = require("../repository/imRepo");
var wlyyRepo = require("../repository/wlyy.repo");
var imRepo = require("../repository/im.repo");
function isGroupUser(user_id, group_id, group_type, handler) {
	if (group_type == 1) {
		mysql_wlyy.execQuery({
		wlyyRepo.execQuery({
			"sql": "SELECT doctor_code from wlyy_admin_team_member WHERE team_id=? and doctor_code=?",
			"args": [group_id, user_id],
			"handler": handler
		});
	} else {
		mysql_wlyy.execQuery({
		wlyyRepo.execQuery({
			"sql": "SELECT member_code from wlyy_talk_group_member WHERE group_code=? and member_code=?",
			"args": [group_id, user_id],
			"handler": handler
@ -22,13 +22,13 @@ function isGroupUser(user_id, group_id, group_type, handler) {
function getGroupUsers(group_id, group_type, handler) {
	if (group_type == 1) {
		mysql_wlyy.execQuery({
		wlyyRepo.execQuery({
			"sql": "SELECT doctor_code from wlyy_admin_team_member WHERE team_id=?",
			"args": [group_id],
			"handler": handler
		});
	} else {
		mysql_wlyy.execQuery({
		wlyyRepo.execQuery({
			"sql": "SELECT member_code from wlyy_talk_group_member WHERE group_code=?",
			"args": [group_id],
			"handler": handler
@ -37,7 +37,7 @@ function getGroupUsers(group_id, group_type, handler) {
}
function saveGroupMsg(user_id, group_id, at_uid, type, content, handler) {
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "INSERT INTO groups (to_gid,from_uid,at_uid,type,content) VALUES (?,?,?,?,?)",
		"args": [group_id, user_id, at_uid, type, content],
		"handler": handler
@ -49,7 +49,7 @@ function getGroupMsg(group_id, start, count, handler) {
	sql += start;
	sql += ",";
	sql += count;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": sql,
		"args": [group_id],
		"handler": handler

+ 5 - 5
src/doctor/models/msg.p2p.js

@ -1,11 +1,11 @@
"use strict";
var log = require('../util/log');
var mysql_wlyy = require("../repository/mysql_wlyy");
var mysql_im = require("../repository/imRepo");
var wlyyRepo = require("../repository/wlyy.repo");
var imRepo = require("../repository/im.repo");
function isUserExist(to_uid, handler) {
	mysql_wlyy.execQuery({
	wlyyRepo.execQuery({
		"sql": "SELECT count(*) from wlyy_doctor WHERE code=?",
		"args": [to_uid],
		"handler": handler
@ -13,7 +13,7 @@ function isUserExist(to_uid, handler) {
}
function saveP2PMsg(to_uid, from_uid, type, content, handler) {
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "INSERT INTO privates (to_uid,from_uid,type,content) VALUES (?,?,?,?)",
		"args": [to_uid, from_uid, type, content],
		"handler": handler
@ -25,7 +25,7 @@ function getP2PMsg(to_uid, from_uid, start, count, handler) {
	sql += start;
	sql += ",";
	sql += count;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": sql,
		"args": [to_uid, from_uid, from_uid, to_uid],
		"handler": handler

+ 16 - 17
src/doctor/models/msg.stat.js

@ -4,23 +4,22 @@ var http = require('http');
var qs = require('querystring');
var async = require('async');
var commons = require('./include/endpoints');
var config = require(commons.CONFIG_FILE);
var config = require('../include/commons').CONFIG_FILE;
var log = require('../util/log');
var mysql_wlyy = require("../repository/wlyyRepo");
var mysql_im = require("../repository/imRepo");
var wlyyRepo = require("../repository/wlyy.repo");
var imRepo = require("../repository/im.repo");
function updateGroupChatInfo(user_id, group_id, from_uid, at_me, type, content, msg_count_plus_one, handler) {
	var uuid = user_id + '_' + group_id;
    if (msg_count_plus_one) {
        mysql_im.execQuery({
        imRepo.execQuery({
            "sql": "INSERT INTO statistic (uid,uuid,from_uid,from_gid,at_me,msg_type,last_content_type,last_content,new_msg_count) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE from_uid=?,at_me=?,last_content_type=?,last_content=?,new_msg_count=new_msg_count+1",
            "args": [user_id, uuid, from_uid, group_id, at_me, 2, type, content, 1, from_uid, at_me, type, content],
            "handler": handler
        });
    } else {
        mysql_im.execQuery({
        imRepo.execQuery({
            "sql": "INSERT INTO statistic (uid,uuid,from_uid,from_gid,at_me,msg_type,last_content_type,last_content,new_msg_count) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE from_uid=?,at_me=?,last_content_type=?,last_content=?",
            "args": [user_id, uuid, from_uid, group_id, at_me, 2, type, content, 0, from_uid, at_me, type, content],
            "handler": handler
@ -32,14 +31,14 @@ function updateP2PChatInfo(user_id, peer_uid, from_uid, type, content, handler)
    var uuid = user_id + '_' + peer_uid;
    if (user_id == from_uid) {
        // 更新自身的统计信息
        mysql_im.execQuery({
        imRepo.execQuery({
            "sql": "INSERT INTO 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=?",
            "args": [user_id, uuid, from_uid, peer_uid, 1, type, content, 0, peer_uid, type, content],
            "handler": handler
        });
    } else {
        // 更新对端的统计信息
        mysql_im.execQuery({
        imRepo.execQuery({
            "sql": "INSERT INTO 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",
            "args": [user_id, uuid, from_uid, peer_uid, 1, type, content, 1, peer_uid, type, content],
            "handler": handler
@ -49,7 +48,7 @@ function updateP2PChatInfo(user_id, peer_uid, from_uid, type, content, handler)
function clearGroupChatInfo(user_id, group_id, handler) {
	var uuid = user_id + '_' + group_id;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "UPDATE statistic SET new_msg_count='0' WHERE uuid=?",
		"args": [uuid],
		"handler": handler
@ -58,7 +57,7 @@ function clearGroupChatInfo(user_id, group_id, handler) {
function clearP2PChatInfo(user_id, peer_uid, handler) {
	var uuid = user_id + '_' + peer_uid;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "UPDATE statistic SET new_msg_count='0' WHERE uuid=?",
		"args": [uuid],
		"handler": handler
@ -67,7 +66,7 @@ function clearP2PChatInfo(user_id, peer_uid, handler) {
function getGroupChatInfo(user_id, group_id, handler) {
	var uuid = user_id + '_' + group_id;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "SELECT uid,from_uid,from_gid,at_me,last_content_type,last_content,new_msg_count,timestamp from statistic WHERE uuid = ?",
		"args": [uuid],
		"handler": handler
@ -76,7 +75,7 @@ function getGroupChatInfo(user_id, group_id, handler) {
function getP2PChatInfo(user_id, peer_uid, handler) {
	var uuid = user_id + '_' + peer_uid;
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "SELECT uid,from_uid,last_content_type,last_content,new_msg_count,timestamp from statistic WHERE uuid = ?",
		"args": [uuid],
		"handler": handler
@ -84,7 +83,7 @@ function getP2PChatInfo(user_id, peer_uid, handler) {
}
function getChatList(user_id, handler) {
    mysql_im.execQuery({
    imRepo.execQuery({
        "sql": "SELECT uid,from_uid,from_gid,peer_uid,at_me,msg_type,last_content_type,last_content,new_msg_count,timestamp from statistic WHERE uid = ?",
        "args": [user_id],
        "handler": handler
@ -92,7 +91,7 @@ function getChatList(user_id, handler) {
}
function getGroupChatAllUnRead(user_id, handler) {
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "SELECT new_msg_count from statistic WHERE uid=? AND msg_type=2 AND new_msg_count>0",
		"args": [user_id],
		"handler": handler
@ -100,7 +99,7 @@ function getGroupChatAllUnRead(user_id, handler) {
}
function getP2PChatAllUnRead(user_id, handler) {
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "SELECT new_msg_count from statistic WHERE uid=? AND msg_type=1 AND new_msg_count>0",
		"args": [user_id],
		"handler": handler
@ -108,7 +107,7 @@ function getP2PChatAllUnRead(user_id, handler) {
}
function getChatAllUnRead(user_id, handler) {
	mysql_im.execQuery({
	imRepo.execQuery({
		"sql": "SELECT new_msg_count from statistic WHERE uid=? AND new_msg_count>0",
		"args": [user_id],
		"handler": handler
@ -116,7 +115,7 @@ function getChatAllUnRead(user_id, handler) {
}
function getAppMsgAmount(user_id, handler) {
    mysql_wlyy.execQuery({
    wlyyRepo.execQuery({
        "sql": "SELECT imei,token from wlyy_token WHERE users=?",
        "args": [user_id],
        "handler": function(err, result) {

+ 2 - 2
src/doctor/models/msg.system.js

@ -1,10 +1,10 @@
"use strict";
var log = require('../util/log');
var mysql_im = require("../repository/imRepo");
var imRepo = require("../repository/im.repo");
function saveSystemMsg(to_uid, type, title, content, data, handler) {
    mysql_im.execQuery({
    imRepo.execQuery({
        "sql": "INSERT INTO system (to_uid,type,title,content,data) VALUES (?,?,?,?,?)",
        "args": [to_uid, type, title, content, data],
        "handler": handler

+ 2 - 2
src/doctor/models/push_notify.js

@ -1,10 +1,10 @@
"use strict";
var log = require('../util/log');
var mysql_im = require("../repository/imRepo");
var imRepo = require("../repository/im.repo");
function savePushNotify(to_uid, type, title, content, data, has_pushed, handler) {
    mysql_im.execQuery({
    imRepo.execQuery({
        "sql": "INSERT INTO push_notify (to_uid,type,title,content,data,has_pushed) VALUES (?,?,?,?,?,?)",
        "args": [to_uid, type, title, content, data, has_pushed],
        "handler": handler

+ 1 - 0
src/doctor/package.json

@ -16,6 +16,7 @@
    "express": "~4.12.4",
    "jade": "~1.9.2",
    "morgan": "~1.5.3",
    "mysql": "~2.5.3",
    "serve-favicon": "~2.2.1",
    "socket.io": "~1.5.1"
  }

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

@ -1,8 +1,9 @@
"use strict";
var configFile = require('../include/commons').CONFIG_FILE;
var config = require('../resources/config/' + configFile);
var mysql = require('mysql');
var commons = require('./include/endpoints');
var config = require(commons.CONFIG_FILE);
var dbUtil = require('../util/dbUtil');
var pool = mysql.createPool(config.imDbConfig);

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

@ -1,8 +1,9 @@
"use strict";
var configFile = require('../include/commons').CONFIG_FILE;
var config = require('../resources/config/' + configFile);
var mysql = require('mysql');
var commons = require('./include/endpoints');
var config = require(commons.CONFIG_FILE);
var dbUtil = require('../util/dbUtil');
var pool = mysql.createPool(config.wlyyDbConfig);

+ 13 - 4
src/doctor/resources/config/config.dev.js

@ -16,7 +16,7 @@ var imDbConfig = {
    connectionLimit: '50'
};
// 个推接口参数
// 企业版的推送配置
var geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'qWmRh2X88l7HuE36z3qBe8',
@ -24,11 +24,20 @@ var geTuiConfig = {
    MASTERSECRET: 'veXiajQrId6iojy7Qv8kZ2'
};
exports.app = 'im.server';
exports.version = '1.0.5.20160922';
// AppStore版的推送App配置
var geTuiAppStoreCfg = {
    HOST : 'https://api.getui.com/apiex.htm',
    APPID : 'H6FYbDejks6VjMmW3uH7V6',
    APPKEY : '0PFWlKmLBN9YzhCfFWVgYA',
    MASTERSECRET : 'pvjCGtRZJx9SRVODkxc816'
};
exports.app = 'IM.Server';
exports.version = '1.0.5.20161107';
exports.debug = true;
exports.httpPort = 3000;
exports.sessionExpire = 1800;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiAppStoreCfg = geTuiAppStoreCfg;

+ 11 - 2
src/doctor/resources/config/config.pro.js

@ -16,7 +16,7 @@ var imDbConfig = {
    connectionLimit: '100'
};
// 个推接口参数
// 企业版的推送配置
var geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'qWmRh2X88l7HuE36z3qBe8',
@ -24,6 +24,14 @@ var geTuiConfig = {
    MASTERSECRET: 'veXiajQrId6iojy7Qv8kZ2'
};
//AppStore版的推送App配置
var geTuiAppStoreCfg = {
    HOST : 'https://api.getui.com/apiex.htm',
    APPID : 'H6FYbDejks6VjMmW3uH7V6',
    APPKEY : '0PFWlKmLBN9YzhCfFWVgYA',
    MASTERSECRET : 'pvjCGtRZJx9SRVODkxc816'
};
exports.app = 'im.server';
exports.version = '1.0.2.20160805';
exports.debug = true;
@ -31,4 +39,5 @@ exports.httpPort = 3000;
exports.sessionExpire = 1800;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiAppStoreCfg = geTuiAppStoreCfg;

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

@ -16,7 +16,7 @@ var imDbConfig = {
    connectionLimit: '100'
};
// 个推接口参数
// 企业版的推送配置
var geTuiConfig = {
    HOST: 'https://api.getui.com/apiex.htm',
    APPID: 'qWmRh2X88l7HuE36z3qBe8',
@ -24,6 +24,14 @@ var geTuiConfig = {
    MASTERSECRET: 'veXiajQrId6iojy7Qv8kZ2'
};
//AppStore版的推送App配置
var geTuiAppStoreCfg = {
    HOST : 'https://api.getui.com/apiex.htm',
    APPID : 'H6FYbDejks6VjMmW3uH7V6',
    APPKEY : '0PFWlKmLBN9YzhCfFWVgYA',
    MASTERSECRET : 'pvjCGtRZJx9SRVODkxc816'
};
exports.app = 'im.server';
exports.version = '1.0.2.20160805';
exports.debug = true;
@ -31,4 +39,5 @@ exports.httpPort = 3030;
exports.sessionExpire = 1800;
exports.wlyyDbConfig = wlyyDbConfig;
exports.imDbConfig = imDbConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiConfig = geTuiConfig;
exports.geTuiAppStoreCfg = geTuiAppStoreCfg;