package com.config;
|
|
import java.io.File;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
import org.dom4j.Document;
|
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentHelper;
|
import org.dom4j.Element;
|
import org.dom4j.io.OutputFormat;
|
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.XMLWriter;
|
|
public class AppConfig {
|
public static final int SOURCE_BATTDATA_TYPE_FBSDEV = 0;
|
public static final int SOURCE_BATTDATA_TYPE_SQLSERVER = 1;
|
public static final int SOURCE_BATTDATA_TYPE_C_INTERFACE = 2;
|
public static final int SOURCE_BATTDATA_TYPE_SQLSERVER_AND_C_INTERFACE = 3;
|
private final String ConfigFileName = "config.xml";
|
|
private String mysqlServerIp = "127.0.0.1";
|
|
private int sourceBattDataType = 0;
|
|
private int sourceSQLServerType = 1;
|
private String sourceSQLServerIp = "127.0.0.1";
|
private String sourceSQLServerUsrName = "sxfg001";
|
private String sourceSQLServerPWD = "sxfg001";
|
private int sourceSQLServerPort = 5000;
|
|
private String cInterfaceServerIp = "127.0.0.1";
|
private String cInterfaceUsrName = "cdnt";
|
private String cInterfacePWD = "cdnt";
|
private int cInterfaceSocketPort = 7009;
|
|
private String fbsDeviceBaseIp = "192.168.0.1";
|
|
private boolean sybSrvCurrChargeDirPos = false;
|
|
private int mysqlConnCountMax = 300;
|
private int workThreadCountMax = 300;
|
|
private boolean battAlarmFnEn = false;
|
private int battAlarmFnStartDelay = 60;
|
private int battAlarmClearedDelay = 600;
|
private int battAlarmDataDayCountMax = 400;
|
|
private boolean battResStoreFnEn = false;
|
private int battResStoreDelayForTestManual = 1200;
|
private int battResStoreDayInterval = 7;
|
|
private boolean battAutoStoreFnEn = false;
|
private int battAutoStoreDelayForStartUp = 60;
|
private int battAutoStoreMinuteInterval = 10;
|
private int battAutoStoreDayCountMax = 7;
|
|
private boolean userTaskFnEn = true;
|
private boolean userTaskSmsFnEn = false;
|
private String userTaskSmsDevIp = "192.168.1.60";
|
|
private boolean idce8200ServerFnEn = false;
|
private boolean mobileServerFnEn = true;
|
private boolean ftpServerFnEn = true;
|
|
private int autoSqlDbBackUpDayInterval = 30;
|
private boolean bpm7100CommErrDataClearEN = true;
|
private int fbsDevCommRate = 1;
|
|
private boolean DevBTS_SeverComm_En = true;
|
private boolean DevFBS9100_SeverComm_En = true;
|
private boolean DevFBS9100_ClientComm_En = true;
|
|
public AppConfig() {
|
String path = "config.xml";
|
|
File f = new File(path);
|
if (!f.exists()) {
|
writeConfigToXml();
|
}
|
|
readConfigFromXml();
|
}
|
|
public String getMysqlServerIp() {
|
return this.mysqlServerIp;
|
}
|
|
public String getSourceSQLServerIp() {
|
return this.sourceSQLServerIp;
|
}
|
|
public String getSourceSQLServerUsrName() {
|
return this.sourceSQLServerUsrName;
|
}
|
|
public String getSourceSQLServerPWD() {
|
return this.sourceSQLServerPWD;
|
}
|
|
public int getSourceSQLServerPort() {
|
return this.sourceSQLServerPort;
|
}
|
|
public String getCInterfaceServerIp() {
|
return this.cInterfaceServerIp;
|
}
|
|
public String getCInterfaceUsrName() {
|
return this.cInterfaceUsrName;
|
}
|
|
public String getCInterfacePWD() {
|
return this.cInterfacePWD;
|
}
|
|
public int getCInterfacePort() {
|
return this.cInterfaceSocketPort;
|
}
|
|
public String getFbsDeviceBaseIp() {
|
return this.fbsDeviceBaseIp;
|
}
|
|
public int getSourceSQLServerType() {
|
return this.sourceSQLServerType;
|
}
|
|
public int getSourceBattDataType() {
|
return this.sourceBattDataType;
|
}
|
|
public boolean getSybSrvCurrChargeDirPos() {
|
return this.sybSrvCurrChargeDirPos;
|
}
|
|
public int getMysqlConnCountMax() {
|
return this.mysqlConnCountMax;
|
}
|
|
public int getWorkThreadCountMax() {
|
return this.workThreadCountMax;
|
}
|
|
public boolean getBattAlarmFnEn() {
|
return this.battAlarmFnEn;
|
}
|
|
public int getBattAlarmFnStartDelay() {
|
return this.battAlarmFnStartDelay;
|
}
|
|
public int getBattAlarmClearedDelay() {
|
return this.battAlarmClearedDelay;
|
}
|
|
public int getBattAlarmDataDayCountMax() {
|
return this.battAlarmDataDayCountMax;
|
}
|
|
public boolean getBattResStoreFnEn() {
|
return this.battResStoreFnEn;
|
}
|
|
public int getBattResStoreDelayForTestManual() {
|
return this.battResStoreDelayForTestManual;
|
}
|
|
public int getBattResStoreDayInterval() {
|
return this.battResStoreDayInterval;
|
}
|
|
public boolean getBattAutoStoreFnEn() {
|
return this.battAutoStoreFnEn;
|
}
|
|
public int getBattAutoStoreDelayForStartUp() {
|
return this.battAutoStoreDelayForStartUp;
|
}
|
|
public int getBattAutoStoreMinuteInterval() {
|
return this.battAutoStoreMinuteInterval;
|
}
|
|
public int getBattAutoStoreDayCountMax() {
|
return this.battAutoStoreDayCountMax;
|
}
|
|
public boolean getUserTaskFnEn() {
|
return this.userTaskFnEn;
|
}
|
|
public boolean getUserTaskSmsFnEn() {
|
return this.userTaskSmsFnEn;
|
}
|
|
public String getUserTaskSmsDevIp() {
|
return this.userTaskSmsDevIp;
|
}
|
|
public boolean getIdce8200ServerFnEn() {
|
return this.idce8200ServerFnEn;
|
}
|
|
public boolean getMobileServerFnEn() {
|
return this.mobileServerFnEn;
|
}
|
|
public boolean getFtpServerFnEn() {
|
return this.ftpServerFnEn;
|
}
|
|
public int getAutoSqlDbBackUpDayInterval() {
|
return this.autoSqlDbBackUpDayInterval;
|
}
|
|
public boolean getBpm7100CommErrDataClearEN() {
|
return this.bpm7100CommErrDataClearEN;
|
}
|
|
public int getFbsDevCommRate() {
|
return this.fbsDevCommRate;
|
}
|
|
public boolean getBTS_CommEn() {
|
return this.DevBTS_SeverComm_En;
|
}
|
|
public boolean getFbs9100_ServerCommEn() {
|
return this.DevFBS9100_SeverComm_En;
|
}
|
|
public boolean getFbs9100_ClientCommEn() {
|
return this.DevFBS9100_ClientComm_En;
|
}
|
|
public void writeConfigToXml() {
|
try {
|
Document document = DocumentHelper.createDocument();
|
Element root = document.addElement("root");
|
|
Element param = root.addElement("mysql_server_ip");
|
param.addText(this.mysqlServerIp);
|
|
root.addComment("SOURCE_BATTDATA_TYPE_FBSDEV = 0");
|
root.addComment("SOURCE_BATTDATA_TYPE_SQLSERVER = 1");
|
root.addComment("SOURCE_BATTDATA_TYPE_C_INTERFACE = 2");
|
root.addComment("SOURCE_BATTDATA_TYPE_SQLSERVER_AND_C_INTERFACE = 3");
|
|
param = root.addElement("source_battdata_type");
|
param.addText(String.valueOf(this.sourceBattDataType));
|
|
param = root.addElement("source_sqlserver_config");
|
|
param.addComment("SOURCE_SQLSERVER_TYPE_SYBASE_DEMO = 0");
|
param.addComment("SOURCE_SQLSERVER_TYPE_SYBASE = 1");
|
param.addComment("SOURCE_SQLSERVER_TYPE_MSSQLSERVER = 2");
|
|
Element sub_param = param.addElement("source_sqlserver_type");
|
sub_param.addText(String.valueOf(this.sourceSQLServerType));
|
|
sub_param = param.addElement("source_sqlserver_ip");
|
sub_param.addText(this.sourceSQLServerIp);
|
|
sub_param = param.addElement("source_sqlserver_usrname");
|
sub_param.addText(this.sourceSQLServerUsrName);
|
|
sub_param = param.addElement("source_sqlserver_pwd");
|
sub_param.addText(this.sourceSQLServerPWD);
|
|
sub_param = param.addElement("source_sqlserver_port");
|
sub_param.addText(String.valueOf(this.sourceSQLServerPort));
|
|
param = root.addElement("c_interface_server_config");
|
|
sub_param = param.addElement("c_interface_server_ip");
|
sub_param.addText(this.cInterfaceServerIp);
|
|
sub_param = param.addElement("c_interface_usrname");
|
sub_param.addText(this.cInterfaceUsrName);
|
|
sub_param = param.addElement("c_interface_pwd");
|
sub_param.addText(this.cInterfacePWD);
|
|
sub_param = param.addElement("c_interface_sokcet_port");
|
sub_param.addText(String.valueOf(this.cInterfaceSocketPort));
|
|
param = root.addElement("fbs_device_base_ip");
|
param.addText(this.fbsDeviceBaseIp);
|
|
param = root.addElement("syb_srv_curr_charge_dir_pos");
|
param.addText(String.valueOf(this.sybSrvCurrChargeDirPos));
|
|
param = root.addElement("mysql_conn_count_max");
|
param.addText(String.valueOf(this.mysqlConnCountMax));
|
|
param = root.addElement("work_thread_count_max");
|
param.addText(String.valueOf(this.workThreadCountMax));
|
|
param = root.addElement("batt_alarm_fn_config");
|
|
sub_param = param.addElement("batt_alarm_fn_en");
|
sub_param.addText(String.valueOf(this.battAlarmFnEn));
|
|
sub_param = param.addElement("batt_alarm_fn_start_delay");
|
sub_param.addText(String.valueOf(this.battAlarmFnStartDelay));
|
|
sub_param = param.addElement("batt_alarm_cleared_delay");
|
sub_param.addText(String.valueOf(this.battAlarmClearedDelay));
|
|
sub_param = param.addElement("batt_alarm_data_daycount_max");
|
sub_param.addText(String.valueOf(this.battAlarmDataDayCountMax));
|
|
param = root.addElement("batt_res_store_fn_config");
|
|
sub_param = param.addElement("batt_res_store_fn_en");
|
sub_param.addText(String.valueOf(this.battResStoreFnEn));
|
|
sub_param = param.addElement("batt_res_store_delay_for_test_manual");
|
sub_param.addText(String.valueOf(this.battResStoreDelayForTestManual));
|
|
sub_param = param.addElement("batt_res_store_day_interval");
|
sub_param.addText(String.valueOf(this.battResStoreDayInterval));
|
|
param = root.addElement("batt_auto_store_fn_config");
|
|
sub_param = param.addElement("batt_auto_store_fn_en");
|
sub_param.addText(String.valueOf(this.battAutoStoreFnEn));
|
|
sub_param = param.addElement("batt_auto_store_delay_for_start_up");
|
sub_param.addText(String.valueOf(this.battAutoStoreDelayForStartUp));
|
|
sub_param = param.addElement("batt_auto_store_minute_interval");
|
sub_param.addText(String.valueOf(this.battAutoStoreMinuteInterval));
|
|
sub_param = param.addElement("batt_auto_store_day_count_max");
|
sub_param.addText(String.valueOf(this.battAutoStoreDayCountMax));
|
|
param = root.addElement("user_task_fn_config");
|
|
sub_param = param.addElement("user_task_fn_en");
|
sub_param.addText(String.valueOf(this.userTaskFnEn));
|
|
sub_param = param.addElement("user_task_sms_fn_en");
|
sub_param.addText(String.valueOf(this.userTaskSmsFnEn));
|
|
sub_param = param.addElement("user_task_sms_dev_ip");
|
sub_param.addText(this.userTaskSmsDevIp);
|
|
param = root.addElement("idce8200_server_fn_config");
|
param.addText(String.valueOf(this.idce8200ServerFnEn));
|
|
param = root.addElement("mobile_server_fn_config");
|
param.addText(String.valueOf(this.mobileServerFnEn));
|
|
param = root.addElement("ftp_server_fn_config");
|
param.addText(String.valueOf(this.ftpServerFnEn));
|
|
param = root.addElement("auto_sqldb_backup_dayinterval");
|
param.addText(String.valueOf(this.autoSqlDbBackUpDayInterval));
|
|
param = root.addElement("bpm7100_commerr_dataclear_en");
|
param.addText(String.valueOf(this.bpm7100CommErrDataClearEN));
|
|
param = root.addElement("fbsdev_comm_rate");
|
param.addText(String.valueOf(this.fbsDevCommRate));
|
|
param = root.addElement("dev_bts_severcomm_en");
|
param.addText(String.valueOf(this.DevBTS_SeverComm_En));
|
|
param = root.addElement("devfbs9100_severcomm_en");
|
param.addText(String.valueOf(this.DevFBS9100_SeverComm_En));
|
|
param = root.addElement("devfbs9100_clientcomm_en");
|
param.addText(String.valueOf(this.DevFBS9100_ClientComm_En));
|
|
OutputFormat format = OutputFormat.createPrettyPrint();
|
format.setEncoding("gbk");
|
XMLWriter writer2 = new XMLWriter(new FileWriter("config.xml"), format);
|
writer2.write(document);
|
writer2.close();
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void readConfigFromXml() {
|
boolean res = true;
|
try {
|
SAXReader reader = new SAXReader();
|
Document document = reader.read(new File("config.xml"));
|
Element rootnode = document.getRootElement();
|
|
Element node = rootnode.element("mysql_server_ip");
|
this.mysqlServerIp = node.getTextTrim();
|
|
node = rootnode.element("source_battdata_type");
|
this.sourceBattDataType = Integer.parseInt(node.getTextTrim());
|
if (this.sourceBattDataType < 0)
|
this.sourceBattDataType = 0;
|
if (this.sourceBattDataType > 3) {
|
this.sourceBattDataType = 3;
|
}
|
|
node = rootnode.element("source_sqlserver_config");
|
|
Element sub_node = node.element("source_sqlserver_type");
|
this.sourceSQLServerType = Integer.parseInt(sub_node.getTextTrim());
|
|
sub_node = node.element("source_sqlserver_ip");
|
this.sourceSQLServerIp = sub_node.getTextTrim();
|
|
sub_node = node.element("source_sqlserver_usrname");
|
this.sourceSQLServerUsrName = sub_node.getTextTrim();
|
|
sub_node = node.element("source_sqlserver_pwd");
|
this.sourceSQLServerPWD = sub_node.getTextTrim();
|
|
sub_node = node.element("source_sqlserver_port");
|
this.sourceSQLServerPort = Integer.parseInt(sub_node.getTextTrim());
|
|
node = rootnode.element("c_interface_server_config");
|
|
sub_node = node.element("c_interface_server_ip");
|
this.cInterfaceServerIp = sub_node.getTextTrim();
|
|
sub_node = node.element("c_interface_usrname");
|
this.cInterfaceUsrName = sub_node.getTextTrim();
|
|
sub_node = node.element("c_interface_pwd");
|
this.cInterfacePWD = sub_node.getTextTrim();
|
|
sub_node = node.element("c_interface_sokcet_port");
|
this.cInterfaceSocketPort = Integer.parseInt(sub_node.getTextTrim());
|
|
node = rootnode.element("fbs_device_base_ip");
|
this.fbsDeviceBaseIp = node.getTextTrim();
|
|
node = rootnode.element("syb_srv_curr_charge_dir_pos");
|
this.sybSrvCurrChargeDirPos = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("mysql_conn_count_max");
|
this.mysqlConnCountMax = Integer.parseInt(node.getTextTrim());
|
if (this.mysqlConnCountMax < 5)
|
this.mysqlConnCountMax = 5;
|
if (this.mysqlConnCountMax > 400) {
|
this.mysqlConnCountMax = 400;
|
}
|
node = rootnode.element("work_thread_count_max");
|
this.workThreadCountMax = Integer.parseInt(node.getTextTrim());
|
|
if (this.workThreadCountMax < 10)
|
this.workThreadCountMax = 10;
|
if (this.workThreadCountMax > 400) {
|
this.workThreadCountMax = 400;
|
}
|
|
node = rootnode.element("batt_alarm_fn_config");
|
|
sub_node = node.element("batt_alarm_fn_en");
|
this.battAlarmFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
|
|
sub_node = node.element("batt_alarm_fn_start_delay");
|
this.battAlarmFnStartDelay = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAlarmFnStartDelay < 0)
|
this.battAlarmFnStartDelay = 0;
|
if (this.battAlarmFnStartDelay > 3600) {
|
this.battAlarmFnStartDelay = 3600;
|
}
|
sub_node = node.element("batt_alarm_cleared_delay");
|
this.battAlarmClearedDelay = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAlarmClearedDelay < 0)
|
this.battAlarmClearedDelay = 0;
|
if (this.battAlarmClearedDelay > 3600) {
|
this.battAlarmClearedDelay = 3600;
|
}
|
|
sub_node = node.element("batt_alarm_data_daycount_max");
|
this.battAlarmDataDayCountMax = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAlarmDataDayCountMax < 7)
|
this.battAlarmDataDayCountMax = 7;
|
if (this.battAlarmDataDayCountMax > 2048) {
|
this.battAlarmDataDayCountMax = 2048;
|
}
|
|
node = rootnode.element("batt_res_store_fn_config");
|
|
sub_node = node.element("batt_res_store_fn_en");
|
this.battResStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
|
|
sub_node = node.element("batt_res_store_delay_for_test_manual");
|
this.battResStoreDelayForTestManual = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battResStoreDelayForTestManual < 180)
|
this.battResStoreDelayForTestManual = 180;
|
if (this.battResStoreDelayForTestManual > 1800) {
|
this.battResStoreDelayForTestManual = 1800;
|
}
|
sub_node = node.element("batt_res_store_day_interval");
|
this.battResStoreDayInterval = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battResStoreDayInterval < 1)
|
this.battResStoreDayInterval = 1;
|
if (this.battResStoreDayInterval > 360) {
|
this.battResStoreDayInterval = 360;
|
}
|
|
node = rootnode.element("batt_auto_store_fn_config");
|
|
sub_node = node.element("batt_auto_store_fn_en");
|
this.battAutoStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
|
|
sub_node = node.element("batt_auto_store_delay_for_start_up");
|
this.battAutoStoreDelayForStartUp = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAutoStoreDelayForStartUp < 180)
|
this.battAutoStoreDelayForStartUp = 180;
|
if (this.battAutoStoreDelayForStartUp > 3600) {
|
this.battAutoStoreDelayForStartUp = 3600;
|
}
|
sub_node = node.element("batt_auto_store_minute_interval");
|
this.battAutoStoreMinuteInterval = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAutoStoreMinuteInterval < 10)
|
this.battAutoStoreMinuteInterval = 10;
|
if (this.battAutoStoreMinuteInterval > 43200) {
|
this.battAutoStoreMinuteInterval = 43200;
|
}
|
sub_node = node.element("batt_auto_store_day_count_max");
|
this.battAutoStoreDayCountMax = Integer.parseInt(sub_node.getTextTrim());
|
if (this.battAutoStoreDayCountMax < 1)
|
this.battAutoStoreDayCountMax = 1;
|
if (this.battAutoStoreDayCountMax > 300) {
|
this.battAutoStoreDayCountMax = 300;
|
}
|
|
node = rootnode.element("user_task_fn_config");
|
|
sub_node = node.element("user_task_fn_en");
|
this.userTaskFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
|
|
sub_node = node.element("user_task_sms_fn_en");
|
this.userTaskSmsFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
|
|
sub_node = node.element("user_task_sms_dev_ip");
|
this.userTaskSmsDevIp = sub_node.getTextTrim();
|
|
node = rootnode.element("idce8200_server_fn_config");
|
this.idce8200ServerFnEn = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("mobile_server_fn_config");
|
this.mobileServerFnEn = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("ftp_server_fn_config");
|
this.ftpServerFnEn = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("auto_sqldb_backup_dayinterval");
|
this.autoSqlDbBackUpDayInterval = Integer.parseInt(node.getTextTrim());
|
if (this.autoSqlDbBackUpDayInterval < 7) {
|
this.autoSqlDbBackUpDayInterval = 7;
|
}
|
if (this.autoSqlDbBackUpDayInterval > 365) {
|
this.autoSqlDbBackUpDayInterval = 365;
|
}
|
|
node = rootnode.element("bpm7100_commerr_dataclear_en");
|
this.bpm7100CommErrDataClearEN = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("fbsdev_comm_rate");
|
this.fbsDevCommRate = Integer.parseInt(node.getTextTrim());
|
|
node = rootnode.element("dev_bts_severcomm_en");
|
this.DevBTS_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("devfbs9100_severcomm_en");
|
this.DevFBS9100_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
|
|
node = rootnode.element("devfbs9100_clientcomm_en");
|
this.DevFBS9100_ClientComm_En = Boolean.parseBoolean(node.getTextTrim());
|
} catch (NullPointerException | NumberFormatException | DocumentException e) {
|
res = false;
|
e.printStackTrace();
|
} finally {
|
if (!res)
|
writeConfigToXml();
|
}
|
}
|
}
|
|
/*
|
* Location:
|
* C:\Users\LiJun\Desktop\公司各种设备资料\9600显示模块相关文件\后台程序\2018-09-07\BattFBS9600XSP.
|
* jar Qualified Name: com.config.AppConfig JD-Core Version: 0.6.2
|
*/
|