自动加服

master
duhui 2021-08-26 15:51:17 +08:00
parent cb319c8759
commit b346ca72ab
4 changed files with 105 additions and 98 deletions

View File

@ -192,32 +192,13 @@ public class ServerInfoController {
@RequestMapping(value = "/addServer", method = {RequestMethod.POST, RequestMethod.GET})
public @ResponseBody int addServer(@RequestBody ServerInfo serverInfo1, HttpServletRequest request) throws Exception {
int server_id ;
if(serverInfo1.get_id()==0){
server_id = seqUtils.getSequence("serverid", 2000);
serverInfo1.set_id(server_id);
}else {
server_id = serverInfo1.get_id();
public @ResponseBody int addServer(@RequestBody ServerInfo serverInfo) throws Exception {
ServerInfo info = serverInfoDao.getServerinfo(serverInfo.getServer_id());
if (info != null){
return 0;
}
serverInfo1.setServer_id(String.valueOf(server_id));
if (null == serverInfo1.getOpen_time() || "".equals(serverInfo1.getOpen_time())) {
if(serverInfo1.getOpen_type().equals(Constants.SERVEROPEN_HAND)){
Date data = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
serverInfo1.setOpen_time(simpleDateFormat.format(data));
}else if(serverInfo1.getOpen_type().equals(Constants.SERVEROPEN_TIME)){
return 2;
}
}
if(serverInfo1.getOpen_type().equals(Constants.SERVEROPEN_TIME)){
RedisUtil.getInstence().putObject(server_id + RedisUserKey.Delimiter_colon + RedisUserKey.AUTOOPENTIME, "", serverInfo1.getOpen_time(), -1);
}
String startTime = JsonUtil.date3TimeStamp(serverInfo1.getOpen_time());
serverInfo1.setOpen_time(startTime);
serverInfoDao.addServerInfo(serverInfo1);
return 0;
serverInfoDao.addServerInfo(serverInfo);
return 1;
}
/**
@ -232,6 +213,7 @@ public class ServerInfoController {
autoServerSetting = new AutoServerSetting();
}
map.addAttribute("autoServerSetting", autoServerSetting);
LOGGER.info("自动开服配置:{}",autoServerSetting.toString());
return "autoStartServerSetting";
}

View File

@ -62,4 +62,14 @@ public class CServerOpenTime {
public void setRestartTime(String restartTime) {
this.restartTime = restartTime;
}
@Override
public String toString() {
return "CServerOpenTime{" +
"id=" + id +
", openTime='" + openTime + '\'' +
", version=" + version +
", restartTime='" + restartTime + '\'' +
'}';
}
}

View File

@ -63,7 +63,6 @@ public class AutoServerManager {
*/
public void startServer() throws Exception {
if (isOpen()){
LOGGER.info("=======================自动开服进行中=========================");
// 当前时间
long now = DateUtil.now();
// 获取全部服务器列表,排除非未运营和准备中的服务器,正序排列
@ -78,7 +77,6 @@ public class AutoServerManager {
ServerInfo newServer = first.get();
// 自动开服配置
AutoServerSetting setting = RedisUtil.getInstence().getMapValue(RedisUserKey.AUTO_START_SERVER_SETTING, "1", "1", AutoServerSetting.class, -1);
LOGGER.info("自动开服配置:{}",setting.toString());
// 注册人数
if (REGISTER.equals(setting.getChoose())) {
// 注册人数3分钟检查一次
@ -87,7 +85,7 @@ public class AutoServerManager {
String serverId = String.valueOf(Integer.valueOf(newServer.getServer_id())-1);
// 注册人数
long registerNum = serverInfoDao.getRegisterNum(serverId);
LOGGER.info("自动开服,注册人数判断,条件值:{},当前服务器人数:{}-{}",setting.getNum(),serverId,registerNum);
LOGGER.info("自动开服,注册人数判断,条件值:{},当前服务器人数:{}{}",setting.getNum(),serverId,registerNum);
if (registerNum >= Integer.parseInt(setting.getNum())){
startServers(newServer);
}
@ -118,7 +116,6 @@ public class AutoServerManager {
// 验证新服状态
CServerOpenTime cServerOpenTime = serverInfoDao.getOpenServerTime(newServer.getServer_id());
LOGGER.info("=================新服服务器信息============={}",cServerOpenTime.toString());
if (null == cServerOpenTime || cServerOpenTime.getOpenTime() == null || "".equals(cServerOpenTime.getOpenTime()) || cServerOpenTime.getVersion() <= 0){
LOGGER.error("新服自动开服失败================={}",newServer.toString());
// 通知钉钉

View File

@ -42,14 +42,12 @@
</div>
<div class="tabCon">
<span class="ERRINFO"></span>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
服务器id</label>
serverId</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="number" name="_id" style="width: 100px;" placeholder="0自动生成" class="input-text"/>
<input type="number" name="serverId" style="width: 200px;" class="input-text"/>
</div>
</div>
@ -58,7 +56,7 @@
<span class="c-red">*</span>
服务器name</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="name" placeholder="" class="input-text"/>
<input type="text" name="name" style="width: 200px;" class="input-text"/>
</div>
</div>
@ -67,7 +65,7 @@
<span class="c-red">*</span>
服务器ip</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="ip" placeholder="" class="input-text"/>
<input type="text" name="ip" style="width: 200px;" class="input-text"/>
</div>
</div>
@ -76,43 +74,44 @@
<span class="c-red">*</span>
服务器port</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="port" placeholder="" class="input-text"/>
<input type="number" name="port" style="width: 200px;" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
channel</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="channel" placeholder="" class="input-text"/>
<input type="text" name="channel" value="MHT" style="width: 200px;" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
sub_channel</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="sub_channel" placeholder="" class="input-text"/>
<input type="text" name="sub_channel" value="2000" style="width: 200px;" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
plat</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="plat" placeholder="android/ios" class="input-text"/>
<input type="text" name="plat" value="android" style="width: 200px;" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
服务器状态:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="hidden" id="status"/>
<select name="status" class="input-text" id="status1"><!--下拉列表-->
<option value="-1" selected="selected">服务准备中</option>
<select name="status" class="input-text" style="width: 200px;" id="status"><!--下拉列表-->
<option value="-2" selected="selected">未运营</option>
<option value="0">关闭</option>
<option value="1">维护</option>
<option value="2">流畅</option>
@ -121,15 +120,42 @@
</select>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
开启时间:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="open_time" style="width: 200px;" value="0" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
开启类型:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="number" name="open_type" style="width: 200px;" value="0" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
是否开启白名单:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="isWhite" style="width: 200px;" value="0" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
服务器推荐:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="hidden" id="isnew"/>
<select name="isnew" class="input-text" id="isnew1"><!--下拉列表-->
<option value="0">普通</option>
<option value="1" selected="selected">新服</option>
<select name="is_new" class="input-text" style="width: 200px;" id="is_new"><!--下拉列表-->
<option value="0" selected="selected">普通</option>
<option value="1">新服</option>
</select>
</div>
</div>
@ -137,23 +163,27 @@
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
开服时间</label>
core</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="startTime" placeholder="yyyy-MM-dd HH:mm:ss" class="input-text"/>
<input type="text" name="coreName" style="width: 200px;" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
服务器开启类型</label>
版本号</label>
<div class="formControls col-xs-8 col-sm-9">
<select name="open_type" class="input-text" id="open_type"><!--下拉列表-->
<option value="0" selected = "selected">手动启动</option>
<option value="1">按时启动</option>
<option value="2">按量启动</option>
</select>
<input type="number" name="server_version" style="width: 200px;" value="0" class="input-text"/>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*</span>
注册状态:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="number" name="register_state" style="width: 200px;" value="1" class="input-text"/>
</div>
</div>
@ -195,61 +225,52 @@
function addServer() {
var erroCode = $('.ERRINFO');
var _id = $("input[name='_id']").val();
var server_id = $("input[name='serverId']").val();
var _id = server_id;
var name = $("input[name='name']").val();
var ip = $("input[name='ip']").val();
var port = $("input[name='port']").val();
var channel = $("input[name='channel']").val();
var sub_channel = $("input[name='sub_channel']").val();
var status = document.getElementById("status").value;
var plat = $("input[name='plat']").val();
var status = document.getElementById("status1").value;
var isnew =document.getElementById("isnew1").value;
var startTime = $("input[name='startTime']").val();
var open_type =document.getElementById("open_type").value;
var open_time = $("input[name='open_time']").val();
var is_new = document.getElementById("is_new").value;
var open_type = $("input[name='open_type']").val();
var register_state = $("input[name='register_state']").val();
var coreName = $("input[name='coreName']").val();
var server_version = $("input[name='server_version']").val();
var isWhite = $("input[name='isWhite']").val();
var reg = new RegExp(/^-?[A-Za-z0-9]$/i);
if (!reg.test(server_id) || !reg.test(_id) || !reg.test(name) || !reg.test(ip) ||
!reg.test(port) || !reg.test(channel) || !reg.test(sub_channel) || !reg.test(status) ||
!reg.test(plat) || !reg.test(open_time) || !reg.test(is_new) || !reg.test(open_type) ||
!reg.test(register_state) || !reg.test(coreName) || !reg.test(server_version) || !reg.test(isWhite)){
alert("参数不能为空,或者特殊字符");
return false;
}
if (name === '' || name == null) {
erroCode.html('<span style="color: red; ">服务器name不能为空!</span>');
return false;
}
if (ip === '' || ip == null) {
erroCode.html('<span style="color: red; ">服务器ip不能为空!</span>');
return false;
}
if (port === '' || port == null) {
erroCode.html('<span style="color: red; ">服务器port不能为空!</span>');
return false;
}
if (channel === '' || channel == null) {
erroCode.html('<span style="color: red; ">服务器channel不能为空!</span>');
return false;
}
if (sub_channel === '' || sub_channel == null) {
erroCode.html('<span style="color: red; ">服务器sub_channel不能为空!</span>');
return false;
}
if (plat === '' || plat == null) {
erroCode.html('<span style="color: red; ">服务器plat不能为空!</span>');
return false;
}
$.ajax({
type: "POST",
data:
JSON.stringify({
"_id": _id,
"name": name,
"ip": ip,
"IP": ip,
"port": port,
"server_id":server_id,
"channel": channel,
"sub_channel": sub_channel,
"status":status,
"plat": plat,
"status": status,
"is_new": isnew,
"open_time": startTime,
"open_time":open_time,
"is_new": is_new,
"open_type": open_type,
"register_state":register_state,
"coreName":coreName,
"server_version":server_version,
"isWhite":isWhite
})
,
url: "/addServer",
@ -257,14 +278,11 @@
contentType: 'application/json',
success: function (data) {
if (data === 0) {
if (data === 1) {
layer.msg('添加成功!', {icon: 6, time: 1000});
}
if (data === 1) {
layer.msg('添加失败!', {icon: 6, time: 1000});
}
if (data === 2) {
layer.msg('添加失败 自动开服请设置开服时间!', {icon: 6, time: 2000});
if (data === 0) {
layer.msg('server_id重复!', {icon: 6, time: 1000});
}
}
}