Skip to content

Commit

Permalink
Merge pull request #91 from jzyong/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jzyong authored Sep 20, 2022
2 parents dec8e46 + 36d98b6 commit 99bc91d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 69 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jzyong/game-server/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/jzyong/game-server?style=social)](https://github.com/jzyong/game-server/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/jzyong/game-server?style=social)](https://github.com/jzyong/game-server/network)

简介
====
Expand All @@ -9,7 +11,10 @@
文档
---------

详细请查看[wiki](https://github.com/jzyong/game-server/wiki)
详细请查看[wiki](https://github.com/jzyong/game-server/wiki)
项目已停止维护:
* 新版本服务器 可参考 [GameServer4j](https://github.com/jzyong/GameServer4j)
* game-ai 移动到[GameAi4j](https://github.com/jzyong/GameAi4j)

交流
---------
Expand Down
130 changes: 66 additions & 64 deletions game-tool/src/main/java/com/jzy/game/tool/db/DBTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.jzy.game.tool.util.StringUtil;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;

import java.io.File;
import java.text.MessageFormat;
import java.util.*;
Expand All @@ -24,11 +25,11 @@
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author Administrator
*/
public class DBTool extends javax.swing.JFrame {
Expand Down Expand Up @@ -144,39 +145,39 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(db, 0, 151, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(javaFieldBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(insertDataBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(clearLogBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(db, 0, 151, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(javaFieldBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(insertDataBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(clearLogBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(db, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(insertDataBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(javaFieldBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(clearLogBtn)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(db, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(insertDataBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(javaFieldBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(clearLogBtn)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
.addContainerGap())
);

pack();
Expand All @@ -188,40 +189,41 @@ private void insertDataBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN
logTextArea.append("请选择表单\r\n");
return;
}
logTextArea.append(MessageFormat.format("选择配置表:{0}\r\n",selectSheets.size()));
logTextArea.append(MessageFormat.format("选择配置表:{0}\r\n", selectSheets.size()));
CountDownLatch countDownLatch = new CountDownLatch(selectSheets.size());
AtomicInteger count=new AtomicInteger(0);
AtomicInteger count = new AtomicInteger(0);
//更新数据库配置
selectSheets.forEach(sheetName -> {
threadPoolExecutor.execute(()->{
threadPoolExecutor.execute(() -> {
try {
String log = MongoUtil.insertConfigData(getMongoClient(), sheetNameFiles.get(sheetName).getAbsolutePath(), sheetName, getDBConfig().getDbName());
logTextArea.append(MessageFormat.format("[{0}] {1}\r\n",count.incrementAndGet(),log));
countDownLatch.countDown();
String log = MongoUtil.insertConfigData(getMongoClient(), sheetNameFiles.get(sheetName).getAbsolutePath(), sheetName, getDBConfig().getDbName());
logTextArea.append(MessageFormat.format("[{0}] {1}\r\n", count.incrementAndGet(), log));
LOGGER.info("{} 导入配置:{} 成功", sheetName, sheetNameFiles.get(sheetName).getName());
countDownLatch.countDown();
} catch (Exception e) {
countDownLatch.countDown();
LOGGER.error("更新数据", e);
}
});
});

Thread thread=new Thread(() -> {
try{
Thread thread = new Thread(() -> {
try {
countDownLatch.await();
}catch (Exception e){
LOGGER.error("定时等待",e);
} catch (Exception e) {
LOGGER.error("定时等待", e);
}
logTextArea.append("=========所有表单导入成功======== \r\n");
if(mongoClient!=null){
if (mongoClient != null) {
mongoClient.close();
}
//加载服务器配置
// String loadConfigUrl = getDBConfig().getLoadConfigUrl();
List<String> loadConfigUrls = getDBConfig().getLoadConfigUrls();
for (String loadConfigUrl:loadConfigUrls){
if(loadConfigUrl!=null&&!loadConfigUrl.equalsIgnoreCase("")){
for (String loadConfigUrl : loadConfigUrls) {
if (loadConfigUrl != null && !loadConfigUrl.equalsIgnoreCase("")) {
String log = HttpUtil.URLGet(loadConfigUrl);
logTextArea.append("游戏服-"+getDBConfig().getDbName()+" "+loadConfigUrl+":"+log+"更新配置成功\r\n");
logTextArea.append("游戏服-" + getDBConfig().getDbName() + " " + loadConfigUrl + ":" + log + "更新配置成功\r\n");
}
}
});
Expand All @@ -243,7 +245,7 @@ private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.showDialog(new JLabel(), "选择");
File file = jfc.getSelectedFile();
if(file!=null){
if (file != null) {
setSheetList(file.getAbsolutePath());
}
}//GEN-LAST:event_openMenuItemActionPerformed
Expand All @@ -257,37 +259,37 @@ private void javaFieldBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
}
selectSheets.forEach(sheetName -> {
try {
Args.Four<List<String>, List<String>, List<String>,List<String>> metaData = ExcelUtil.getMetaData(sheetNameFiles.get(sheetName).getAbsolutePath(), sheetName);
for(int i=0;i<metaData.a().size();i++){
Args.Four<List<String>, List<String>, List<String>, List<String>> metaData = ExcelUtil.getMetaData(sheetNameFiles.get(sheetName).getAbsolutePath(), sheetName);
for (int i = 0; i < metaData.a().size(); i++) {
//不显示客户端字段
if("client".equalsIgnoreCase(metaData.d().get(i))){
if ("client".equalsIgnoreCase(metaData.d().get(i))) {
continue;
}
StringBuilder sb=new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.append("/**").append(metaData.c().get(i)).append("*/").append("\r\n");
sb.append("private ");
String filedType = metaData.b().get(i).toLowerCase();
if("string".equals(filedType)||"date".equals(filedType)||"object".equals(filedType)){ //首字母大写
filedType=StringUtil.upFirstChar(filedType);
}else if("array".equals(filedType)){
filedType="List<Object>";
if ("string".equals(filedType) || "date".equals(filedType) || "object".equals(filedType)) { //首字母大写
filedType = StringUtil.upFirstChar(filedType);
} else if ("array".equals(filedType)) {
filedType = "List<Object>";
}
sb.append(filedType).append(" ").append(metaData.a().get(i)).append(";");
logTextArea.append(sb.toString() + "\r\n");
}
logTextArea.append("\r\n");
logTextArea.append("\r\n");
} catch (Exception e) {
LOGGER.error("更新数据", e);
}
});
if (mongoClient!=null){
if (mongoClient != null) {
mongoClient.close();
}

}//GEN-LAST:event_javaFieldBtnActionPerformed

private void clearLogBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearLogBtnActionPerformed
this.logTextArea.setText("");
this.logTextArea.setText("");
}//GEN-LAST:event_clearLogBtnActionPerformed

/**
Expand All @@ -297,7 +299,7 @@ public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
Expand Down Expand Up @@ -349,7 +351,7 @@ public void run() {
private Map<String, File> sheetNameFiles = new HashMap<>();
private static MongoClient mongoClient; //数据库客户端
private static Config config;
private ThreadPoolExecutor threadPoolExecutor= new ThreadPoolExecutor(10,20,5000, TimeUnit.MILLISECONDS,new LinkedBlockingDeque<>());
private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20, 5000, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());

/**
* 自定义初始化
Expand Down Expand Up @@ -377,8 +379,8 @@ private void init() throws Exception {
*/
public void setSheetList(String filePath) {
List<File> excelFiles = new ArrayList<>();
FileUtil.getFiles(filePath, excelFiles, ExcelUtil.xls,null);
FileUtil.getFiles(filePath, excelFiles, ExcelUtil.xlsx,null);
FileUtil.getFiles(filePath, excelFiles, ExcelUtil.xls, null);
FileUtil.getFiles(filePath, excelFiles, ExcelUtil.xlsx, null);
Vector sheetNames = new Vector();
sheetNameFiles.clear();
sheetJList.removeAll();
Expand All @@ -387,7 +389,7 @@ public void setSheetList(String filePath) {
try {
List<String> sheets = ExcelUtil.getSheetNames(absolutePath);
if (sheets != null) {
sheets.stream().filter(it->it.startsWith("config")).forEach(name -> {
sheets.stream().filter(it -> it.startsWith("config")).forEach(name -> {
sheetNameFiles.put(name, file);
sheetNames.add(name);
});
Expand All @@ -412,7 +414,7 @@ public void setSheetList(String filePath) {
public String getConfigPath() {
if (configPath == null) {
File file = new File(System.getProperty("user.dir"));
if ("target".equals(file.getName())||file.getAbsolutePath().contains("DBTool")) {
if ("target".equals(file.getName()) || file.getAbsolutePath().contains("DBTool")) {
configPath = file.getPath() + File.separatorChar + "config";
} else {
configPath = file.getPath() + File.separatorChar + "target" + File.separatorChar + "config";
Expand Down
4 changes: 2 additions & 2 deletions game-tool/src/main/java/com/jzy/game/tool/util/ExcelUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static Args.Five<List<String>, List<String>, List<String>, List<List<Obje
continue;
}
if ("".equalsIgnoreCase(firstColumn.getStringCellValue())) {
LOGGER.warn("{} {}-{} 有空行或者id未设值,跳过读取", sheetName, i + 1, 1);
LOGGER.trace("{} {}-{} 有空行或者id未设值,跳过读取", sheetName, i + 1, 1);
continue;
}

Expand All @@ -134,7 +134,7 @@ public static Args.Five<List<String>, List<String>, List<String>, List<List<Obje

datas.add(object);
} catch (Exception e) {
LOGGER.error(String.format("%d-%d 数据读取错误", i + 1, j + 1), e);
LOGGER.error(String.format("%s 表单%s %d-%d 数据读取错误",filePath,sheetName, i + 1, j + 1), e);
}
}
dataList.add(datas);
Expand Down
4 changes: 2 additions & 2 deletions game-tool/src/main/java/com/jzy/game/tool/util/MongoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static MongoDatabase getMongoDatabase(MongoClient client, String name) {
* @param dbName
*/
public static String insertConfigData(MongoClient client, String filePath, String sheetName, String dbName) throws Exception {
String retString = sheetName + " 更新成功";
String retString = sheetName + " 更新成功:";
Args.Five<List<String>, List<String>, List<String>, List<List<Object>>, List<String>> excel = ExcelUtil.readExcel(filePath, sheetName);
if (excel == null) {
LOGGER.warn("{}--{}未找到数据", filePath, sheetName);
Expand Down Expand Up @@ -183,7 +183,7 @@ public static Object getRealValue(String valueStr, String... type) {
if (StringUtil.isInteger(valueStr)) {
try {
return Integer.parseInt(valueStr);
}catch (NumberFormatException e){
} catch (NumberFormatException e) {
//数据过长,用long解析
return Long.parseLong(valueStr);
}
Expand Down

0 comments on commit 99bc91d

Please sign in to comment.