From bec9d52048d24f89ac665aa4b5abb726e212df63 Mon Sep 17 00:00:00 2001
From: Administrator <1525436766@qq.com>
Date: 星期三, 19 十月 2022 09:00:56 +0800
Subject: [PATCH] 应客户需求增加设备模拟单体电压内阻数据修改

---
 BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java |   63 +++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java b/BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java
index ae83f77..c4ef008 100644
--- a/BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java
+++ b/BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java
@@ -433,22 +433,59 @@
 			sql.close_con();
 		}
 	}
+	
+	public static float queryAvgBattMonResAlmPama(MysqlConnPool pool,int dev_id) {
+		String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Tb_Dev_Param_Table + " WHERE dev_Id = " + dev_id + " AND alm_id = 119007 LIMIT 1";
+		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		ResultSet res = null;
+		float avg_param = 0;
+		try {
+			res = sql.sqlMysqlQuery(sql_str_sel);
+			if(res.next()) {
+				float alm_high_coe = res.getFloat("alm_high_coe");
+				float alm_low_coe = res.getFloat("alm_low_coe");
+				avg_param = (alm_high_coe + alm_low_coe)/2;
+			}			
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if(null != res) {
+				try {
+					res.close();
+				} catch (SQLException e) {
+					e.printStackTrace();
+				}
+			}
+			sql.close_con();
+		}
+		return avg_param;
+	}
 
 	/**
 	 * 鍚姩鏄ā鎷熸瘡涓數姹犵粍鐨勫唴闃绘暟鎹��
 	 * @param gB_MysqlConnPool
 	 */
 	public static void MakeMonResDataRandom(MysqlConnPool pool) {		
-		String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattRtData_Table;	
+		String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattInf_Table;	
+		//String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattRtData_Table;	
 		ResultSet res = null;
 		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
 		try {
 			res = sql.sqlMysqlQuery(sql_str_sel);
 			while(res.next()) {
-				int battgroupid = res.getInt("BattGroupId");
-				int mon_num = res.getInt("mon_num");
+				int BattGroupId = res.getInt("BattGroupId");
+				int MonCount    = res.getInt("MonCount");
+				int MonVolStd   = res.getInt("MonVolStd");
+				int MonCapStd   = res.getInt("MonCapStd");
 				
-				sql.sqlMysqlExecute("UPDATE " + Sql_Mysql.BattRtData_Table + " SET mon_res = " + String.format("%1.3f", (float)(0.101+Math.random()*0.298)) + " WHERE BattGroupId = " + battgroupid + " AND mon_num = " + mon_num);
+				int FBSDeviceId = res.getInt("FBSDeviceId");
+				
+				float avg_param = queryAvgBattMonResAlmPama(pool,FBSDeviceId);
+				float jiaozhun = (float)(1*((float)MonVolStd/2)/((float)MonCapStd/100));
+				//System.out.println("鏍″噯鍊间负锛�"+jiaozhun + "\t MonVolStd"+MonVolStd+"\t MonCapStd"+MonCapStd);
+				for(int cnt = 1 ;cnt <= MonCount;cnt++) {					
+					sql.sqlMysqlExecute("UPDATE " + Sql_Mysql.BattRtData_Table + " SET mon_res = " + String.format("%1.3f", (float)(jiaozhun*avg_param +Math.random()*0.01)) + " WHERE BattGroupId = " + BattGroupId + " AND mon_num = " + cnt);
+				}
 			}
 		} catch (SQLException e) {
 			e.printStackTrace();
@@ -466,14 +503,16 @@
 	
 	public static void main(String[] args) {
 		MysqlConnPool pool = new MysqlConnPool("127.0.0.1", 3360, 5);
-		MakeMonResDataRandom(pool);
+		//MakeMonResDataRandom(pool);
 		
-//		for(int i = 0;i< 100000;i++) {
-//			float ran = (float)(0.101+Math.random()*0.298);
-//			if(ran < 0.101 || ran > 0.4 ) {
-//				System.err.println(ran);
-//			}
-//			System.out.println(String.format("%1.3f", ran));
-//		}
+		System.out.println(queryAvgBattMonResAlmPama(pool, 401600012));
+		
+		for(int i = 0;i< 100000;i++) {
+			float ran = (float)(0.11+Math.random()*0.019);
+			if(ran < 0.101 || ran > 0.4 ) {
+				System.err.println(ran);
+			}
+			System.out.println(String.format("%1.3f", ran));
+		}
 	}
 }

--
Gitblit v1.9.1