充放电一体机FGCD通信程序【二期初版】
BattMonitor_FGCD-A059NT/src/com/batttest/BattResStorePro_Thread.java
@@ -203,6 +203,175 @@
         sql.close_con();
      }
   }
   /**
    *
    *    @lijun  2021-08-18 重写记录单体内阻数据方法,为记录放电数据时记录当前单体的内阻数据
    *
    *    创建及添加数据到tb_battresdata_id表;添加数据,以及更新tb_battresdata_inf数据表,并且向表中添加数据
    * @param conn_pool
    * @param data_rt
    * @param test_type
    */
   public static void insertMonDataToResTable(MysqlConnPool conn_pool, BattData_RT data_rt,Date test_starttime, int test_type)
   {
      int mon_count = data_rt.MonCount;
      if(mon_count < 1)
         return;
      Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
      String sql_str = null;
      try {
         sql.sqlMysqlUseDB(Sql_Mysql.DB_BATT_TESTDATA);
         boolean result = true;
         Date rc_time = test_starttime;
         String tb_name = "tb_BattResData_" + data_rt.BattGroupId;
         if(false == sql.sqlMysqlCheckIfTableExist(tb_name))
         {
            sql_str = "CREATE TABLE IF NOT EXISTS " + tb_name + " "
                  + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                  + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                  + "`test_record_count` INT NOT NULL DEFAULT 0, "
                  + "`test_type` INT NOT NULL DEFAULT 0, "
                  + "`data_new` BOOLEAN NOT NULL DEFAULT false, "
                  + "`data_available` BOOLEAN NOT NULL DEFAULT false, "
                  + "`test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                  + "`group_vol` FLOAT NOT NULL DEFAULT 0, "
                  + "`test_curr` FLOAT NOT NULL DEFAULT 0, "
                  + "`mon_num` INT NOT NULL DEFAULT 0, "
                  + "`mon_vol` FLOAT NOT NULL DEFAULT 0, "
                  + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, "
                  + "`mon_res` FLOAT NOT NULL DEFAULT 0, "
                  + "`mon_ser` FLOAT NOT NULL DEFAULT 0, "
                  + "`conn_res` FLOAT NOT NULL DEFAULT 0, "
                  + "INDEX index_test_record_count (`test_record_count`), "
                  + "PRIMARY KEY (`num`));";
            //System.out.println(sql_str);
            sql.sqlMysqlExecute(sql_str);
         }
         int mtest_record_count = 0;//sql.getBattTestRecordCountNew(data_rt.BattGroupId, Sql_Mysql.BattResDataInf_Table);
         for(int c=0; c<3; c++)
         {
            try {
               sql_str = "INSERT INTO " + tb_name + " "
                     + " (BattGroupId, "
                     + "test_record_count, "
                     + "test_type, "
                     + "data_new, "
                     + "data_available, "
                     + "test_starttime, "
                     + "group_vol, "
                     + "test_curr, "
                     + "mon_num, "
                     + "mon_vol,"
                     + "mon_tmp,"
                     + "mon_res,"
                     + "mon_ser,"
                     + "conn_res)"
                     + " VALUES ";
               try {
                  for(int n=0; n<mon_count; n++) {
                     String tmp_sql_str = "("
                              + data_rt.BattGroupId + ", "
                              + mtest_record_count + ", "
                              + test_type + ", "
                              + true + ", "
                              + true + ", "
                              + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                              + data_rt.mTestData.groupVol + ", "
                              + data_rt.mTestData.testCurr + ", "
                              + ((n+1)*10 + 1) + ", "
                              + data_rt.al_MonVol.get(n).monVol + ","
                              + data_rt.al_MonVol.get(n).monTmp + ","
                              + data_rt.al_MonVol.get(n).monRes + ","
                              + data_rt.al_MonVol.get(n).monSer + ","
                              + data_rt.al_MonVol.get(n).connRes
                              + ")";
                     if(n > 0) {
                        sql_str += ", ";
                     }
                     sql_str += tmp_sql_str;
                  }
               } catch (Exception e) {
                  sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
               }
               String sql_str2 = "INSERT INTO " + Sql_Mysql.BattResDataInf_Table
                        + " (BattGroupId, "
                        + "test_record_count, "
                        + "test_type, "
                        + "data_new, "
                        + "data_available, "
                        + "test_starttime, "
                        + "test_devtype, "
                        + "record_time, "
                        + "group_vol, "
                        + "test_curr, "
                        + "upload_usr_id) "
                        + " VALUES "
                        + "("+ data_rt.BattGroupId + ", "
                        + mtest_record_count + ", "
                        + test_type + ", "
                        + true + ", "
                        + true + ", "
                        + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                        + 0 + ", "
                        + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                        + 0 + ", "
                        + 0 + ", "
                        + 0 + ") ";
               if(1 == mtest_record_count) {
                  sql_str2 = "UPDATE " + Sql_Mysql.BattResDataInf_Table + " SET "
                        + "test_type=" + test_type + ", "
                        + "data_new=" + true + ", "
                        + "data_available=" + true + ", "
                        + "test_starttime='" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                        + "test_devtype=" + 0 + ", "
                        + "record_time='" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                        + "group_vol=" + 0 + ", "
                        + "test_curr=" + 0 + ", "
                        + "upload_usr_id=" + 0 + " "
                        + " WHERE BattGroupId=" + data_rt.BattGroupId
                        + " AND test_record_count=" + mtest_record_count;
               }
               //System.out.println(sql_str);
               //System.out.println(sql_str2);
               sql.mysql_con.setAutoCommit(false);
               sql.sqlMysqlExecute(sql_str);
               sql.sqlMysqlExecute(sql_str2);
               sql.mysql_con.commit();
            } catch (SQLException e) {
               sql.mysql_con.rollback();
               //System.out.println(sql_str);
               sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
               result = false;
            } finally {
               sql.mysql_con.setAutoCommit(true);
               if(true == result)
               {
                  break;
               }
               else
               {
                  try {
                     Thread.sleep(500);
                  } catch (InterruptedException e) {
                     sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
                  }
               }
            }
         }
      } catch (SQLException e) {
         sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
      } finally {
         sql.close_con();
      }
   }
   //-----------------------------------------------------------------------------//
   @Override
    public void run() {