var project_name, project_attr, projects = {},
	java_projects = [],
	node_projects = [],
	python_projects = [],
	ui_projects = [];
var param = {
	type: "",
	name: "",
	attr: ""
}
var users = [{}, {
	name: "dekun.dai",
	pwd: "quantgroup.com"
}, {
	name: "dekun.dai",
	pwd: "quantgroup.com"
}];

var pClass = function() {};
pClass.prototype = {
		init: function(isActive, projectType, port, url, projectName, ssh_git, gitPath, logName, configFile, command, nodeVersion, userIndex, desc, auth, command2, java_target_path) {
			this.name = projectName;
			this.type = projectType;
			this.url=url;
			if (!ssh_git) {
				this.git_path = "http://" + users[userIndex].name + ":" + users[userIndex].pwd + "@gitabc.xyqb.com/" + gitPath + "/" + projectName + ".git"
			} else {
				this.git_path = "git@gitabc.xyqb.com:" + gitPath + "/" + projectName + ".git"
			}

			this.log_name = logName;
			this.config_file = configFile;
			this.command = "";
			this.command2 = command2;
			this.node_version = nodeVersion;
			this.port = port;
			this.desc = desc;
			this.is_active = isActive;
			this.auth = auth;
			this.target_path = java_target_path;
			projects[projectName] = this;
			switch (projectType) {
				case "java":
					this.command = "java -Xmx512m -XX:PermSize64m -Xloggc:/tmp/" + projectName + ".log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps  -jar " + projectName + ".jar " + command;
					java_projects.push(this);
					if (this.target_path == "") {
						this.target_path = "./target"
					}
					break;
				case "node":
					this.command = command;
					node_projects.push(this);
					break;
				case "ui":
					this.command = command;
					ui_projects.push(this);
					break;
				case "python":
					this.command = command;
					python_projects.push(this);
					break;
			}
		}
	}
	// --java
new pClass().init(true, "java", "7003", "api.xyqb.com", "xyqb", false, "QG", "xyqb.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "现金贷-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7025", "btapi.xyqb.com", "baitiao", true, "baitiao", "baitiao.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "./baitiao-api/target");
new pClass().init(true, "java", "7019", "mallapi.xyqb.com", "xyqb-mall", false, "QG", "mall.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "商城后台-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7010", "offapi.xyqb.com", "xyqb-offline", false, "QG", "xyqb_offline.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "线下业务-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7042", "", "xyqb-user2", true, "head_group", "xyqb_user.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "用户注册登录-V2-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7005", "rapi.xyqb.com", "di-ting", false, "QG", "di_ting.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "风控审计-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7013", "auth.xyqb.com", "han-gu-guan", false, "QG", "han-gu-guan.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "用户注册登录-V1-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7015", "", "jian-men-guan", false, "QG", "jian_men_guan.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "信审服务-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7028", "", "black-hole", false, "QG", "black-hole.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "合同中心-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7006", "payapi.xyqb.com", "gu-bei", true, "funding", "pay-center.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "支付中心-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7023", "", "xyqb-quartz", false, "QG", "quartz.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "定时任务-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7021", "scapi.xyqb.com", "spider-center", false, "QG", "spider-center.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "授信-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7037", "qapi.xyqb.com", "cash-loan-flow", false, "QG", "cash_loan_flow.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "现金贷流量对接-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7012", "fsapi.xyqb.com", "financial-system", false, "QG", "financial_system.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "财务系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7034", "", "fund-manage", false, "QG", "fund_manage.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "债转系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7029", "gyxdapi.xyqb.com", "gyxd", false, "QG", "gyxd.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "广源小贷-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7038", "", "merchant-backend", false, "QG", "merchant.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "商户后台-server", "凌子华／陈东亮", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7031", "", "redpacket", true, "baitiao", "redpacket.log", "application.properties", "--worker 1 --currentWorker 1 -t > /dev/null 2>&1 &", null, 2, "红包系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7044", "", "finance-api", false, "bo.wang", "finance-api.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "财务系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7045", "", "check-accounts", false, "QG", "check_accounts.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "对账系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7014", "", "du-jiang-yan", false, "QG", "du_jiang_yan.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "第三方对接导流-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "8051", "", "msg", false, "micro-service", "msg.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "新版消息中心", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7052", "", "xyqb-btzt", true, "qg-op-backend", "xyqb-btzt.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条直投外部", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7053", "", "xyqb-btzt-internal", true, "qg-op-backend", "xyqb-btzt-internal.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条直投内部", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7060", "", "xyqb-backend", true, "qg-op-backend", "xyqb-backend.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "运营系统服务", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7062", "", "xyqb-user2-query", true, "head_group", "xyqb_user_query.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "用户系统查询服务", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7063", "", "traffic-webapp", true, "qg-op-backend", "traffic.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "流量分发系统", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7017", "", "silk-road-eureka", true, "baitiao", "silk-road-eureka.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "Eureka 服务注册发现微服务", "魏巍", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7027", "", "silk-road-caller", true, "baitiao", "silk-road-caller.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "MQ消息调用中心微服务", "魏巍", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7056", "", "score", true, "baitiao", "score.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "积分系统", "刑志超", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7065", "", "silk-road-backman", true, "baitiao", "silk-road-backman.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条直投-对内系统2", "张曙", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7066", "", "silk-road", true, "baitiao", "silk-road.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条直投-对外系统2", "魏巍", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(false, "java", "7059", "", "baitiao-zhitou", true, "baitiao", "baitiao-zhitou.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "白条直投-对接资金方", "张斌", "mvn clean package -Ptest -Dmaven.test.skip=true", "./xyqb-btzt-internal/target/");
new pClass().init(false, "java", "7068", "", "customer_helpdesk", true, "data-riskcontrol", "customer_helpdesk.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "外部客服-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");
new pClass().init(true, "java", "7069", "", "notify", true, "fund_pay", "notify.log", "application.properties", "--worker 1 --currentWorker 1 -t -ts > /dev/null 2>&1 &", null, 2, "支付中心消息通知系统-server", "", "mvn clean package -Ptest -Dmaven.test.skip=true", "");


// ui----
new pClass().init(true, "ui", "7032", "", "op-ui", false, "QG", null, "src/js/env.config.js", "npm run build", "node7", 1, "运营系统-ui", "", "", "");
new pClass().init(true, "ui", "7040", "", "activity-ui", false, "QG", null, "src/app/config.js", "npm run build", "node7", 1, "活动中心-ui", "", "", "");
new pClass().init(true, "ui", "7011", "financial.xyqb.com", "financial-system-ui", false, "QG", null, "src/js/env.config.js", "npm run build", "node7", 1, "财务系统-ui", "", "", "");
new pClass().init(true, "ui", "7030", "", "gyxd-ui", false, "QG", null, "src/js/env.config.js", "npm run build", "node7", 1, "广源小贷-ui", "", "");
new pClass().init(true, "ui", "7008", "off.xyqb.com", "offline-ui", false, "QG", null, "src/app/config/env.config.js", "npm run build", "node7", 1, "线下白条-ui", "", "", "");
new pClass().init(true, "ui", "7035", "", "funding-corp-op-ui", false, "QG", null, "src/js/env.config.js", "npm run build", "node7", 1, "白条债转系统-ui", "", "", "");
new pClass().init(true, "ui", "7007", "pay.xyqb.com", "paycenter-ui", false, "QG", null, "src/app/config/env.config.js", "npm run build", "node7", 1, "支付中心-ui", "", "", "");
new pClass().init(true, "ui", "7043", "", "xyqb-user-ui", false, "head_group", null, "src/app/config.js", "npm run qa", "node7", 1, "用户注册登录-V2-ui", "", "", "");
new pClass().init(true, "ui", "7039", "", "merchant-op-ui", false, "QG", null, "src/js/env.config.js", "npm run build", "node7", 1, "商户系统-ui", "", "", "");
new pClass().init(true, "ui", "7004", "r.xyqb.com", "di-ting-ui", false, "QG", null, "client/app/config.js", "grunt build", "node7", 1, "信审-ui", "", "", "");
new pClass().init(true, "ui", "7020", "", "spider-center-ui", false, "QG", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "授信中心-ui", "", "", "");
new pClass().init(true, "ui", "7050", "bt.xyqb.com", "bt-ui", false, "QG", null, "src/app/config/env.config.js", "npm --registry http://172.16.3.15:4873 run qa", "node7", 1, "新版白条-ui", "", "", "");
new pClass().init(true, "ui", "7058", "", "mall-ui", true, "ui", null, "src/app/config/env.config.js", "npm run build", "node7", 1, "商城-ui", "", "", "");
new pClass().init(true, "ui", "7001", "m.xyqb.com", "xyqb-ui", false, "QG", null, "client/app/config.js", "grunt build", "node7", 1, "现金贷和白条-现金贷-ui", "", "", "");
new pClass().init(true, "ui", "7046", "", "activity-op-ui", false, "QG", null, "src/config/env.config.js", "npm run build", "node7", 1, "优惠券管理后台-ui", "", "", "");
new pClass().init(true, "ui", "7048", "", "order-op-ui", false, "OP", null, "src/js/env.config.js", "gulp build", "node7", 1, "订单系统-ui", "", "", "");
new pClass().init(true, "ui", "7002", "", "qgbc-ui", false, "QG", null, "src/app/config/env.config.js", "npm run build_production", "node7", 1, "白条-ui", "", "", "");
new pClass().init(true, "ui", "7057", "", "xjd-ui", false, "QG", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "新版现金贷-ui", "", "", "");
new pClass().init(true, "ui", "7007", "", "new-paycenter-ui", false, "QG", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "新版支付中心-ui", "", "", "");
new pClass().init(false, "ui", "7061", "", "wind-control-op-ui", true, "ui", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "临时项目，未来删除风控平台-ui", "", "", "");
new pClass().init(false, "ui", "7016", "", "flow-op-ui", true, "ui", null, "src/config/env.config.js", "npm run build", "node7", 1, "导流UI页面", "", "", "");
new pClass().init(false, "ui", "7051", "", "h5-ui", true, "ui", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "h5平台业务", "李长城", "", "");
new pClass().init(true, "ui", "7057", "", "ka-spider-center-ui", true, "ui", null, "src/app/config/env.config.js", "npm run qa", "node7", 1, "新版授信UI", "郑少文", "", "");
new pClass().init(true, "ui", "7067", "", "new-op-ui", true, "ui", null, "src/config/env.config.js", "npm run build", "node7", 1, "运营系统 vue", "孙小英", "", "");
new pClass().init(true, "ui", "7070", "", "customer-op-ui", true, "ui", null, "src/config/env.config.js", "npm run build", "node7", 1, "外部查询-ui", "", "", "");


// node
new pClass().init(true, "node", "7018", "", "AppBackend", false, "QG", null, "config/environment/test.js", "forever start -a -s --uid AppBackend bin/www", null, 1, "APP后台服务-server", "", "forever stop AppBackend", "");
new pClass().init(true, "node", "7041", "", "activity-op", false, "QG", null, "src/config.js", "sh start.sh", null, 1, "优惠券中心-server", "", "sh stop.sh", "");
new pClass().init(true, "node", "7047", "", "op-api", false, "OP", null, "src/dev.config.js", "sh start.sh", null, 1, "系统Api-Gateway-server", "", "sh stop.sh", "");
new pClass().init(true, "node", "7049", "", "fe-api", false, "QG", null, "src/config.js", "sh start.sh", null, 1, "科传项目-消息推送", "", "pm2 stop fe-api", "");
new pClass().init(true, "node", "7054", "", "xyqb-h5-backend", false, "QG", null, "src/dev.config.js", "sh start.sh", null, 1, "信用钱包帮助中心", "", "sh stop.sh", "");
new pClass().init(true, "node", "7055", "", "statistics", true, "OP", null, "src/config.js", "sh start.sh", null, 1, "收集前端日志", "", "sh stop.sh", "");
//python
new pClass().init(true, "python", "7022", "", "qin-qiong", false, "QG", null, "config/beta/config.properties", null, null, 1, "加密解密-server", "", "", "");
new pClass().init(true, "python", "7033", "", "xyqb-query", false, "QG", null, "server/config/beta/config.ini", null, null, 1, "query-server", "", "", "");
new pClass().init(false, "python", "7027", "", "msg-center", false, "QG", null, "server/config/beta/config.ini", null, null, 1, "短信中心-以前的sms-center", "", "", "");

var temp = "";

process.argv.forEach(function(val, index, array) {
	if (index >= 2) {
		if (index % 2 == 0) {
			temp = val.replace(/\-/, "");
			param[temp] = "";
		} else {
			param[temp] = val;
		}
	}
});

function getListAttr(projects, attr) {
	var list = [];
	for (var i = 0; i < projects.length; i++) {
		if (projects[i].is_active) {
			list.push(projects[i][attr])
		}
	}
	return list.join(" ");
}
var configFunction = function() {};
configFunction.prototype = {
	getProjectAttr: function(pName, pAttr) {
		if (typeof projects[pName] == "undefined") {
			console.log("")
		} else {
				var attrs = pAttr.split("/");
				if (attrs.length == 0) {
					console.log("")
					return
				}
				var list = [];
				for (var j = 0; j < attrs.length; j++) {
					if(projects[pName][attrs[j]]){
						
						list.push(projects[pName][attrs[j]].split(" ").join("^"));
					}else{
						list.push(" ");
					}
				}
				console.log(list.join("|"))
		}
	},
	getProjectsAttrs: function(projects, attr) {
		var attrs = attr.split("/");
		if (attrs.length == 0) {
			return
		}
		var list = [];
		for (var i = 0; i < projects.length; i++) {
			var li = [projects[i]["name"]];
			for (var j = 0; j < attrs.length; j++) {
				li.push(projects[i][attrs[j]]);
			}
			list.push(li.join("|"));
		}
		return list.join(" ");
	},
	getProjectsAttr: function(type, attr) {
		switch (type) {
			case "java":
				console.log(getListAttr(java_projects, attr));
				break;
			case "ui":
				console.log(getListAttr(ui_projects, attr));
				break;
			case "python":
				console.log(getListAttr(python_projects, attr));
				break;
			case "node":
				console.log(getListAttr(node_projects, attr));
				break;
		}
	}
}
var F = new configFunction();

if (param["type"] == "") {
	F.getProjectAttr(param["name"], param["attr"]);
} else if (param["type"] == "multi") {
	var str = "";
	str += F.getProjectsAttrs(java_projects, param["attr"]);
	str += " " + F.getProjectsAttrs(ui_projects, param["attr"]);
	str += " " + F.getProjectsAttrs(python_projects, param["attr"]);
	str += " " + F.getProjectsAttrs(node_projects, param["attr"]);
	console.log(str)
} else {
	F.getProjectsAttr(param["type"], param["attr"]);
}
