蓄电池监控管理平台数据库初始化程序
BattMonitor_DB_Builder/src/com/config/AppConfig.java
@@ -1,694 +1,694 @@
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;
/**
 * 创建config.xml文件并更新  config.xml 文件中的属性值
 * @author 军
 *
 */
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 boolean mysqlDB_RecreateEn = false;
   private String mysqlServerIp = "127.0.0.1";
   private int sourceBattDataType = 0;
   //----------------------------------------------------------------//
   private int sourceSQLServerType = 0;
   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 = System.getProperty("user.dir");
      if(path.contains("\\"))
         path += "\\";
      else path += "/";
      */
      String path = ConfigFileName;
      //System.out.println(path);
      File f = new File(path);
      if(false == f.exists())
      {
         writeConfigToXml();
      }
      readConfigFromXml();
   }
   public boolean getMysqlDB_RecreateEn()
   {
      return mysqlDB_RecreateEn;
   }
   public void setMysqlDB_RecreateEn(boolean en)
   {
      mysqlDB_RecreateEn = en;
   }
   public String getMysqlServerIp()
   {
      return mysqlServerIp;
   }
   public String getSourceSQLServerIp()
   {
      return sourceSQLServerIp;
   }
   public String getSourceSQLServerUsrName()
   {
      return sourceSQLServerUsrName;
   }
   public String getSourceSQLServerPWD()
   {
      return sourceSQLServerPWD;
   }
   public int getSourceSQLServerPort()
   {
      return sourceSQLServerPort;
   }
   public String getCInterfaceServerIp()
   {
      return cInterfaceServerIp;
   }
   public String getCInterfaceUsrName()
   {
      return cInterfaceUsrName;
   }
   public String getCInterfacePWD()
   {
      return cInterfacePWD;
   }
   public int getCInterfacePort()
   {
      return cInterfaceSocketPort;
   }
   public String getFbsDeviceBaseIp()
   {
      return fbsDeviceBaseIp;
   }
   public int getSourceSQLServerType()
   {
      return sourceSQLServerType;
   }
   public int getSourceBattDataType()
   {
      return sourceBattDataType;
   }
   public boolean getSybSrvCurrChargeDirPos()
   {
      return sybSrvCurrChargeDirPos;
   }
   public int getMysqlConnCountMax()
   {
      return mysqlConnCountMax;
   }
   public int getWorkThreadCountMax()
   {
      return workThreadCountMax;
   }
   public boolean getBattAlarmFnEn()
   {
      return battAlarmFnEn;
   }
   public int getBattAlarmFnStartDelay()
   {
      return battAlarmFnStartDelay;
   }
   public int getBattAlarmClearedDelay()
   {
      return battAlarmClearedDelay;
   }
   public int getBattAlarmDataDayCountMax()
   {
      return battAlarmDataDayCountMax;
   }
   public boolean getBattResStoreFnEn()
   {
      return battResStoreFnEn;
   }
   public int getBattResStoreDelayForTestManual()
   {
      return battResStoreDelayForTestManual;
   }
   public int getBattResStoreDayInterval()
   {
      return battResStoreDayInterval;
   }
   public boolean getBattAutoStoreFnEn()
   {
      return battAutoStoreFnEn;
   }
   public int getBattAutoStoreDelayForStartUp()
   {
      return battAutoStoreDelayForStartUp;
   }
   public int getBattAutoStoreMinuteInterval()
   {
      return battAutoStoreMinuteInterval;
   }
   public int getBattAutoStoreDayCountMax()
   {
      return battAutoStoreDayCountMax;
   }
   public boolean getUserTaskFnEn()
   {
      return userTaskFnEn;
   }
   public boolean getUserTaskSmsFnEn()
   {
      return userTaskSmsFnEn;
   }
   public String getUserTaskSmsDevIp()
   {
      return userTaskSmsDevIp;
   }
   public boolean getIdce8200ServerFnEn()
   {
      return idce8200ServerFnEn;
   }
   public boolean getMobileServerFnEn()
   {
      return mobileServerFnEn;
   }
   public boolean getFtpServerFnEn()
   {
      return ftpServerFnEn;
   }
   public int getAutoSqlDbBackUpDayInterval() {
      return autoSqlDbBackUpDayInterval;
   }
   public boolean getBpm7100CommErrDataClearEN() {
      return bpm7100CommErrDataClearEN;
   }
   public int getFbsDevCommRate() {
      return fbsDevCommRate;
   }
   public boolean getBTS_CommEn() {
      return DevBTS_SeverComm_En;
   }
   public boolean getFbs9100_ServerCommEn() {
      return DevFBS9100_SeverComm_En;
   }
   public boolean getFbs9100_ClientCommEn() {
      return DevFBS9100_ClientComm_En;
   }
   public void writeConfigToXml()
   {
      try {
            Document document = DocumentHelper.createDocument();
            Element root = document.addElement("root");
            //root.addComment("这个一个注释");
            Element param;
            Element sub_param;
            //-------------------------------------------------------//
            param = root.addElement("mysql_ramdb_recreate_en");
            param.addText(String.valueOf(mysqlDB_RecreateEn));
            //-------------------------------------------------------//
            param = root.addElement("mysql_server_ip");
            param.addText(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(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");
            sub_param = param.addElement("source_sqlserver_type");
            sub_param.addText(String.valueOf(sourceSQLServerType));
            sub_param = param.addElement("source_sqlserver_ip");
            sub_param.addText(sourceSQLServerIp);
            sub_param = param.addElement("source_sqlserver_usrname");
            sub_param.addText(sourceSQLServerUsrName);
            sub_param = param.addElement("source_sqlserver_pwd");
            sub_param.addText(sourceSQLServerPWD);
            sub_param = param.addElement("source_sqlserver_port");
            sub_param.addText(String.valueOf(sourceSQLServerPort));
            //-------------------------------------------------------//
            //--------------------------------------------------------//
            param = root.addElement("c_interface_server_config");
            sub_param = param.addElement("c_interface_server_ip");
            sub_param.addText(cInterfaceServerIp);
            sub_param = param.addElement("c_interface_usrname");
            sub_param.addText(cInterfaceUsrName);
            sub_param = param.addElement("c_interface_pwd");
            sub_param.addText(cInterfacePWD);
            sub_param = param.addElement("c_interface_sokcet_port");
            sub_param.addText(String.valueOf(cInterfaceSocketPort));
            //--------------------------------------------------------//
            //--------------------------------------------------------//
            param = root.addElement("fbs_device_base_ip");
            param.addText(fbsDeviceBaseIp);
            //--------------------------------------------------------//
            param = root.addElement("syb_srv_curr_charge_dir_pos");
            param.addText(String.valueOf(sybSrvCurrChargeDirPos));
            param = root.addElement("mysql_conn_count_max");
            param.addText(String.valueOf(mysqlConnCountMax));
            param = root.addElement("work_thread_count_max");
            param.addText(String.valueOf(workThreadCountMax));
            //--------------------------------------------------------//
            param = root.addElement("batt_alarm_fn_config");
           sub_param = param.addElement("batt_alarm_fn_en");
           sub_param.addText(String.valueOf(battAlarmFnEn));
           sub_param = param.addElement("batt_alarm_fn_start_delay");
           sub_param.addText(String.valueOf(battAlarmFnStartDelay));
           sub_param = param.addElement("batt_alarm_cleared_delay");
           sub_param.addText(String.valueOf(battAlarmClearedDelay));
           sub_param = param.addElement("batt_alarm_data_daycount_max");
           sub_param.addText(String.valueOf(battAlarmDataDayCountMax));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("batt_res_store_fn_config");
           sub_param = param.addElement("batt_res_store_fn_en");
           sub_param.addText(String.valueOf(battResStoreFnEn));
           sub_param = param.addElement("batt_res_store_delay_for_test_manual");
           sub_param.addText(String.valueOf(battResStoreDelayForTestManual));
           sub_param = param.addElement("batt_res_store_day_interval");
           sub_param.addText(String.valueOf(battResStoreDayInterval));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("batt_auto_store_fn_config");
           sub_param = param.addElement("batt_auto_store_fn_en");
           sub_param.addText(String.valueOf(battAutoStoreFnEn));
           sub_param = param.addElement("batt_auto_store_delay_for_start_up");
           sub_param.addText(String.valueOf(battAutoStoreDelayForStartUp));
           sub_param = param.addElement("batt_auto_store_minute_interval");
           sub_param.addText(String.valueOf(battAutoStoreMinuteInterval));
           sub_param = param.addElement("batt_auto_store_day_count_max");
           sub_param.addText(String.valueOf(battAutoStoreDayCountMax));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("user_task_fn_config");
           sub_param = param.addElement("user_task_fn_en");
           sub_param.addText(String.valueOf(userTaskFnEn));
           sub_param = param.addElement("user_task_sms_fn_en");
           sub_param.addText(String.valueOf(userTaskSmsFnEn));
           sub_param = param.addElement("user_task_sms_dev_ip");
           sub_param.addText(userTaskSmsDevIp);
           //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("idce8200_server_fn_config");
           param.addText(String.valueOf(idce8200ServerFnEn));
           param = root.addElement("mobile_server_fn_config");
           param.addText(String.valueOf(mobileServerFnEn));
           param = root.addElement("ftp_server_fn_config");
           param.addText(String.valueOf(ftpServerFnEn));
           //--------------------------------------------------------//
           //-------------------------------------------------------//
            param = root.addElement("auto_sqldb_backup_dayinterval");
            param.addText(String.valueOf(autoSqlDbBackUpDayInterval));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("bpm7100_commerr_dataclear_en");
            param.addText(String.valueOf(bpm7100CommErrDataClearEN));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("fbsdev_comm_rate");
            param.addText(String.valueOf(fbsDevCommRate));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("dev_bts_severcomm_en");
            param.addText(String.valueOf(DevBTS_SeverComm_En));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("devfbs9100_severcomm_en");
            param.addText(String.valueOf(DevFBS9100_SeverComm_En));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("devfbs9100_clientcomm_en");
            param.addText(String.valueOf(DevFBS9100_ClientComm_En));
            //-------------------------------------------------------//
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("gbk");
            XMLWriter writer2 = new XMLWriter(new FileWriter(ConfigFileName), 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(ConfigFileName));
          Element rootnode = document.getRootElement();
          Element node;
          Element sub_node;
          //------------------------------------------------------------//
          node = rootnode.element("mysql_ramdb_recreate_en");
          mysqlDB_RecreateEn = Boolean.parseBoolean(node.getTextTrim());
          //------------------------------------------------------------//
          node = rootnode.element("mysql_server_ip");
          mysqlServerIp = node.getTextTrim();
          //------------------------------------------------------------//
          node = rootnode.element("source_battdata_type");
          sourceBattDataType = Integer.parseInt(node.getTextTrim());
          if(sourceBattDataType < 0)
             sourceBattDataType = 0;
          if(sourceBattDataType > 3)
             sourceBattDataType = 3;
          //------------------------------------------------------------//
          node = rootnode.element("source_sqlserver_config");
          sub_node = node.element("source_sqlserver_type");
          sourceSQLServerType = Integer.parseInt(sub_node.getTextTrim());
          sub_node = node.element("source_sqlserver_ip");
          sourceSQLServerIp = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_usrname");
          sourceSQLServerUsrName = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_pwd");
          sourceSQLServerPWD = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_port");
          sourceSQLServerPort = Integer.parseInt(sub_node.getTextTrim());
          //------------------------------------------------------------//
          //------------------------------------------------------------//
          node = rootnode.element("c_interface_server_config");
          sub_node = node.element("c_interface_server_ip");
          cInterfaceServerIp = sub_node.getTextTrim();
          sub_node = node.element("c_interface_usrname");
          cInterfaceUsrName = sub_node.getTextTrim();
          sub_node = node.element("c_interface_pwd");
          cInterfacePWD = sub_node.getTextTrim();
          sub_node = node.element("c_interface_sokcet_port");
          cInterfaceSocketPort = Integer.parseInt(sub_node.getTextTrim());
            //------------------------------------------------------------//
          //------------------------------------------------------------//
          node = rootnode.element("fbs_device_base_ip");
          fbsDeviceBaseIp = node.getTextTrim();
          //------------------------------------------------------------//
          node = rootnode.element("syb_srv_curr_charge_dir_pos");
          sybSrvCurrChargeDirPos = Boolean.parseBoolean(node.getTextTrim());
          node = rootnode.element("mysql_conn_count_max");
          mysqlConnCountMax = Integer.parseInt(node.getTextTrim());
          if(mysqlConnCountMax < 5)
             mysqlConnCountMax = 5;
          if(mysqlConnCountMax > 400)
             mysqlConnCountMax = 400;
          node = rootnode.element("work_thread_count_max");
          workThreadCountMax = Integer.parseInt(node.getTextTrim());
          if(workThreadCountMax < 10)
             workThreadCountMax = 10;
          if(workThreadCountMax > 400)
             workThreadCountMax = 400;
          //-------------------------------------------------------//
          node = rootnode.element("batt_alarm_fn_config");
            sub_node = node.element("batt_alarm_fn_en");
            battAlarmFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_alarm_fn_start_delay");
            battAlarmFnStartDelay = Integer.parseInt(sub_node.getTextTrim());
            if(battAlarmFnStartDelay < 0)
               battAlarmFnStartDelay = 0;
            if(battAlarmFnStartDelay > 3600)
               battAlarmFnStartDelay = 3600;
            sub_node = node.element("batt_alarm_cleared_delay");
            battAlarmClearedDelay = Integer.parseInt(sub_node.getTextTrim());
            if(battAlarmClearedDelay < 0)
               battAlarmClearedDelay = 0;
            if(battAlarmClearedDelay > 3600)
               battAlarmClearedDelay = 3600;
            sub_node = node.element("batt_alarm_data_daycount_max");
            battAlarmDataDayCountMax = Integer.parseInt(sub_node.getTextTrim());
            if(battAlarmDataDayCountMax < 7)
               battAlarmDataDayCountMax = 7;
            if(battAlarmDataDayCountMax > 2048)
               battAlarmDataDayCountMax = 2048;
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            node = rootnode.element("batt_res_store_fn_config");
            sub_node = node.element("batt_res_store_fn_en");
            battResStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_res_store_delay_for_test_manual");
            battResStoreDelayForTestManual = Integer.parseInt(sub_node.getTextTrim());
            if(battResStoreDelayForTestManual < 180)
               battResStoreDelayForTestManual = 180;
            if(battResStoreDelayForTestManual > 1800)
               battResStoreDelayForTestManual = 1800;
            sub_node = node.element("batt_res_store_day_interval");
            battResStoreDayInterval = Integer.parseInt(sub_node.getTextTrim());
            if(battResStoreDayInterval < 1)
               battResStoreDayInterval = 1;
            if(battResStoreDayInterval > 360)
               battResStoreDayInterval = 360;
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            node = rootnode.element("batt_auto_store_fn_config");
            sub_node = node.element("batt_auto_store_fn_en");
            battAutoStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_auto_store_delay_for_start_up");
            battAutoStoreDelayForStartUp = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreDelayForStartUp < 180)
               battAutoStoreDelayForStartUp = 180;
            if(battAutoStoreDelayForStartUp > 3600)
               battAutoStoreDelayForStartUp = 3600;
            sub_node = node.element("batt_auto_store_minute_interval");
            battAutoStoreMinuteInterval = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreMinuteInterval < 10)
               battAutoStoreMinuteInterval = 10;
            if(battAutoStoreMinuteInterval > ((60*24)*30))
               battAutoStoreMinuteInterval = ((60*24)*30);
            sub_node = node.element("batt_auto_store_day_count_max");
            battAutoStoreDayCountMax = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreDayCountMax < 1)
               battAutoStoreDayCountMax = 1;
            if(battAutoStoreDayCountMax > 300)
               battAutoStoreDayCountMax = 300;
            //-------------------------------------------------------//
            //--------------------------------------------------------//
            node = rootnode.element("user_task_fn_config");
            sub_node = node.element("user_task_fn_en");
            userTaskFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("user_task_sms_fn_en");
            userTaskSmsFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("user_task_sms_dev_ip");
            userTaskSmsDevIp = sub_node.getTextTrim();
           //--------------------------------------------------------//
            //--------------------------------------------------------//
            node = rootnode.element("idce8200_server_fn_config");
            idce8200ServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            node = rootnode.element("mobile_server_fn_config");
            mobileServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            node = rootnode.element("ftp_server_fn_config");
            ftpServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            //--------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("auto_sqldb_backup_dayinterval");
          autoSqlDbBackUpDayInterval = Integer.parseInt(node.getTextTrim());
          if(autoSqlDbBackUpDayInterval < 7) {
             autoSqlDbBackUpDayInterval = 7;
          }
          if(autoSqlDbBackUpDayInterval > 365) {
             autoSqlDbBackUpDayInterval = 365;
          }
            //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("bpm7100_commerr_dataclear_en");
          bpm7100CommErrDataClearEN = Boolean.parseBoolean(node.getTextTrim());
          //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("fbsdev_comm_rate");
          fbsDevCommRate = Integer.parseInt(node.getTextTrim());
          //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("dev_bts_severcomm_en");
          DevBTS_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("devfbs9100_severcomm_en");
          DevFBS9100_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("devfbs9100_clientcomm_en");
          DevFBS9100_ClientComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
       } catch (NullPointerException | NumberFormatException | DocumentException e) {
         res = false;
         e.printStackTrace();
      } finally {
         if(false == res)
            writeConfigToXml();
      }
   }
}
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;
/**
 * 创建config.xml文件并更新  config.xml 文件中的属性值
 * @author 军
 *
 */
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 boolean mysqlDB_RecreateEn = false;
   private String mysqlServerIp = "127.0.0.1";
   private int sourceBattDataType = 0;
   //----------------------------------------------------------------//
   private int sourceSQLServerType = 0;
   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 = System.getProperty("user.dir");
      if(path.contains("\\"))
         path += "\\";
      else path += "/";
      */
      String path = ConfigFileName;
      //System.out.println(path);
      File f = new File(path);
      if(false == f.exists())
      {
         writeConfigToXml();
      }
      readConfigFromXml();
   }
   public boolean getMysqlDB_RecreateEn()
   {
      return mysqlDB_RecreateEn;
   }
   public void setMysqlDB_RecreateEn(boolean en)
   {
      mysqlDB_RecreateEn = en;
   }
   public String getMysqlServerIp()
   {
      return mysqlServerIp;
   }
   public String getSourceSQLServerIp()
   {
      return sourceSQLServerIp;
   }
   public String getSourceSQLServerUsrName()
   {
      return sourceSQLServerUsrName;
   }
   public String getSourceSQLServerPWD()
   {
      return sourceSQLServerPWD;
   }
   public int getSourceSQLServerPort()
   {
      return sourceSQLServerPort;
   }
   public String getCInterfaceServerIp()
   {
      return cInterfaceServerIp;
   }
   public String getCInterfaceUsrName()
   {
      return cInterfaceUsrName;
   }
   public String getCInterfacePWD()
   {
      return cInterfacePWD;
   }
   public int getCInterfacePort()
   {
      return cInterfaceSocketPort;
   }
   public String getFbsDeviceBaseIp()
   {
      return fbsDeviceBaseIp;
   }
   public int getSourceSQLServerType()
   {
      return sourceSQLServerType;
   }
   public int getSourceBattDataType()
   {
      return sourceBattDataType;
   }
   public boolean getSybSrvCurrChargeDirPos()
   {
      return sybSrvCurrChargeDirPos;
   }
   public int getMysqlConnCountMax()
   {
      return mysqlConnCountMax;
   }
   public int getWorkThreadCountMax()
   {
      return workThreadCountMax;
   }
   public boolean getBattAlarmFnEn()
   {
      return battAlarmFnEn;
   }
   public int getBattAlarmFnStartDelay()
   {
      return battAlarmFnStartDelay;
   }
   public int getBattAlarmClearedDelay()
   {
      return battAlarmClearedDelay;
   }
   public int getBattAlarmDataDayCountMax()
   {
      return battAlarmDataDayCountMax;
   }
   public boolean getBattResStoreFnEn()
   {
      return battResStoreFnEn;
   }
   public int getBattResStoreDelayForTestManual()
   {
      return battResStoreDelayForTestManual;
   }
   public int getBattResStoreDayInterval()
   {
      return battResStoreDayInterval;
   }
   public boolean getBattAutoStoreFnEn()
   {
      return battAutoStoreFnEn;
   }
   public int getBattAutoStoreDelayForStartUp()
   {
      return battAutoStoreDelayForStartUp;
   }
   public int getBattAutoStoreMinuteInterval()
   {
      return battAutoStoreMinuteInterval;
   }
   public int getBattAutoStoreDayCountMax()
   {
      return battAutoStoreDayCountMax;
   }
   public boolean getUserTaskFnEn()
   {
      return userTaskFnEn;
   }
   public boolean getUserTaskSmsFnEn()
   {
      return userTaskSmsFnEn;
   }
   public String getUserTaskSmsDevIp()
   {
      return userTaskSmsDevIp;
   }
   public boolean getIdce8200ServerFnEn()
   {
      return idce8200ServerFnEn;
   }
   public boolean getMobileServerFnEn()
   {
      return mobileServerFnEn;
   }
   public boolean getFtpServerFnEn()
   {
      return ftpServerFnEn;
   }
   public int getAutoSqlDbBackUpDayInterval() {
      return autoSqlDbBackUpDayInterval;
   }
   public boolean getBpm7100CommErrDataClearEN() {
      return bpm7100CommErrDataClearEN;
   }
   public int getFbsDevCommRate() {
      return fbsDevCommRate;
   }
   public boolean getBTS_CommEn() {
      return DevBTS_SeverComm_En;
   }
   public boolean getFbs9100_ServerCommEn() {
      return DevFBS9100_SeverComm_En;
   }
   public boolean getFbs9100_ClientCommEn() {
      return DevFBS9100_ClientComm_En;
   }
   public void writeConfigToXml()
   {
      try {
            Document document = DocumentHelper.createDocument();
            Element root = document.addElement("root");
            //root.addComment("这个一个注释");
            Element param;
            Element sub_param;
            //-------------------------------------------------------//
            param = root.addElement("mysql_ramdb_recreate_en");
            param.addText(String.valueOf(mysqlDB_RecreateEn));
            //-------------------------------------------------------//
            param = root.addElement("mysql_server_ip");
            param.addText(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(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");
            sub_param = param.addElement("source_sqlserver_type");
            sub_param.addText(String.valueOf(sourceSQLServerType));
            sub_param = param.addElement("source_sqlserver_ip");
            sub_param.addText(sourceSQLServerIp);
            sub_param = param.addElement("source_sqlserver_usrname");
            sub_param.addText(sourceSQLServerUsrName);
            sub_param = param.addElement("source_sqlserver_pwd");
            sub_param.addText(sourceSQLServerPWD);
            sub_param = param.addElement("source_sqlserver_port");
            sub_param.addText(String.valueOf(sourceSQLServerPort));
            //-------------------------------------------------------//
            //--------------------------------------------------------//
            param = root.addElement("c_interface_server_config");
            sub_param = param.addElement("c_interface_server_ip");
            sub_param.addText(cInterfaceServerIp);
            sub_param = param.addElement("c_interface_usrname");
            sub_param.addText(cInterfaceUsrName);
            sub_param = param.addElement("c_interface_pwd");
            sub_param.addText(cInterfacePWD);
            sub_param = param.addElement("c_interface_sokcet_port");
            sub_param.addText(String.valueOf(cInterfaceSocketPort));
            //--------------------------------------------------------//
            //--------------------------------------------------------//
            param = root.addElement("fbs_device_base_ip");
            param.addText(fbsDeviceBaseIp);
            //--------------------------------------------------------//
            param = root.addElement("syb_srv_curr_charge_dir_pos");
            param.addText(String.valueOf(sybSrvCurrChargeDirPos));
            param = root.addElement("mysql_conn_count_max");
            param.addText(String.valueOf(mysqlConnCountMax));
            param = root.addElement("work_thread_count_max");
            param.addText(String.valueOf(workThreadCountMax));
            //--------------------------------------------------------//
            param = root.addElement("batt_alarm_fn_config");
           sub_param = param.addElement("batt_alarm_fn_en");
           sub_param.addText(String.valueOf(battAlarmFnEn));
           sub_param = param.addElement("batt_alarm_fn_start_delay");
           sub_param.addText(String.valueOf(battAlarmFnStartDelay));
           sub_param = param.addElement("batt_alarm_cleared_delay");
           sub_param.addText(String.valueOf(battAlarmClearedDelay));
           sub_param = param.addElement("batt_alarm_data_daycount_max");
           sub_param.addText(String.valueOf(battAlarmDataDayCountMax));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("batt_res_store_fn_config");
           sub_param = param.addElement("batt_res_store_fn_en");
           sub_param.addText(String.valueOf(battResStoreFnEn));
           sub_param = param.addElement("batt_res_store_delay_for_test_manual");
           sub_param.addText(String.valueOf(battResStoreDelayForTestManual));
           sub_param = param.addElement("batt_res_store_day_interval");
           sub_param.addText(String.valueOf(battResStoreDayInterval));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("batt_auto_store_fn_config");
           sub_param = param.addElement("batt_auto_store_fn_en");
           sub_param.addText(String.valueOf(battAutoStoreFnEn));
           sub_param = param.addElement("batt_auto_store_delay_for_start_up");
           sub_param.addText(String.valueOf(battAutoStoreDelayForStartUp));
           sub_param = param.addElement("batt_auto_store_minute_interval");
           sub_param.addText(String.valueOf(battAutoStoreMinuteInterval));
           sub_param = param.addElement("batt_auto_store_day_count_max");
           sub_param.addText(String.valueOf(battAutoStoreDayCountMax));
            //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("user_task_fn_config");
           sub_param = param.addElement("user_task_fn_en");
           sub_param.addText(String.valueOf(userTaskFnEn));
           sub_param = param.addElement("user_task_sms_fn_en");
           sub_param.addText(String.valueOf(userTaskSmsFnEn));
           sub_param = param.addElement("user_task_sms_dev_ip");
           sub_param.addText(userTaskSmsDevIp);
           //--------------------------------------------------------//
           //--------------------------------------------------------//
           param = root.addElement("idce8200_server_fn_config");
           param.addText(String.valueOf(idce8200ServerFnEn));
           param = root.addElement("mobile_server_fn_config");
           param.addText(String.valueOf(mobileServerFnEn));
           param = root.addElement("ftp_server_fn_config");
           param.addText(String.valueOf(ftpServerFnEn));
           //--------------------------------------------------------//
           //-------------------------------------------------------//
            param = root.addElement("auto_sqldb_backup_dayinterval");
            param.addText(String.valueOf(autoSqlDbBackUpDayInterval));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("bpm7100_commerr_dataclear_en");
            param.addText(String.valueOf(bpm7100CommErrDataClearEN));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("fbsdev_comm_rate");
            param.addText(String.valueOf(fbsDevCommRate));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("dev_bts_severcomm_en");
            param.addText(String.valueOf(DevBTS_SeverComm_En));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("devfbs9100_severcomm_en");
            param.addText(String.valueOf(DevFBS9100_SeverComm_En));
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            param = root.addElement("devfbs9100_clientcomm_en");
            param.addText(String.valueOf(DevFBS9100_ClientComm_En));
            //-------------------------------------------------------//
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("gbk");
            XMLWriter writer2 = new XMLWriter(new FileWriter(ConfigFileName), 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(ConfigFileName));
          Element rootnode = document.getRootElement();
          Element node;
          Element sub_node;
          //------------------------------------------------------------//
          node = rootnode.element("mysql_ramdb_recreate_en");
          mysqlDB_RecreateEn = Boolean.parseBoolean(node.getTextTrim());
          //------------------------------------------------------------//
          node = rootnode.element("mysql_server_ip");
          mysqlServerIp = node.getTextTrim();
          //------------------------------------------------------------//
          node = rootnode.element("source_battdata_type");
          sourceBattDataType = Integer.parseInt(node.getTextTrim());
          if(sourceBattDataType < 0)
             sourceBattDataType = 0;
          if(sourceBattDataType > 3)
             sourceBattDataType = 3;
          //------------------------------------------------------------//
          node = rootnode.element("source_sqlserver_config");
          sub_node = node.element("source_sqlserver_type");
          sourceSQLServerType = Integer.parseInt(sub_node.getTextTrim());
          sub_node = node.element("source_sqlserver_ip");
          sourceSQLServerIp = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_usrname");
          sourceSQLServerUsrName = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_pwd");
          sourceSQLServerPWD = sub_node.getTextTrim();
          sub_node = node.element("source_sqlserver_port");
          sourceSQLServerPort = Integer.parseInt(sub_node.getTextTrim());
          //------------------------------------------------------------//
          //------------------------------------------------------------//
          node = rootnode.element("c_interface_server_config");
          sub_node = node.element("c_interface_server_ip");
          cInterfaceServerIp = sub_node.getTextTrim();
          sub_node = node.element("c_interface_usrname");
          cInterfaceUsrName = sub_node.getTextTrim();
          sub_node = node.element("c_interface_pwd");
          cInterfacePWD = sub_node.getTextTrim();
          sub_node = node.element("c_interface_sokcet_port");
          cInterfaceSocketPort = Integer.parseInt(sub_node.getTextTrim());
            //------------------------------------------------------------//
          //------------------------------------------------------------//
          node = rootnode.element("fbs_device_base_ip");
          fbsDeviceBaseIp = node.getTextTrim();
          //------------------------------------------------------------//
          node = rootnode.element("syb_srv_curr_charge_dir_pos");
          sybSrvCurrChargeDirPos = Boolean.parseBoolean(node.getTextTrim());
          node = rootnode.element("mysql_conn_count_max");
          mysqlConnCountMax = Integer.parseInt(node.getTextTrim());
          if(mysqlConnCountMax < 5)
             mysqlConnCountMax = 5;
          if(mysqlConnCountMax > 400)
             mysqlConnCountMax = 400;
          node = rootnode.element("work_thread_count_max");
          workThreadCountMax = Integer.parseInt(node.getTextTrim());
/*          if(workThreadCountMax < 10)
             workThreadCountMax = 10;
          if(workThreadCountMax > 400)
             workThreadCountMax = 400;*/
          //-------------------------------------------------------//
          node = rootnode.element("batt_alarm_fn_config");
            sub_node = node.element("batt_alarm_fn_en");
            battAlarmFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_alarm_fn_start_delay");
            battAlarmFnStartDelay = Integer.parseInt(sub_node.getTextTrim());
            if(battAlarmFnStartDelay < 0)
               battAlarmFnStartDelay = 0;
            if(battAlarmFnStartDelay > 3600)
               battAlarmFnStartDelay = 3600;
            sub_node = node.element("batt_alarm_cleared_delay");
            battAlarmClearedDelay = Integer.parseInt(sub_node.getTextTrim());
            if(battAlarmClearedDelay < 0)
               battAlarmClearedDelay = 0;
            if(battAlarmClearedDelay > 3600)
               battAlarmClearedDelay = 3600;
            sub_node = node.element("batt_alarm_data_daycount_max");
            battAlarmDataDayCountMax = Integer.parseInt(sub_node.getTextTrim());
//            if(battAlarmDataDayCountMax < 7)
//               battAlarmDataDayCountMax = 7;
//            if(battAlarmDataDayCountMax > 2048)
//               battAlarmDataDayCountMax = 2048;
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            node = rootnode.element("batt_res_store_fn_config");
            sub_node = node.element("batt_res_store_fn_en");
            battResStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_res_store_delay_for_test_manual");
            battResStoreDelayForTestManual = Integer.parseInt(sub_node.getTextTrim());
            if(battResStoreDelayForTestManual < 180)
               battResStoreDelayForTestManual = 180;
            if(battResStoreDelayForTestManual > 1800)
               battResStoreDelayForTestManual = 1800;
            sub_node = node.element("batt_res_store_day_interval");
            battResStoreDayInterval = Integer.parseInt(sub_node.getTextTrim());
            if(battResStoreDayInterval < 1)
               battResStoreDayInterval = 1;
            if(battResStoreDayInterval > 360)
               battResStoreDayInterval = 360;
            //-------------------------------------------------------//
            //-------------------------------------------------------//
            node = rootnode.element("batt_auto_store_fn_config");
            sub_node = node.element("batt_auto_store_fn_en");
            battAutoStoreFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("batt_auto_store_delay_for_start_up");
            battAutoStoreDelayForStartUp = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreDelayForStartUp < 180)
               battAutoStoreDelayForStartUp = 180;
            if(battAutoStoreDelayForStartUp > 3600)
               battAutoStoreDelayForStartUp = 3600;
            sub_node = node.element("batt_auto_store_minute_interval");
            battAutoStoreMinuteInterval = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreMinuteInterval < 10)
               battAutoStoreMinuteInterval = 10;
            if(battAutoStoreMinuteInterval > ((60*24)*30))
               battAutoStoreMinuteInterval = ((60*24)*30);
            sub_node = node.element("batt_auto_store_day_count_max");
            battAutoStoreDayCountMax = Integer.parseInt(sub_node.getTextTrim());
            if(battAutoStoreDayCountMax < 1)
               battAutoStoreDayCountMax = 1;
            if(battAutoStoreDayCountMax > 300)
               battAutoStoreDayCountMax = 300;
            //-------------------------------------------------------//
            //--------------------------------------------------------//
            node = rootnode.element("user_task_fn_config");
            sub_node = node.element("user_task_fn_en");
            userTaskFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("user_task_sms_fn_en");
            userTaskSmsFnEn = Boolean.parseBoolean(sub_node.getTextTrim());
            sub_node = node.element("user_task_sms_dev_ip");
            userTaskSmsDevIp = sub_node.getTextTrim();
           //--------------------------------------------------------//
            //--------------------------------------------------------//
            node = rootnode.element("idce8200_server_fn_config");
            idce8200ServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            node = rootnode.element("mobile_server_fn_config");
            mobileServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            node = rootnode.element("ftp_server_fn_config");
            ftpServerFnEn = Boolean.parseBoolean(node.getTextTrim());
            //--------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("auto_sqldb_backup_dayinterval");
          autoSqlDbBackUpDayInterval = Integer.parseInt(node.getTextTrim());
          if(autoSqlDbBackUpDayInterval < 7) {
             autoSqlDbBackUpDayInterval = 7;
          }
          if(autoSqlDbBackUpDayInterval > 365) {
             autoSqlDbBackUpDayInterval = 365;
          }
            //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("bpm7100_commerr_dataclear_en");
          bpm7100CommErrDataClearEN = Boolean.parseBoolean(node.getTextTrim());
          //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("fbsdev_comm_rate");
          fbsDevCommRate = Integer.parseInt(node.getTextTrim());
          //-------------------------------------------------------//
          //-------------------------------------------------------//
          node = rootnode.element("dev_bts_severcomm_en");
          DevBTS_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("devfbs9100_severcomm_en");
          DevFBS9100_SeverComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
            //-------------------------------------------------------//
          node = rootnode.element("devfbs9100_clientcomm_en");
          DevFBS9100_ClientComm_En = Boolean.parseBoolean(node.getTextTrim());
            //-------------------------------------------------------//
       } catch (NullPointerException | NumberFormatException | DocumentException e) {
         res = false;
         e.printStackTrace();
      } finally {
         if(false == res)
            writeConfigToXml();
      }
   }
}