Commit 683df2dd by chenjinjing

no message

parent 658c4066
...@@ -21,7 +21,7 @@ export function getKeyValueModule() { ...@@ -21,7 +21,7 @@ export function getKeyValueModule() {
} }
export function getCharModule() { export function getCharModule() {
let dataList = generateArr(5, 6, 10, 100, "数据名称", "key"); let dataList = generateArr(2, 6, 10, 100, "数据名称", "key");
let result = getChartOutData("柱状图数据", planarArrBecomeChartData(dataList)); let result = getChartOutData("柱状图数据", planarArrBecomeChartData(dataList));
return result; return result;
} }
......
import mongoose = require('mongoose');
let defaultOptions = {
auto_reconnect: true,
reconnectTries: 1000,
reconnectInterval: 3000,
keepAlive: 1,
connectTimeoutMS: 30000
};
export async function createDbConnect(connectUrl:string, options?:object) {
if (!connectUrl) throw new Error(`wrong connect url: ${connectUrl}`);
if (!options) options = defaultOptions;
console.log("connection mongo=>", connectUrl);
return await mongoose.createConnection(connectUrl);
}
\ No newline at end of file
import { mongoServerConstVal } from "../../serverConfig";
import { createDbConnect } from "./db_connect";
import { tableInit } from "./table_init";
let userDB;
let pictureDB;
let logDB;
export async function initDB() {
if (mongoServerConstVal.userUrl) {
userDB = await createDbConnect(mongoServerConstVal.userUrl).catch(err => {throw err});
process.stdin.emit('userdbinit success');
}
if (mongoServerConstVal.userUrl) {
pictureDB = await createDbConnect(mongoServerConstVal.pictureUrl).catch(err => {throw err});
process.stdin.emit('picturedbinit success');
}
if (mongoServerConstVal.userUrl) {
logDB = await createDbConnect(mongoServerConstVal.logUrl).catch(err => {throw err});
process.stdin.emit('logdbinit success');
}
tableInit();
}
export {userDB, pictureDB, logDB};
\ No newline at end of file
import * as userData from '../../model/users'
import * as pictureData from '../../model/picture'
export function tableInit() {
userData.initModel();
pictureData.initModel();
}
\ No newline at end of file
import { Schema } from "mongoose";
import { logDB } from "../../db/mongo/db_init";
const logSchema = new Schema({
createTime: {type:Number, index: true},
aId: {type: Number}
});
let logModel;
export function getModel() {
logModel = logDB.model('log', logSchema);
}
export async function getLogAll() {
return await logModel.find({}).exec();
}
\ No newline at end of file
import { Schema } from "mongoose";
import { pictureDB } from "../db/mongo/db_init";
const pictureSchema = new Schema({
pId: {type:Number, index: true},
pName: {type: String},
path: {type: String}
});
let pictureModel;
export function initModel() {
pictureModel = pictureDB.model('picture', pictureSchema)
}
export async function getPictureAll() {
return await pictureModel.find({}).exec();
}
export async function insertPic(picList) {
return await pictureModel.insertMany(picList);
}
import { Schema } from "mongoose";
import { userDB } from "../db/mongo/db_init";
const usersSchema = new Schema({
uId: {type:Number, index: true}, //id
uName: {type: String}, //管理员账号
uPwd: {type: String}, //管理员密码
lastOperationTime: {type: Date} //最近操作时间
});
let usersModel;
export function initModel() {
usersModel = userDB.model('users', usersSchema);
}
export async function getAdminAll() {
return await usersModel.find({}).exec();
}
\ No newline at end of file
//端口 //端口
export function getPort() : number { export function getPort() : number {
return Number(process.env.PORT) || Number(process.argv[3]) || 60000; return Number(process.env.PORT) || Number(process.argv[3]) || 60000;
...@@ -11,7 +10,10 @@ export function getEnv() : string { ...@@ -11,7 +10,10 @@ export function getEnv() : string {
//mongo数据库连接字符 //mongo数据库连接字符
export const mongoServerConstVal = { export const mongoServerConstVal = {
dbUrl:'' dbUrl:'',
userUrl: getUserUrl(),
pictureUrl: getPictureUrl(),
logUrl: getLogUrl()
} }
//mysql数据库连接对象 //mysql数据库连接对象
...@@ -21,3 +23,19 @@ export const mySqlConfig = { ...@@ -21,3 +23,19 @@ export const mySqlConfig = {
mysqlUser: '', mysqlUser: '',
mysqlPwd: '', mysqlPwd: '',
}; };
export function getPlatform() {
return process.argv[3] || "guanfang";
}
function getUserUrl() {
return (getEnv(), getPlatform());
}
function getPictureUrl() {
return (getEnv(), getPlatform());
}
function getLogUrl() {
return (getEnv(), getPlatform());
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment