充放电一体机FGCD通信程序【二期初版】
Administrator
2021-08-11 138d0c2a4e42d7c1a03c19536436a59aa37c2ba6
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_SocketClient_Thread_SQL.java
@@ -1053,37 +1053,47 @@
   /***********************************************************************************/
   public static void updateFbs9100StateOnlyByDev_Id(MysqlConnPool con_pool, FGCD_StateAndParam m_pm)
   {
      String sql_str_base = Sql_Mysql.FBS9100State_Table
                  + " SET "
                  + "dev_id=" + m_pm.dev_id + ", "
                  + "dev_ip='" + m_pm.dev_ipaddr + "', "
                  + "dev_version='" + m_pm.m_DevVersion + "', "
                  + "record_datetime="
                  + "'" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',"
                  + "dev_datetime='" + m_pm.sysState.chageDate+ "', "
                  + "dev_testtype=" + m_pm.sysState.btnState+ ", "
                  + "dev_captest_onlinevol=" + m_pm.sysState.on_online_vol+ ", "
                  + "dev_captest_groupvol=" + m_pm.sysState.on_group_vol+ ", "
                  + "batt_online_state=" + m_pm.sysState.diode_state+ ", "
                  + "dev_temp=" + m_pm.sysState.devtmp + ", "
                  + "dev_testgroupnum=" + m_pm.sysState.hhProgress + ", "
                  + "dev_workstate=" + m_pm.sysState.dev_workstate + ", "
                  + "dev_captest_curr=" + m_pm.sysState.chargeCurr + ", "
                  + "dev_last_captest_stop_type=" + m_pm.sysState.dev_captest_stop_type + ", "
                  + "dev_captest_cap=" + m_pm.sysState.testCap + ", "
                  + "dev_data_flowsum=" + m_pm.sysState.dev_data_flowsum+ ", "
                  + "dev_commcount=" + m_pm.sysState.dev_commcount+ ", "
                  + "dev_errcommcount=" + m_pm.sysState.dev_errcommcount;
                  if((m_pm.sysState.dev_captest_stop_type>=0) && (m_pm.sysState.dev_captest_stop_type<50)) {
                     sql_str_base += ", ";
                     sql_str_base += "dev_last_captest_stop_type=" + m_pm.sysState.dev_captest_stop_type;
                  }
      String sql_str_sel = "SELECT dev_res_test_state " +
            " FROM " + Sql_Mysql.FBS9100State_Table +
            " WHERE dev_id = " + m_pm.dev_id;
      
      String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id=" + m_pm.dev_id;
      ResultSet res = null;
      Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
      try {
         //sql.logger.debug(sql_str);
         res = sql.sqlMysqlQuery(sql_str_sel);      //查询当前设备的锁定状态
         if(res.next()) {
            m_pm.sysState.tmp_alm_lock = res.getInt("dev_res_test_state");
         }
         m_pm.sysState.checkTmpAlmState();
         String sql_str_base = Sql_Mysql.FBS9100State_Table
               + " SET "
               + "dev_id=" + m_pm.dev_id + ", "
               + "dev_ip='" + m_pm.dev_ipaddr + "', "
               + "dev_version='" + m_pm.m_DevVersion + "', "
               + "record_datetime="
               + "'" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',"
               + "dev_datetime='" + m_pm.sysState.chageDate+ "', "
               + "dev_testtype=" + m_pm.sysState.btnState+ ", "
               + "dev_captest_onlinevol=" + m_pm.sysState.on_online_vol+ ", "
               + "dev_captest_groupvol=" + m_pm.sysState.on_group_vol+ ", "
               + "batt_online_state=" + m_pm.sysState.diode_state+ ", "
               + "dev_temp=" + m_pm.sysState.devtmp + ", "
               + "dev_res_test_state=" + m_pm.sysState.tmp_alm_lock + ", "
               + "dev_testgroupnum=" + m_pm.sysState.hhProgress + ", "
               + "dev_workstate=" + m_pm.sysState.dev_workstate + ", "
               + "dev_captest_curr=" + m_pm.sysState.chargeCurr + ", "
               + "dev_last_captest_stop_type=" + m_pm.sysState.dev_captest_stop_type + ", "
               + "dev_captest_cap=" + m_pm.sysState.testCap + ", "
               + "dev_data_flowsum=" + m_pm.sysState.dev_data_flowsum+ ", "
               + "dev_commcount=" + m_pm.sysState.dev_commcount+ ", "
               + "dev_errcommcount=" + m_pm.sysState.dev_errcommcount;
               if((m_pm.sysState.dev_captest_stop_type>=0) && (m_pm.sysState.dev_captest_stop_type<50)) {
                  sql_str_base += ", ";
                  sql_str_base += "dev_last_captest_stop_type=" + m_pm.sysState.dev_captest_stop_type;
               }
         String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id=" + m_pm.dev_id;
         sql.sqlMysqlExecute(sql_str_update);
      } catch (SQLException e) {
         sql.logger.error("FGCD_SocketClient_Thread_SQL.updateFbs9100StateOnlyByDev_Id():" + e.toString(), e);
@@ -1626,6 +1636,28 @@
            sql.close_con();
         }         
      }
   }
   /**
    *    插入或更新当前参数
    * @param con_pool
    * @param dev_id
    */
   public static void insertOrUpdateFbs9100SetParamBydev_id(MysqlConnPool con_pool, int dev_id) {
      String sql_str_sel = " Select * from "+Sql_Mysql.FBS9100SetParam_Table+" where dev_id= "+dev_id ;
      String sql_str_ins = " insert into "+Sql_Mysql.FBS9100SetParam_Table+"(dev_id) values("+dev_id+")";
      Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
      ResultSet res = null;
      try {
         res = sql.sqlMysqlQuery(sql_str_sel);
         if(!res.next()) {
            sql.sqlMysqlExecute(sql_str_ins);
         }
      } catch (SQLException e) {
         sql.logger.error("FGCD_SocketClient_Thread_SQL.insertOrUpdateFbs9100SetParamBydev_id():" + e.toString(), e);
      } finally {
         sql.close_con();
      }
   }
   
   /**
@@ -2500,4 +2532,121 @@
         sql.close_con();
      }
   }
   /**
    *    查询系统参数中的清除告警功能
    * @param conn_pool
    * @param param
    * @return
    */
   public static int queryClearAlarmState(MysqlConnPool conn_pool,FGCD_StateAndParam param) {
      int op_cmd = 0;
      String sql_str = " SELECT * " +
            " FROM " + Sql_Mysql.FBS9100SysParam_Table +
            " WHERE dev_id = " + param.dev_id;
      Sql_Mysql sql = null;
      ResultSet res = null;
      try {
         sql = new Sql_Mysql(conn_pool);
         res = sql.sqlMysqlQuery(sql_str);
         if(res.next()) {
            op_cmd = res.getInt("op_cmd");
         }
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         if(null != res) {
            try {
               res.close();
            } catch (SQLException e) {
               e.printStackTrace();
            }
         }
         sql.close_con();
      }
      return op_cmd;
   }
   /**
    *    查询系统参数中的清除告警功能
    * @param conn_pool
    * @param param
    * @return
    */
   public static int updateClearAlarmState(MysqlConnPool conn_pool,FGCD_StateAndParam param,int op_cmd_ack) {
      int op_cmd = 0;
      String sql_str = " update " + Sql_Mysql.FBS9100SysParam_Table +
            " Set op_cmd =  " + op_cmd_ack +
            " WHERE dev_id = " + param.dev_id;
      Sql_Mysql sql = null;
      try {
         sql = new Sql_Mysql(conn_pool);
         sql.sqlMysqlExecute(sql_str);
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         sql.close_con();
      }
      return op_cmd;
   }
   public static void insertFBS9100_SysParamDefaultData(MysqlConnPool conn_pool,FGCD_StateAndParam param) {
      String sql_str_sel = " Select * from "+Sql_Mysql.FBS9100SysParam_Table +" Where dev_id = "+param.dev_id;
      String sql_str_ins = " insert into " + Sql_Mysql.FBS9100SysParam_Table+"(dev_id) values("+param.dev_id+")";
      ResultSet res = null;
      Sql_Mysql sql = null;
      try {
         sql = new Sql_Mysql(conn_pool);
         res = sql.sqlMysqlQuery(sql_str_sel);
         if(!res.next()) {
            sql.sqlMysqlExecute(sql_str_ins);
         }
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         if(null != res) {
            try {
               res.close();
            } catch (SQLException e) {
               e.printStackTrace();
            }
         }
         sql.close_con();
      }
   }
   //更新充放电一体机线程的启动时间和版本好
   public static void updateServerStartInf_StartTime(MysqlConnPool conn_pool,double version){
      Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
      try {
         sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
         String sql_str = "UPDATE tb_process_survey "
               + "SET Process_starttime = '"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"'"
               + ",ProcessTime = '"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"'"
               + ",ProcessVersion = 'V"+version+"'"
               + " WHERE processid = 11018 ";
         //System.out.println(sql_str);
         sql.sqlMysqlExecute(sql_str);
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         sql.close_con();
      }
   }
   //更新电池组负载线程的时间戳
   public static void updateServerStartInf_Time(MysqlConnPool conn_pool){
      Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
      try {
         sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
         String sql_str = "UPDATE tb_process_survey SET ProcessTime = '"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
                  + "' WHERE processid = 11018";
         sql.sqlMysqlExecute(sql_str);
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         sql.close_con();
      }
   }
}