初始化静态数据表信息
parent
56a23659b3
commit
728d8c62da
|
|
@ -0,0 +1,18 @@
|
|||
id event groups
|
||||
int int mut,int#int,2
|
||||
1 102011 13#8|13#9|14#8|14#9
|
||||
2 101010 10#5
|
||||
3 102010 18#5|18#6|19#5|19#6
|
||||
4 102013 9#1|9#2|10#1|10#2
|
||||
5 102001 2#3|3#1|3#4
|
||||
6 101001 4#4|4#5|5#4|5#5|5#7|5#8|6#1|6#2|6#7|6#8|7#1|7#2|18#9|18#10|19#9|19#10|20#6|20#7
|
||||
7 102012 13#1|13#2|14#1|14#2
|
||||
8 102004 7#9|7#10|8#3|8#4|8#9|8#10|9#3|9#4|11#2|11#3|12#2|12#3|13#5|13#6|14#5|14#6|15#9|15#10|16#9|16#10
|
||||
9 102015 9#8|10#8
|
||||
10 102014 6#4|6#5|7#4|7#5
|
||||
11 101005 8#6|8#7|9#6|9#7|18#2|18#3|19#2|19#3
|
||||
12 102016 15#3|16#3
|
||||
13 101006 3#2
|
||||
14 101007 2#10
|
||||
15 101008 17#7
|
||||
16 101009 12#9
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
id length width
|
||||
int int int
|
||||
1 10 20
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
id event groups
|
||||
int int mut,int#int,2
|
||||
1 201012 5#3|5#4|6#3|6#4
|
||||
2 101010 9#8
|
||||
3 101011 16#7
|
||||
4 101001 2#6|3#5|3#6|4#8|4#9|5#8|6#7|7#7|8#5|8#6|9#5|9#6|11#4|12#4|14#6|15#6|16#3|16#4|17#3|17#4
|
||||
5 101002 12#1|12#2|13#1|13#2|18#5|18#6|19#6
|
||||
6 101003 4#4
|
||||
7 101004 5#10|6#10
|
||||
8 101005 7#1|7#2|8#1|8#2|11#8|11#9|12#8|12#9|14#2|14#3|14#9|14#10|15#2|15#3|15#9|15#10|19#4|19#7|19#8|20#3|20#8
|
||||
9 101006 3#8
|
||||
10 101007 5#5
|
||||
11 101008 11#10
|
||||
12 101009 18#2
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
id length width
|
||||
int int int
|
||||
1 10 20
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
Id Style Refresh
|
||||
int int int
|
||||
101001 1 2
|
||||
101002 3 2
|
||||
101003 5 2
|
||||
101004 9 2
|
||||
101005 1 2
|
||||
101006 6 3
|
||||
101007 7 3
|
||||
101008 6 2
|
||||
101009 6 3
|
||||
101010 8 2
|
||||
101011 8 2
|
||||
101012 4 2
|
||||
102001 9 2
|
||||
102002 1 2
|
||||
102003 1 2
|
||||
102004 1 2
|
||||
102005 6 3
|
||||
102006 6 3
|
||||
102007 6 3
|
||||
102008 6 3
|
||||
102009 6 3
|
||||
102010 3 1
|
||||
102011 3 2
|
||||
102012 3 2
|
||||
102013 3 1
|
||||
102014 3 2
|
||||
102015 2 2
|
||||
102016 2 2
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class ClassScanner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ClassScanner.class);
|
||||
|
||||
/**
|
||||
* 默认过滤器(无实现)
|
||||
*/
|
||||
private final static Predicate<Class<?>> EMPTY_FILTER = clazz -> true;
|
||||
|
||||
/**
|
||||
* 扫描目录下的所有class文件
|
||||
*
|
||||
* @param scanPackage 搜索的包根路径
|
||||
* @return
|
||||
*/
|
||||
public static Set<Class<?>> getClasses(String scanPackage) {
|
||||
return getClasses(scanPackage, EMPTY_FILTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有的子类(不包括抽象类)
|
||||
*
|
||||
* @param scanPackage 搜索的包根路径
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public static Set<Class<?>> listAllSubclasses(String scanPackage, Class<?> parent) {
|
||||
return getClasses(scanPackage, (clazz) -> {
|
||||
return parent.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有带制定注解的class列表
|
||||
*
|
||||
* @param scanPackage 搜索的包根路径
|
||||
* @param annotation
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Annotation> Set<Class<?>> listClassesWithAnnotation(String scanPackage,
|
||||
Class<A> annotation) {
|
||||
return getClasses(scanPackage, (clazz) -> clazz.getAnnotation(annotation) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描目录下的所有class文件
|
||||
*
|
||||
* @param pack 包路径
|
||||
* @param filter 自定义类过滤器
|
||||
* @return
|
||||
*/
|
||||
public static Set<Class<?>> getClasses(String pack, Predicate<Class<?>> filter) {
|
||||
Set<Class<?>> result = new LinkedHashSet<Class<?>>();
|
||||
// 是否循环迭代
|
||||
boolean recursive = true;
|
||||
// 获取包的名字 并进行替换
|
||||
String packageName = pack;
|
||||
String packageDirName = packageName.replace('.', '/');
|
||||
// 定义一个枚举的集合 并进行循环来处理这个目录下的things
|
||||
Enumeration<URL> dirs;
|
||||
try {
|
||||
dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
|
||||
// 循环迭代下去
|
||||
while (dirs.hasMoreElements()) {
|
||||
// 获取下一个元素
|
||||
URL url = dirs.nextElement();
|
||||
// 得到协议的名称
|
||||
String protocol = url.getProtocol();
|
||||
// 如果是以文件的形式保存在服务器上
|
||||
if ("file".equals(protocol)) {
|
||||
// 获取包的物理路径
|
||||
String filePath = URLDecoder.decode(url.getFile(), "UTF-8");
|
||||
// 以文件的方式扫描整个包下的文件 并添加到集合中
|
||||
findAndAddClassesInPackageByFile(packageName, filePath, recursive, result, filter);
|
||||
} else if ("jar".equals(protocol)) {
|
||||
// 如果是jar包文件
|
||||
Set<Class<?>> jarClasses = findClassFromJar(url, packageName, packageDirName, recursive, filter);
|
||||
result.addAll(jarClasses);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<Class<?>> findClassFromJar(URL url, String packageName, String packageDirName, boolean recursive,
|
||||
Predicate<Class<?>> filter) {
|
||||
Set<Class<?>> result = new LinkedHashSet<Class<?>>();
|
||||
try {
|
||||
// 获取jar
|
||||
JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile();
|
||||
// 从此jar包 得到一个枚举类
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
// 同样的进行循环迭代
|
||||
while (entries.hasMoreElements()) {
|
||||
// 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件
|
||||
JarEntry entry = entries.nextElement();
|
||||
String name = entry.getName();
|
||||
// 如果是以/开头的
|
||||
if (name.charAt(0) == '/') {
|
||||
// 获取后面的字符串
|
||||
name = name.substring(1);
|
||||
}
|
||||
// 如果前半部分和定义的包名相同
|
||||
if (name.startsWith(packageDirName)) {
|
||||
int idx = name.lastIndexOf('/');
|
||||
// 如果以"/"结尾 是一个包
|
||||
if (idx != -1) {
|
||||
// 获取包名 把"/"替换成"."
|
||||
packageName = name.substring(0, idx).replace('/', '.');
|
||||
}
|
||||
// 如果可以迭代下去 并且是一个包
|
||||
if ((idx != -1) || recursive) {
|
||||
// 如果是一个.class文件 而且不是目录
|
||||
if (name.endsWith(".class") && !entry.isDirectory()) {
|
||||
// 去掉后面的".class" 获取真正的类名
|
||||
String className = name.substring(packageName.length() + 1, name.length() - 6);
|
||||
try {
|
||||
// 添加到classes
|
||||
Class<?> c = Class.forName(packageName + '.' + className);
|
||||
if (filter.test(c)) {
|
||||
result.add(c);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void findAndAddClassesInPackageByFile(String packageName, String packagePath,
|
||||
final boolean recursive, Set<Class<?>> classes, Predicate<Class<?>> filter) {
|
||||
// 获取此包的目录 建立一个File
|
||||
File dir = new File(packagePath);
|
||||
// 如果不存在或者 也不是目录就直接返回
|
||||
if (!dir.exists() || !dir.isDirectory()) {
|
||||
// log.warn("用户定义包名 " + packageName + " 下没有任何文件");
|
||||
return;
|
||||
}
|
||||
// 如果存在 就获取包下的所有文件 包括目录
|
||||
File[] dirfiles = dir.listFiles(new FileFilter() {
|
||||
// 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件)
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return (recursive && file.isDirectory()) || (file.getName().endsWith(".class"));
|
||||
}
|
||||
});
|
||||
// 循环所有文件
|
||||
for (File file : dirfiles) {
|
||||
// 如果是目录 则继续扫描
|
||||
if (file.isDirectory()) {
|
||||
findAndAddClassesInPackageByFile(packageName + "." + file.getName(), file.getAbsolutePath(), recursive,
|
||||
classes, filter);
|
||||
} else {
|
||||
// 如果是java类文件 去掉后面的.class 只留下类名
|
||||
String className = file.getName().substring(0, file.getName().length() - 6);
|
||||
try {
|
||||
// 添加到集合中去
|
||||
Class<?> clazz = Thread.currentThread().getContextClassLoader()
|
||||
.loadClass(packageName + '.' + className);
|
||||
if (filter.test(clazz)) {
|
||||
classes.add(clazz);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class STableManager {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(STableManager.class);
|
||||
|
||||
/**
|
||||
* table表包名
|
||||
*/
|
||||
private static String data_parackage = null;
|
||||
|
||||
public static void initialize(String data_parackage) throws Exception {
|
||||
STableManager.data_parackage = data_parackage;
|
||||
updateTablesWithTableNames(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名字更新表数据
|
||||
*
|
||||
* @param hotfixTableStr
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void updateTablesWithTableNames(String hotfixTableStr) throws Exception {
|
||||
|
||||
String[] tableList = null;
|
||||
if (hotfixTableStr == null || hotfixTableStr.isEmpty()) { // 启动而不是热更
|
||||
// 加载全部
|
||||
tableList = null;
|
||||
} else {
|
||||
//更新指定表
|
||||
tableList = hotfixTableStr.split("\\|");
|
||||
}
|
||||
Set<Class<?>> messageCommandClasses = ClassScanner.listClassesWithAnnotation(data_parackage, Table.class);
|
||||
for (Class<?> cls : messageCommandClasses) {
|
||||
String tableName = cls.getAnnotation(Table.class).name();
|
||||
if (tableList != null) {
|
||||
if (!isHotFixContainTableName(tableList, tableName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Object stable = cls.newInstance();
|
||||
Method method = cls.getMethod("init");
|
||||
method.invoke(stable);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isHotFixContainTableName(String[] tableNames, String curTableName) {
|
||||
if (tableNames == null) {
|
||||
return false;
|
||||
}
|
||||
if (tableNames.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String oneTable : tableNames) {
|
||||
if (oneTable.equalsIgnoreCase(curTableName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置表到内存
|
||||
*/
|
||||
public static <T> Map<Integer, T> getConfig(Class<T> clazz) throws Exception {
|
||||
Map<Integer, T> map = new HashMap<>();
|
||||
try {
|
||||
String tableName = clazz.getAnnotation(Table.class).name();
|
||||
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
||||
File file = new File(path);
|
||||
String line;
|
||||
List<String> key = new ArrayList<>();
|
||||
List<String> type = new ArrayList<>();
|
||||
int lineNum = 0;
|
||||
if (!file.exists()) {
|
||||
LOGGER.error("file not find {}, do not find sheet with {} you need rebuild all sheet by gen sheet tool!", path, tableName);
|
||||
// return null;
|
||||
}
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
LOGGER.info("initMap:{}", clazz.getSimpleName());
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
T obj = clazz.newInstance();
|
||||
String[] prarms = line.split("\\t");
|
||||
switch (lineNum) {
|
||||
case 0:
|
||||
prarms = StringUtil.fieldHandle(prarms);
|
||||
key.addAll(Arrays.asList(prarms));
|
||||
break;
|
||||
case 1:
|
||||
type.addAll(Arrays.asList(prarms));
|
||||
break;
|
||||
default:
|
||||
dealParams(clazz, map, key, type, obj, prarms);
|
||||
break;
|
||||
}
|
||||
lineNum++;
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理参数
|
||||
*/
|
||||
private static <T> void dealParams(Class<T> clazz, Map<Integer, T> map, List<String> key, List<String> type, T obj, String[] prarms) throws NoSuchFieldException, IllegalAccessException {
|
||||
int id = Integer.parseInt(prarms[0]);
|
||||
for (int i = 0; i < prarms.length; i++) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(key.get(i));
|
||||
boolean flag = field.isAccessible();
|
||||
field.setAccessible(true);
|
||||
switch (type.get(i)) {
|
||||
case "int":
|
||||
field.set(obj, Integer.parseInt(prarms[i]));
|
||||
break;
|
||||
case "string":
|
||||
case "stringt":
|
||||
if (!"null".equalsIgnoreCase(prarms[i])) {
|
||||
field.set(obj, prarms[i]);
|
||||
}
|
||||
break;
|
||||
case "long":
|
||||
field.set(obj, Long.parseLong(prarms[i]));
|
||||
break;
|
||||
case "double":
|
||||
field.set(obj, Double.parseDouble(prarms[i]));
|
||||
break;
|
||||
case "float":
|
||||
field.set(obj, Float.parseFloat(prarms[i]));
|
||||
break;
|
||||
case "bool":
|
||||
field.set(obj, Boolean.parseBoolean(prarms[i]));
|
||||
break;
|
||||
default:
|
||||
if (type.get(i).startsWith("ref")) {
|
||||
field.set(obj, Integer.parseInt(prarms[i]));
|
||||
} else if (type.get(i).startsWith("mut")) {
|
||||
mut(key, type, obj, prarms, i, field);
|
||||
}
|
||||
break;
|
||||
}
|
||||
field.setAccessible(flag);
|
||||
map.put(id, obj);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作mut开头的类型
|
||||
*/
|
||||
private static <T> void mut(List<String> key, List<String> type, T obj, String[] prarms, int i, Field field) throws IllegalAccessException {
|
||||
String[] params = type.get(i).split(",");
|
||||
String[] type1 = params[1].split("#");
|
||||
int dimension = dimension(type1, params);
|
||||
if (dimension == 0) {
|
||||
field.set(obj, prarms[i]);
|
||||
} else {
|
||||
//全为int或者float
|
||||
switch (type1[0]) {
|
||||
case "int":
|
||||
intField(obj, prarms, i, field, dimension);
|
||||
break;
|
||||
case "float":
|
||||
floatField(obj, prarms, i, field, dimension);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void floatField(T obj, String[] prarms, int i, Field field, int dimension) throws IllegalAccessException {
|
||||
switch (dimension) {
|
||||
case 1:
|
||||
field.set(obj, StringUtil.parseFiledFloat(prarms[i]));
|
||||
break;
|
||||
case 2:
|
||||
field.set(obj, StringUtil.parseFiledFloat2(prarms[i]));
|
||||
break;
|
||||
case 3:
|
||||
field.set(obj, StringUtil.parseFiledFloat3(prarms[i]));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void intField(T obj, String[] prarms, int i, Field field, int dimension) throws IllegalAccessException {
|
||||
switch (dimension) {
|
||||
case 1:
|
||||
field.set(obj, StringUtil.parseFiledInt(prarms[i]));
|
||||
break;
|
||||
case 2:
|
||||
field.set(obj, StringUtil.parseFiledInt2(prarms[i]));
|
||||
break;
|
||||
case 3:
|
||||
field.set(obj, StringUtil.parseFiledInt3(prarms[i]));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是几维数组
|
||||
*/
|
||||
private static int dimension(String type[], String[] params) throws IllegalAccessException {
|
||||
|
||||
String type1 = type[0];
|
||||
boolean flag = false;
|
||||
for (int i = 0; i < type.length; i++) {
|
||||
if (!type1.equals(type[i])) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.parseInt(params[2]);
|
||||
}
|
||||
|
||||
private static String getType(String param) {
|
||||
String[] params = param.split(",");
|
||||
String[] type = params[1].split("#");
|
||||
return type[0];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: server
|
||||
* @description: 字符串函数类
|
||||
* @author: Diyigeng
|
||||
* @Company: BeiJing Blue Whale Technology CO.LTD. All rights reserved
|
||||
* @create: 2018-11-29 21:05
|
||||
**/
|
||||
public class StringUtil {
|
||||
|
||||
public static int[] parseFiledInt(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new int[0];
|
||||
}
|
||||
String[] param = value.split("#");
|
||||
int[] values = new int[param.length];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = Integer.parseInt(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static int[][] parseFiledInt2(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new int[0][0];
|
||||
}
|
||||
String[] param = value.split("\\|");
|
||||
int[][] values = new int[param.length][];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = parseFiledInt(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static int[][][] parseFiledInt3(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new int[0][0][0];
|
||||
}
|
||||
String[] param = value.split(",");
|
||||
int[][][] values = new int[param.length][][];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = parseFiledInt2(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static float[] parseFiledFloat(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new float[0];
|
||||
}
|
||||
String[] param = value.split("#");
|
||||
float[] values = new float[param.length];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = Float.parseFloat(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static float[][] parseFiledFloat2(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new float[0][0];
|
||||
}
|
||||
String[] param = value.split("\\|");
|
||||
float[][] values = new float[param.length][];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = parseFiledFloat(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static float[][][] parseFiledFloat3(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new float[0][0][0];
|
||||
}
|
||||
String[] param = value.split(",");
|
||||
float[][][] values = new float[param.length][][];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = parseFiledFloat2(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取配置表将首字母小写,如果只有两个字母则全变为小写
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String[] fieldHandle(String[] params) {
|
||||
String[] params1 = new String[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (params[i].length() <= 2) {
|
||||
params1[i] = params[i].toLowerCase();
|
||||
} else {
|
||||
params1[i] = (new StringBuilder()).append(Character.toLowerCase(params[i].charAt(0))).append(params[i].substring(1)).toString();
|
||||
}
|
||||
}
|
||||
return params1;
|
||||
}
|
||||
|
||||
|
||||
public static int[] getIntArray(String str, String sep) {
|
||||
String[] prop = getStringList(str, sep);
|
||||
List<Integer> tmp = new ArrayList<Integer>();
|
||||
for (int i = 0; i < prop.length; i++) {
|
||||
try {
|
||||
int r = Integer.parseInt(prop[i]);
|
||||
tmp.add(r);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
int[] ints = new int[tmp.size()];
|
||||
for (int i = 0; i < tmp.size(); i++) {
|
||||
ints[i] = tmp.get(i);
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
public static String[] getStringList(String str, String sep) {
|
||||
str = trim(str);
|
||||
return str.split(sep);
|
||||
}
|
||||
|
||||
|
||||
public static String trim(String str) {
|
||||
if (str == null) {
|
||||
str = "";
|
||||
} else {
|
||||
str = str.trim();
|
||||
}
|
||||
if (str.length() == 0) {
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str.charAt(0) == '"') {
|
||||
str = str.substring(1);
|
||||
}
|
||||
|
||||
if (str.charAt(str.length() - 1) == '"') {
|
||||
str = str.substring(0, str.length() - 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class SysUtil {
|
||||
public static String getLocalHostIp() throws Exception {
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
return addr.getHostAddress();
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
String osName = System.getProperty("os.name");
|
||||
return osName.matches("^(?i)Windows.*$");
|
||||
}
|
||||
|
||||
public static String getServerConfPath(String... filePath) throws IOException {
|
||||
return getPath("serverconf", filePath).toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getPath(String prefixDir, String... filePath) throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(getRootPath()).append(prefixDir);
|
||||
for (String p : filePath) {
|
||||
path.append(File.separator).append(p);
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
public static String getRootPath() throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
if (SysUtil.isWindows()) {// Window 系统
|
||||
path.append(new File(".").getCanonicalPath()).append(File.separator);
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println(getPath("gameserver\\src\\com\\ljsd\\gameserver\\user\\dao\\"));
|
||||
}
|
||||
|
||||
|
||||
// public static String getConfPath(String... filePath) throws IOException {
|
||||
// StringBuilder path = new StringBuilder();
|
||||
// if (SysUtil.isWindows()) {// Window 系统
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (String p : filePath) {
|
||||
// sb.append("\\").append(p);
|
||||
// }
|
||||
// path.append(new File(".").getCanonicalPath()).append("\\conf").append(sb);
|
||||
// } else {// Linux 系统
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (String p : filePath) {
|
||||
// sb.append("/").append(p);
|
||||
// }
|
||||
// path.append("../conf").append(sb);
|
||||
// }
|
||||
// return path.toString();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Table {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
public interface BaseConfig {
|
||||
void init() throws Exception;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map1")
|
||||
public class sCMap1 implements BaseConfig {
|
||||
public static Map<Integer, sCMap1> sCMap1;
|
||||
public static Map<Integer, sCMap1> sCardMapById;
|
||||
private int id;
|
||||
private int event;
|
||||
private int[][] groups;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMap1 = STableManager.getConfig(sCMap1.class);
|
||||
sCardMapById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMap1> entry : sCMap1.entrySet()) {
|
||||
sCardMapById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap1> getsCMap1() {
|
||||
return sCMap1;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap1> getsCardMapById() {
|
||||
return sCardMapById;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public int[][] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map2")
|
||||
public class sCMap2 implements BaseConfig {
|
||||
public static Map<Integer, sCMap2> sCMap1;
|
||||
public static Map<Integer, sCMap2> sCardMapById;
|
||||
private int id;
|
||||
private int event;
|
||||
private int[][] groups;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMap1 = STableManager.getConfig(sCMap2.class);
|
||||
sCardMapById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMap2> entry : sCMap1.entrySet()) {
|
||||
sCardMapById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap2> getsCMap1() {
|
||||
return sCMap1;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap2> getsCardMapById() {
|
||||
return sCardMapById;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public int[][] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map1_size")
|
||||
public class sCMapSize1 implements BaseConfig {
|
||||
public static Map<Integer, sCMapSize1> sCMapSize1;
|
||||
public static Map<Integer, sCMapSize1> sCardMapSizeById;
|
||||
private int id;
|
||||
private int length;
|
||||
private int width;
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMapSize1 = STableManager.getConfig(sCMapSize1.class);
|
||||
sCardMapSizeById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMapSize1> entry : sCMapSize1.entrySet()) {
|
||||
sCardMapSizeById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Map<Integer, com.ljsd.jieling.models.sCMapSize1> getsCMapSize1() {
|
||||
return sCMapSize1;
|
||||
}
|
||||
|
||||
public static Map<Integer, com.ljsd.jieling.models.sCMapSize1> getsCardMapSizeById() {
|
||||
return sCardMapSizeById;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map2_size")
|
||||
public class sCMapSize2 implements BaseConfig {
|
||||
public static Map<Integer, sCMapSize2> sCMapSize1;
|
||||
public static Map<Integer, sCMapSize2> sCardMapSizeById;
|
||||
private int id;
|
||||
private int length;
|
||||
private int width;
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMapSize1 = STableManager.getConfig(sCMapSize2.class);
|
||||
sCardMapSizeById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMapSize2> entry : sCMapSize1.entrySet()) {
|
||||
sCardMapSizeById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMapSize2> getsCMapSize1() {
|
||||
return sCMapSize1;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMapSize2> getsCardMapSizeById() {
|
||||
return sCardMapSizeById;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue