116 lines
2.7 KiB
Java
116 lines
2.7 KiB
Java
package config;
|
|
|
|
import manager.STableManager;
|
|
import manager.Table;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@Table(name = "ExchangeRate")
|
|
public class SExchangeRate implements BaseConfig {
|
|
|
|
private int id;
|
|
|
|
private int price_1;
|
|
|
|
private float price_2;
|
|
|
|
private float price_3;
|
|
|
|
private float price_4;
|
|
|
|
private float price_5;
|
|
|
|
private float price_6;
|
|
|
|
private float price_7;
|
|
|
|
private float price_8;
|
|
|
|
private float price_9;
|
|
|
|
public static HashMap<Integer, HashMap<Integer, Double>> doubleIntegerHashMap = new HashMap<>(); //币种 原货币 本货币
|
|
|
|
|
|
@Override
|
|
public void init() throws Exception {
|
|
doubleIntegerHashMap = new HashMap<>();
|
|
Map<Integer, SExchangeRate> config = STableManager.getConfig(SExchangeRate.class);
|
|
|
|
Field[] fields = SExchangeRate.class.getDeclaredFields();
|
|
for (Field field : fields) {
|
|
field.setAccessible(true);
|
|
String temp = "price_";
|
|
if (!field.getName().contains(temp)) {
|
|
continue;
|
|
}
|
|
String substring = field.getName().substring(temp.length());
|
|
|
|
Integer integer = Integer.valueOf(substring);
|
|
doubleIntegerHashMap.putIfAbsent(integer, new HashMap<>());
|
|
|
|
HashMap<Integer, Double> doubleIntegerHashMap = SExchangeRate.doubleIntegerHashMap.get(integer);
|
|
|
|
config.entrySet().forEach(integerSExchangeRateEntry -> {
|
|
try {
|
|
if (integer == 1) {
|
|
doubleIntegerHashMap.put(integerSExchangeRateEntry.getValue().getPrice_1(), Double.valueOf((int) field.get(integerSExchangeRateEntry.getValue())));
|
|
} else {
|
|
float f = (float) field.get(integerSExchangeRateEntry.getValue());
|
|
double v = Double.parseDouble(Float.toString(f));
|
|
doubleIntegerHashMap.put(integerSExchangeRateEntry.getValue().getPrice_1(), v);
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public int getPrice_1() {
|
|
return price_1;
|
|
}
|
|
|
|
public float getPrice_2() {
|
|
return price_2;
|
|
}
|
|
|
|
public float getPrice_3() {
|
|
return price_3;
|
|
}
|
|
|
|
public float getPrice_4() {
|
|
return price_4;
|
|
}
|
|
|
|
public float getPrice_5() {
|
|
return price_5;
|
|
}
|
|
|
|
public float getPrice_6() {
|
|
return price_6;
|
|
}
|
|
|
|
public float getPrice_7() {
|
|
return price_7;
|
|
}
|
|
|
|
public float getPrice_8() {
|
|
return price_8;
|
|
}
|
|
|
|
public float getPrice_9() {
|
|
return price_9;
|
|
}
|
|
|
|
} |