fix read s table
parent
098024c896
commit
b1e9d4040d
|
@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -81,43 +82,48 @@ public class STableManager {
|
||||||
String tableName = clazz.getAnnotation(Table.class).name();
|
String tableName = clazz.getAnnotation(Table.class).name();
|
||||||
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
String line;
|
|
||||||
List<String> key = new ArrayList<>();
|
|
||||||
List<String> type = new ArrayList<>();
|
|
||||||
int lineNum = 0;
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
LOGGER.error("file not find {}, do not find sheet with {} you need rebuild all sheet by gen sheet tool!", path, tableName);
|
LOGGER.error("file not find {}, do not find sheet with {} you need rebuild all sheet by gen sheet tool!", path, tableName);
|
||||||
// return null;
|
// return null;
|
||||||
}
|
}
|
||||||
try(BufferedReader bufferedReader = new BufferedReader(new FileReader(file))){
|
LOGGER.info("initMap:{}", clazz.getSimpleName());
|
||||||
LOGGER.info("initMap:{}", clazz.getSimpleName());
|
readFileToCache(clazz, map, file);
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
if (line.isEmpty()){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> void readFileToCache(Class<T> clazz, Map<Integer, T> map, File file) throws IOException, InstantiationException, IllegalAccessException, NoSuchFieldException {
|
||||||
|
String line;
|
||||||
|
List<String> key = new ArrayList<>();
|
||||||
|
List<String> type = new ArrayList<>();
|
||||||
|
int lineNum = 0;
|
||||||
|
try(BufferedReader bufferedReader = new BufferedReader(new FileReader(file))){
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
if (line.isEmpty()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取配置表到内存
|
* 读取配置表到内存
|
||||||
|
@ -125,44 +131,20 @@ public class STableManager {
|
||||||
public static <T> Map<Integer, Map<Integer, T>> getMapConfig(Class<T> clazz) throws Exception {
|
public static <T> Map<Integer, Map<Integer, T>> getMapConfig(Class<T> clazz) throws Exception {
|
||||||
Map<Integer, Map<Integer, T>> map = new HashMap<>();
|
Map<Integer, Map<Integer, T>> map = new HashMap<>();
|
||||||
String tableName = clazz.getAnnotation(Table.class).name();
|
String tableName = clazz.getAnnotation(Table.class).name();
|
||||||
int mapType = 100;
|
String pathDir = SysUtil.getPath("conf", "server");
|
||||||
for (int i = 100; i < 1000; i++) {
|
File mapDir = new File(pathDir);
|
||||||
Map<Integer, T> mapConf = new HashMap<>();
|
String prefix = tableName + "_";
|
||||||
tableName = tableName + "_"+ i;
|
int preLength = prefix.length();
|
||||||
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
for(File mapFile : mapDir.listFiles()){
|
||||||
File file = new File(path);
|
tableName = mapFile.getName();
|
||||||
if (!file.exists()) {
|
if(!mapFile.getName().startsWith(prefix)){
|
||||||
tableName = tableName.substring(0, 3);
|
|
||||||
mapType += 100;
|
|
||||||
i = mapType;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String line;
|
int mapId = Integer.parseInt(tableName.substring(preLength).split("\\.")[0]);
|
||||||
List<String> key = new ArrayList<>();
|
LOGGER.info("initMap:{}", tableName);
|
||||||
List<String> type = new ArrayList<>();
|
Map<Integer, T> mapConf = new HashMap<>();
|
||||||
int lineNum = 0;
|
readFileToCache(clazz,mapConf,mapFile);
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))){
|
map.put(mapId, mapConf);
|
||||||
LOGGER.info("initMap:{}", tableName);
|
|
||||||
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, mapConf, key, type, obj, prarms);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lineNum++;
|
|
||||||
}
|
|
||||||
map.put(i, mapConf);
|
|
||||||
tableName = tableName.substring(0, 3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue