批量添加服务器

master
duhui 2021-11-18 16:43:29 +08:00
parent fde633bd58
commit 72c8eb64cd
3 changed files with 82 additions and 31 deletions

View File

@ -332,11 +332,39 @@ public class ServerInfoController {
@RequestMapping(value = "/addServer", method = {RequestMethod.POST, RequestMethod.GET})
public @ResponseBody int addServer(@RequestBody ServerInfo serverInfo) throws Exception {
ServerInfo info = serverInfoDao.getServerinfo(serverInfo.getServer_id());
if (info != null){
return 0;
Map<String, ServerInfo> serverMap = serverInfoDao.getAllServerMap();
int count = serverInfo.getCount();
if (count > 0){
// 需要修改的参数
int serverId = Integer.parseInt(serverInfo.getServer_id());
// name模板太初%d服
String named = serverInfo.getName().split("#")[0];
// name数值23
int nameNum = Integer.parseInt(serverInfo.getName().split("#")[1]);
int port = Integer.parseInt(serverInfo.getPort());
int coreNum = Integer.parseInt(serverInfo.getCoreName());
for (int i = 0; i < count; i++) {
int i1 = serverId + i;
if (serverMap.get(String.valueOf(i1)) != null){
LOGGER.error("批量添加服务器出现重复id:{}",i1);
continue;
}
// 重新赋值
serverInfo.set_id(i1);
serverInfo.setServer_id(String.valueOf(i1));
String name = named.replace("%d", String.valueOf(nameNum + i));
serverInfo.setName(name);
serverInfo.setPort(String.valueOf(port+i));
serverInfo.setCoreName("core"+(coreNum+i));
serverInfoDao.addServerInfo(serverInfo);
}
}else {
ServerInfo info = serverMap.get(serverInfo.getServer_id());
if (info != null){
return 0;
}
serverInfoDao.addServerInfo(serverInfo);
}
serverInfoDao.addServerInfo(serverInfo);
return 1;
}

View File

@ -1,6 +1,7 @@
package com.jmfy.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@ -76,6 +77,12 @@ public class ServerInfo implements Comparable,Cloneable {
@Field(value = "open_time")
private String open_time;
/**
* 使
*/
@Transient
private int count;
public ServerInfo(int _id, String name) {
this._id = _id;
this.server_id = String.valueOf(_id);
@ -209,6 +216,14 @@ public class ServerInfo implements Comparable,Cloneable {
this.open_time = open_time;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
@Override
public String toString() {
return "ServerInfo{" +

View File

@ -37,54 +37,60 @@
<div class="page-container">
<form class="form form-horizontal" id="form-article-add" action="http://60.1.1.212:9076/idip/manager" method="post">
<div id="tab-system" class="HuiTab">
<div class="tabBar cl">
<div class="tabBar cl" title="支持单个添加和批量添加,不会使用批量添加前请勿操作,防止产生坏数据">
<span>创建服务器</span>
</div>
<div class="tabCon">
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*(手动修改)</span>
serverId</label>
<label class="form-label col-xs-4 col-sm-2" title="批量添加填写第一个的服务器id" style="cursor:pointer">
<span class="c-red">* serverId</span>
</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="number" name="serverId" 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>
服务器name</label>
<label class="form-label col-xs-4 col-sm-2" title="批量添加,格式例子:太初%d服#23" style="cursor:pointer">
<span class="c-red">* 服务器name</span>
</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="name" 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>
服务器ip</label>
<label class="form-label col-xs-4 col-sm-2" title="需要手动添加" style="cursor:pointer">
<span class="c-red">* 服务器ip</span>
</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="ip" 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>
服务器port</label>
<label class="form-label col-xs-4 col-sm-2" title="批量添加填写第一个的服务器端口" style="cursor:pointer">
<span class="c-red">* 服务器port</span></label>
<div class="formControls col-xs-8 col-sm-9">
<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">
channel<br>
<span class="c-red">*(不同渠道记得修改默认MHT渠道)</span>
<label class="form-label col-xs-4 col-sm-2" title="批量添加时必须填纯数字" style="cursor:pointer">
<span class="c-red">* core</span></label>
<div class="formControls col-xs-8 col-sm-9">
<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" title="需要手动添加" style="cursor:pointer">
<span class="c-red">* channel</span>
</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" name="channel" value="MHT" style="width: 200px;" class="input-text"/>
<input type="text" name="channel" value="" style="width: 200px;" class="input-text"/>
</div>
</div>
@ -143,15 +149,6 @@
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2">
<span class="c-red">*(手动修改)</span>
core</label>
<div class="formControls col-xs-8 col-sm-9">
<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>
@ -170,6 +167,15 @@
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2" title="非批量添加不要修改" style="cursor:pointer">
<span class="c-green">数量:</span>
</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="number" name="count" style="width: 200px;" value="0" class="input-text"/>
</div>
</div>
</div>
</div>
<div class="row cl">
@ -223,6 +229,7 @@
var coreName = $("input[name='coreName']").val();
var server_version = $("input[name='server_version']").val();
var isWhite = $("input[name='isWhite']").val();
var count = $("input[name='count']").val();
var reg = new RegExp(/[\s\S]/i);
if (!reg.test(server_id) || !reg.test(_id) || !reg.test(name) || !reg.test(ip) ||
@ -252,7 +259,8 @@
"server_version":server_version,
"isWhite":isWhite,
"open_time":"0",
"open_type":"0"
"open_type":"0",
"count":count
}),
url: "/addServer",
dataType: "json",