Commit 4185b735 authored by clauseliu's avatar clauseliu
Browse files

clauseliu

parent b44833f6
Showing with 406 additions and 17 deletions
+406 -17
......@@ -24,6 +24,7 @@ app.use(views(__dirname + '/views', {
extension: 'ejs'
}));
app.use(bodyparser());
//前置中间件
......
......@@ -8,30 +8,161 @@ const ConfigController = {};
ConfigController.index = async(ctx) => {
await ctx.render('index', {
title: 'tars title#common.servername#',
a: ctx.paramsObj.a || '',
title: 'tars title#common.servername#'
});
};
ConfigController.configFileList = async(ctx) => {
let {level, application, set_name, set_area, set_group, server_name} = ctx.paramsObj;
let list = [];
switch(level) {
case '1' :
list = await ConfigService.getApplicationConfigFile(application);
break;
case '2' :
if(!set_name) {
return ctx.makeResObj(500, 'set_name #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name});
break;
case '3' :
if(!set_name || !set_area){
return ctx.makeResObj(500, 'set_name,set_area #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name, set_area:set_area});
break;
case '4' :
if(!set_name || !set_area || !set_group){
return ctx.makeResObj(500, 'set_name,set_area,set_group #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name, set_area:set_area, set_group:set_group});
break;
case '5' :
if(!server_name){
return ctx.makeResObj(500, 'server_name #common.notempty#');
}
list = await ConfigService.getServerConfigFile({server_name:`${application}.${server_name}`, set_name:set_name, set_area:set_area, set_group:set_group});
break;
}
try{
ctx.makeResObj(200, '', await ConfigService.getServerConfigFile());
ctx.makeResObj(200, '', list);
}catch(e){
ctx.makeResObj(500, e.toString());
ctx.makeResObj(500, e);
}
};
ConfigController.addConfigFile = async(ctx) => {
console.info(ctx.paramsObj);
let params = ctx.paramsObj;
try{
ctx.makeResObj(200, '', await ConfigService.addConfigFile(params));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.deleteConfigFile = async(ctx) => {
let id = ctx.paramsObj.id;
try{
ctx.makeResObj(200, '', await ConfigService.deleteConfigFile(id));
}catch(e) {
ctx.makeResObj(500, e.toString());
}
};
ConfigController.updateConfigFile = async(ctx) => {
let params = ctx.paramsObj;
try{
ctx.makeResObj(200, '', await ConfigService.updateConfigFile(params));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.configFile = async(ctx) => {
let id = ctx.paramsObj.id;
try{
ctx.makeResObj(200, '', await ConfigService.loadConfigFile(id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.nodeConfigFileList = async(ctx) => {
let params = ctx.paramsObj;
try{
ctx.makeResObj(200, '', await ConfigService.getNodeConfigFile(params));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.loadConfigFileHistory = async(ctx) => {
let id = ctx.paramsObj.id;
try{
ctx.makeResObj(200, '', await ConfigService.loadConfigFileHistory(id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.configFileHistoryList = async(ctx) => {
let config_id = ctx.paramsObj.config_id;
try{
ctx.makeResObj(200, '', await ConfigService.getConfigFileHistory(config_id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.addConfigRef = async(ctx) => {
let {config_id, reference_id} = ctx.paramsObj;
try{
ctx.makeResObj(200, '', await ConfigService.addConfigRef(config_id, reference_id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.deleteConfigRef = async(ctx) => {
let id = ctx.paramsObj.id;
try{
ctx.makeResObj(200, '', await ConfigService.addConfigFile(ctx.paramsObj));
ctx.makeResObj(200, '', await ConfigService.deleteConfigRef(id));
}catch(e){
console.info(e);
ctx.makeResObj(500, e.toString());
}
};
ConfigController.configRefList = async(ctx) => {
let config_id = ctx.paramsObj.config_id;
try{
ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(config_id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.mergedNodeConfig = async(ctx) => {
let id = ctx.paramsObj.id;
try{
//ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
ConfigController.pushConfigFile = async(ctx) => {
let ids = ctx.paramsObj.ids;
try{
//ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(id));
}catch(e){
ctx.makeResObj(500, e.toString());
}
};
module.exports = ConfigController;
\ No newline at end of file
var SequelizeAuto = require('sequelize-auto')
var auto = new SequelizeAuto('db_tars_web', 'root', '',{
var auto = new SequelizeAuto('db_tars_web', 'root', 'admin',{
host: 'localhost',
dialect: 'mysql',
directory: './models', // prevents the program from writing to disk
......
/* jshint indent: 1 */
module.exports = function(sequelize, DataTypes) {
return sequelize.define('t_config_files', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
server_name: {
type: DataTypes.STRING(128),
allowNull: true,
defaultValue: ''
},
set_name: {
type: DataTypes.STRING(16),
allowNull: false,
defaultValue: ''
},
set_area: {
type: DataTypes.STRING(16),
allowNull: false,
defaultValue: ''
},
set_group: {
type: DataTypes.STRING(16),
allowNull: false,
defaultValue: ''
},
host: {
type: DataTypes.STRING(20),
allowNull: false,
defaultValue: ''
},
filename: {
type: DataTypes.STRING(128),
allowNull: true
},
config: {
type: DataTypes.TEXT,
allowNull: true
},
posttime: {
type: DataTypes.DATE,
allowNull: true
},
lastuser: {
type: DataTypes.STRING(50),
allowNull: true
},
level: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '2'
},
config_flag: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
}
}, {
tableName: 't_config_files',
timestamps: false
});
};
/**
* Created by clauseliu on 2018/4/20.
*/
const {tConfigFiles} = require('./db');
const logger = require('../logger');
let ConfigMapper = {};
ConfigMapper.getApplicationConfigFile = async (application) => {
try{
return await tConfigFiles.findAll({
where : {
level : 1,
server_name : application
}
});
}catch(e) {
logger.error(e);
return e;
}
};
ConfigMapper.getSetConfigFile = async (params) => {
try{
let whereObj = Object.assign({level:1},params);
return await tConfigFiles.findAll({
where : whereObj
});
}catch(e) {
logger.error(e);
return e;
}
};
ConfigMapper.getServerConfigFile = async (params) => {
for(var item in params) {
if(!params[item]){
delete params[item];
}
}
try{
let whereObj = Object.assign({level:2},params);
return await tConfigFiles.findAll({
where : whereObj
});
}catch(e) {
logger.error(e);
return e;
}
};
module.exports = ConfigMapper;
\ No newline at end of file
......@@ -21,7 +21,7 @@ const paramsCheckMidware = async (ctx, next, checkRule) => {
var hasError = false;
_.each(checkRule, (rules, paramName) => {
if(rules){
var value = params[paramName] || '';
var value = params[paramName] != undefined ? params[paramName].toString() : '';
_.each(rules.split(';'), (rule) =>{
if(rule === 'notEmpty' && validator.isEmpty(value)){
hasError = true;
......
......@@ -30,6 +30,7 @@ const getRouter = (router, routerConf) =>{
});
};
//页面类型路由
const pageRouter = new Router();
getRouter(pageRouter, pageConf);
......
......@@ -16,8 +16,19 @@ const apiConf = [
['get', '/getRpcData', DemoController.getRpcData, {id: 'notEmpty;number'}],
// 服务配置接口
['get', '/config_file_list', ConfigController.configFileList, {id: 'notEmpty;number'}],
['post', '/add_config_file', ConfigController.addConfigFile],
['get', '/config_file_list', ConfigController.configFileList, {level:'number', application:'notEmpty'}],
['post', '/add_config_file', ConfigController.addConfigFile, {level:'number', application:'notEmpty', server_name:'notEmpty', filename:'notEmpty',config:'notEmpty'}],
['get', '/delete_config_file', ConfigController.deleteConfigFile, {id: 'number'}],
['post', '/update_config_file', ConfigController.updateConfigFile,{id:'number',config:'notEmpty'}],
['get', '/config_file', ConfigController.configFile, {id: 'number'}],
['post', '/node_config_file_list', ConfigController.nodeConfigFileList, {application:'notEmpty', server_name:'notEmpty'}],
['get', '/config_file_history', ConfigController.loadConfigFileHistory, {id: 'number'}],
['get', '/config_file_history_list', ConfigController.configFileHistoryList, {config_id: 'number'}],
['get', '/add_config_ref', ConfigController.addConfigRef, {config_id: 'number',reference_id:'number'}],
['get', '/delete_config_ref', ConfigController.deleteConfigRef, {id: 'number'}],
['get', '/config_ref_list', ConfigController.configRefList, {config_id: 'number'}]
//['get', '/merged_node_config', ConfigController.configRefList, {id: 'notEmpty;number'}],
//['get', '/push_config_file', ConfigController.configRefList, {ids: 'notEmpty;string'}],
]
module.exports = {pageConf, apiConf};
\ No newline at end of file
......@@ -2,12 +2,15 @@
* Created by clauseliu on 2018/4/18.
*/
const logger = require(`../../logger`);
const ConfigMapper = require('../../dao/tConfigFiles');
const ConfigService = {};
ConfigService.getServerConfigFile = async() => {
let list = [{
ConfigService.addConfigFile = async(params) => {
return {
id : 0,
server_name : '',
node_name : '',
......@@ -18,12 +21,34 @@ ConfigService.getServerConfigFile = async() => {
config : '',
level : 1,
posttime : ''
}];
return list
}
};
ConfigService.addConfigFile = async(params) => {
ConfigService.deleteConfigFile = async(id) => {
try{
return Promise.resolve([id]);
}catch(e){
return Promise.reject(e);
}
};
ConfigService.updateConfigFile = async(params) => {
return {
id : 0,
server_name : '',
node_name : '',
set_name : '',
set_area : '',
set_group : '',
filename : '',
config : '',
level : 1,
posttime : ''
}
};
ConfigService.loadConfigFile = async(id) => {
return {
id : 0,
server_name : '',
......@@ -38,4 +63,103 @@ ConfigService.addConfigFile = async(params) => {
}
};
ConfigService.getServerConfigFile = function(params) {
return ConfigMapper.getServerConfigFile(params).catch(function (e) {
return e;
});
};
ConfigService.getApplicationConfigFile = async(application) => {
return await ConfigMapper.getApplicationConfigFile(application).catch(function (e) {
return e;
});
};
ConfigService.getSetConfigFile = function(params) {
return ConfigMapper.getSetConfigFile(params).catch(function (e) {
return e;
});
};
ConfigService.getNodeConfigFile = async(params) => {
let list = [{
id : 0,
server_name : '',
node_name : '',
set_name : '',
set_area : '',
set_group : '',
filename : '',
config : '',
level : 1,
posttime : ''
}];
return list
};
ConfigService.loadConfigFileHistory = async(id) => {
return {
"id": "", // 变更记录ID
"config_id": "", // 配置文件ID
"reason": "", // 备注
"content": "", // 变更内容
"posttime": "", // 更新时间
}
};
ConfigService.getConfigFileHistory = async(config_id) => {
return [{
"id": "", // 变更记录ID
"config_id": "", // 配置文件ID
"reason": "", // 备注
"content": "", // 变更内容
"posttime": "", // 更新时间
}]
};
/**
* 添加引用文件
* @param config_id
* @param reference_id
* @return {{id: string, config_id: string, reference_id: string}}
*/
ConfigService.addConfigRef = async(config_id, reference_id) => {
return {
"id": "", // 引用ID
"config_id": "", // 配置文件ID
"reference_id": "" // 引用配置文件ID
}
};
ConfigService.deleteConfigRef = async(id) => {
return [0];
};
/**
* 引用列表
* @param config_id
* @return {*[]}
*/
ConfigService.getConfigRefByConfigId = async(config_id) => {
return [{
"id": 0, // 引用ID
"config_id": 0, // 配置文件ID
"reference": {
"id": 0, // 配置文件ID
"server_name": "", // 服务
"node_name": "", // 节点
"set_name": "", // Set名
"set_area": "", // Set取
"set_group": "", // Set组
"filename": "", // 文件名
"config": "", // 文件内容
"level": 1, // 层级,1:应用或Set,2:服务,3:节点
"posttime": "", // 更新时间
}
}]
};
module.exports = ConfigService;
\ No newline at end of file
......@@ -19,7 +19,7 @@ this is Index Page
ajax.open('POST','/api/add_config_file',true);
ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
ajax.send('id=3333');
ajax.send('level=5&application=""');
</script>
</body>
</html>
\ No newline at end of file
Supports Markdown
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