| | |
| | | import com.table_sql.CallBack; |
| | | import com.table_sql.MySqlPool; |
| | | |
| | | |
| | | public class BadBatt_thread extends Thread{ |
| | | private MySqlPool m_ConnPool = null; |
| | | private Connection conn=null; |
| | |
| | | System.out.println("bad_mon_flag: "+bad_mon_flag); |
| | | System.out.println("fbs9100_state: "+fbs9100_state);*/ |
| | | } |
| | | //查询出电池放电所有放电测试 |
| | | public List Batt_selecteffectiveBatt(MySqlPool m_ConnPool){ |
| | | |
| | | String sql="select DISTINCT("+tinf+".BattGroupId),"+tinf+".test_starttime,"+tinf+".record_time,"+tinf+".test_cap,"+tinf+".max_monvol,"+tinf+".min_monvol,"+tinf+".test_record_count,"+tinf+".test_curr, " |
| | | + " "+binf+".battgroupid,"+binf+".stationname1,"+binf+".stationname,"+binf+".battproducer,"+binf+".battinusedate,"+binf+".MonCapStd,"+binf+".monvolstd,"+binf+".battgroupname " |
| | | + " FROM "+tinf+","+binf+","+fbs9100_state+" " |
| | | + " WHERE "+tinf+".BattGroupId="+binf+".BattGroupId " |
| | | + " and "+binf+".FBSDeviceId="+fbs9100_state+".dev_id " |
| | | + " and test_type="+BattCapFactory.test3+" and test_starttype="+BattCapFactory.test_start3+" " |
| | | + " and dev_workstate=0 and "+binf+".Station_install=1 " |
| | | + " ORDER BY "+tinf+".battgroupid asc,"+tinf+".test_starttime desc "; |
| | | //System.out.println(sql); |
| | | List list=new ArrayList(); |
| | | //创建badBatt_Mon_flag表 |
| | | public void badBatt_Mon_flagcreate(MySqlPool m_ConnPool){ |
| | | //创建落后单体的表示表 |
| | | createbadbatt_mon_flagSql="CREATE TABLE IF NOT EXISTS "+bad_mon_flag+" " |
| | | + "(" |
| | | + "`num` int(11) NOT NULL AUTO_INCREMENT," |
| | | + "`count` int NOT NULL DEFAULT '0'," |
| | | + "PRIMARY KEY (`num`)" |
| | | + ")"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | Batt_Maint_Dealarm bmd =new Batt_Maint_Dealarm(); |
| | | Batttestdata_inf tinf=new Batttestdata_inf(); |
| | | BattInf binf=new BattInf(); |
| | | binf.setBattGroupId(rs.getInt("battGroupId")); |
| | | binf.setStationName1(rs.getString("stationName1")); |
| | | binf.setStationName(rs.getString("stationName")); |
| | | binf.setBattProducer(rs.getString("battProducer")); |
| | | if(rs.getString("battInUseDate")!=null) |
| | | binf.setBattInUseDate(rs.getDate("battInUseDate")); |
| | | binf.setMonVolStd(rs.getFloat("monVolStd")); |
| | | binf.setMonCapStd(rs.getFloat("monCapStd")); |
| | | |
| | | binf.setBattGroupName(rs.getString("battGroupName")); |
| | | tinf.setBattGroupId(rs.getInt("battGroupId")); |
| | | if(rs.getString("test_starttime")!=null) |
| | | tinf.setTest_starttime(rs.getTimestamp("test_starttime")); |
| | | if(rs.getString("record_time")!=null) |
| | | tinf.setRecord_time(rs.getTimestamp("record_time")); |
| | | tinf.setTest_cap(rs.getFloat("test_cap")); |
| | | tinf.setMax_monvol(rs.getFloat("max_monvol")); |
| | | tinf.setMin_monvol(rs.getFloat("min_monvol")); |
| | | tinf.setTest_record_count(rs.getInt("test_record_count")); |
| | | tinf.setTest_curr(rs.getFloat("test_curr")); |
| | | |
| | | bmd.setBinf(binf); |
| | | bmd.setTinf(tinf); |
| | | list.add(bmd); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return list; |
| | | Boolean bl=m_ConnPool.sqlMysqlUpdate(conn, createbadbatt_mon_flagSql); |
| | | } |
| | | //查询出落后单体 |
| | | public List Batt_selectBadSql(int battgroupid,int recourd_count,String record_time,MySqlPool m_ConnPool){ |
| | | String usesql=tstop+battgroupid; |
| | | String sql="select num,BattGroupId,test_record_count,test_type,data_new,data_available,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol " |
| | | + " from "+usesql |
| | | + " where test_record_count="+recourd_count+" and record_time='"+record_time+"'"; |
| | | //System.out.println(sql); |
| | | List<Batt_Maint_Dealarm> list=new ArrayList(); |
| | | //创建badBattMon表如果没有则创建 |
| | | public void insertBadBatt(MySqlPool m_ConnPool) { |
| | | //创建数据表 |
| | | String createbadbatt_monSql="CREATE TABLE IF NOT EXISTS "+bad_mon+" " |
| | | + "(" |
| | | + "`num` int(11) NOT NULL AUTO_INCREMENT," |
| | | + "`battgroupid` int NOT NULL DEFAULT '0'," |
| | | + " `mon_num` int NOT NULL DEFAULT '0'," |
| | | + "`record_num` int NOT NULL DEFAULT '0'," |
| | | + "`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_vol` float NOT NULL DEFAULT '0'," |
| | | + "`real_cap` float NOT NULL DEFAULT '0'," |
| | | + "`stdcap` float NOT NULL DEFAULT '0'," |
| | | + "`note` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' '," |
| | | + "`flag` int NOT NULL DEFAULT '4'," |
| | | + "PRIMARY KEY (`num`)," |
| | | + "KEY `index_num` (`battgroupid`)" |
| | | + ")"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | Boolean bl=m_ConnPool.sqlMysqlUpdate(conn, createbadbatt_mon_flagSql); |
| | | } |
| | | //检测badBatt_Mon_flag表数据量 |
| | | public boolean badBatt_Mon_flagsearch(MySqlPool m_ConnPool){ |
| | | searchbadbatt_mon_flagSql=" select count(num) as nums from "+bad_mon_flag+" limit 1"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, searchbadbatt_mon_flagSql); |
| | | boolean bl=false; |
| | | try { |
| | | while(rs.next()){ |
| | | Batt_Maint_Dealarm bmd=new Batt_Maint_Dealarm(); |
| | | BattInf binf=new BattInf(); |
| | | Batttestdatastop tstop=new Batttestdatastop(); |
| | | tstop.setNum(rs.getInt("num")); |
| | | tstop.setBattGroupId(rs.getInt("BattGroupId")); |
| | | tstop.setTest_record_count(rs.getInt("test_record_count")); |
| | | tstop.setTest_type(rs.getInt("test_type")); |
| | | tstop.setData_new(rs.getInt("data_new")); |
| | | tstop.setData_available(rs.getInt("data_available")); |
| | | tstop.setRecord_num(rs.getInt("record_num")); |
| | | tstop.setTest_starttime(rs.getTimestamp("test_starttime")); |
| | | tstop.setRecord_time(rs.getTimestamp("record_time")); |
| | | tstop.setTest_timelong(rs.getInt("test_timelong")); |
| | | tstop.setGroup_vol(rs.getFloat("group_vol")); |
| | | tstop.setTest_curr(rs.getFloat("test_curr")); |
| | | tstop.setTest_cap(rs.getFloat("test_cap")); |
| | | tstop.setMon_num(rs.getInt("mon_num")); |
| | | tstop.setMon_vol(rs.getFloat("mon_vol")); |
| | | bmd.setBinf(binf); |
| | | bmd.setTstop(tstop); |
| | | list.add(bmd); |
| | | int nums=rs.getInt("nums"); |
| | | if(nums>0){ |
| | | bl=true; |
| | | } |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | /*for (Batt_Maint_Dealarm b : list) { |
| | | System.out.println(b.getTstop()); |
| | | }*/ |
| | | return list; |
| | | } |
| | | //向告警表中插入因单体落后导致的告警 |
| | | public ArrayList Batt_insertalarmSql(Object obj,MySqlPool m_ConnPool){ |
| | | List<Batt_Maint_Dealarm> list=(List<Batt_Maint_Dealarm>) obj; |
| | | ArrayList sql_str=new ArrayList(); |
| | | if(list.size()>0&&list!=null){ |
| | | for(int i=0;i<list.size();i++){ |
| | | Battalarm_data adata = new Battalarm_data(); |
| | | Batttestdatastop tstop=(Batttestdatastop) list.get(i).getTstop(); |
| | | adata.setBattGroupId(tstop.getBattGroupId()); |
| | | adata.setMonNum(tstop.getMon_num()); |
| | | adata.setRecord_Id(UUID.randomUUID().getLeastSignificantBits()); |
| | | adata.setAlm_id(tstop.getNum()); |
| | | //System.out.println("tstop.getBattGroupId():"+tstop.getBattGroupId()+" tstop.getNum():"+tstop.getNum()); |
| | | adata.setAlm_signal_id(tstop.getTest_type());//存放告警类型的高低告警 |
| | | adata.setAlm_level(tstop.getData_available());//默认为表中当前告警类型的告警等级 |
| | | adata.setAlm_start_time(new Date());//当前记录的时间 |
| | | adata.setAlm_end_time(new Date()); |
| | | adata.setAlm_value(tstop.getTest_cap());//默认为当前告警类型的实际值 |
| | | adata.setAlm_is_confirmed(0); |
| | | adata.setAlm_confirmed_time(new Date());//默认为当前时间 |
| | | adata.setAlm_cleared_type(0);//默认为实时告警0 |
| | | adata.setUsr_Id(0); |
| | | boolean bl=deleteAndinsert(adata, m_ConnPool); |
| | | //System.out.println(i+" "+bl); |
| | | //int flag=judge(adata, m_ConnPool);//判断改电池组该单体是否存在容量告警告警和容量更换告警 |
| | | /*if(flag==1){ |
| | | //System.out.println(adata.getBattGroupId()); |
| | | updatealarmSql = "update "+balarm+" set Record_Id="+adata.getRecord_Id()+",alm_signal_id="+adata.getAlm_signal_id()+",alm_level="+adata.getAlm_level() |
| | | +",alm_start_time='"+BadBatt_thread.sdf.format(adata.getAlm_start_time())+"',alm_end_time='"+BadBatt_thread.sdf.format(adata.getAlm_end_time())+"',alm_value="+adata.getAlm_value()+",alm_is_confirmed="+adata.getAlm_is_confirmed() |
| | | +",alm_confirmed_time='"+BadBatt_thread.sdf.format(adata.getAlm_confirmed_time())+"',usr_Id="+adata.getUsr_Id() |
| | | +",alm_id="+adata.getAlm_id() |
| | | +" where BattGroupId="+adata.getBattGroupId()+" and MonNum="+adata.getMonNum()+" and alm_id in("+AlarmDaoFactory.Alarm_CapAlarm+","+AlarmDaoFactory.Alarm_CapChange+") and alm_cleared_type="+adata.getAlm_cleared_type(); |
| | | sql_str.add(updatealarmSql); |
| | | }else{*/ |
| | | insertalarmSql="insert into "+balarm+" " |
| | | + "(" |
| | | + "BattGroupId," |
| | | + "MonNum," |
| | | + "Record_Id," |
| | | + "alm_id," |
| | | + "alm_signal_id," |
| | | + "alm_level," |
| | | + "alm_start_time," |
| | | + "alm_end_time," |
| | | + "alm_value," |
| | | + "alm_is_confirmed," |
| | | + "alm_confirmed_time," |
| | | + "alm_cleared_type," |
| | | + "usr_Id" |
| | | + ") " |
| | | + " values(" |
| | | + adata.getBattGroupId()+"," |
| | | + adata.getMonNum()+"," |
| | | + adata.getRecord_Id()+"," |
| | | + adata.getAlm_id()+"," |
| | | + adata.getAlm_signal_id()+"," |
| | | + adata.getAlm_level()+"," |
| | | +"'"+BadBatt_thread.sdf.format(adata.getAlm_start_time())+"'," |
| | | +"'"+BadBatt_thread.sdf.format(adata.getAlm_end_time())+"'," |
| | | + adata.getAlm_value()+"," |
| | | + adata.getAlm_is_confirmed()+"," |
| | | +"'"+BadBatt_thread.sdf.format(adata.getAlm_confirmed_time())+"'," |
| | | + adata.getAlm_cleared_type()+"," |
| | | + adata.getUsr_Id() |
| | | + ")";//如果对应是字符几个带上单引号 |
| | | sql_str.add(insertalarmSql); |
| | | } |
| | | } |
| | | return sql_str; |
| | | } |
| | | //删除旧的该电池组的实时告警,并将其添加至历史告警中 |
| | | public boolean deleteAndinsert(Object obj,MySqlPool m_ConnPool){ |
| | | Battalarm_data adata = (Battalarm_data) obj; |
| | | ArrayList sql_str=new ArrayList(); |
| | | //查询旧的告警 |
| | | String selectSql="select battgroupid,monnum,record_id,alm_id,alm_signal_id,alm_level,alm_start_time,alm_end_time,alm_value,alm_is_confirmed,alm_confirmed_time,alm_cleared_type,usr_id from db_alarm.tb_battalarm_data where battgroupid="+adata.getBattGroupId()+" and alm_id in("+BattCapFactory.Alarm_CapChange+","+BattCapFactory.Alarm_CapAlarm+")"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, selectSql); |
| | | List list=new ArrayList(); |
| | | try { |
| | | while(rs.next()){ |
| | | Battalarm_data a=new Battalarm_data(); |
| | | a.setBattGroupId(rs.getInt("battGroupId")); |
| | | a.setMonNum(rs.getInt("monNum")); |
| | | a.setRecord_Id(rs.getLong("record_Id")); |
| | | a.setAlm_id(rs.getInt("alm_id")); |
| | | a.setAlm_signal_id(rs.getInt("alm_signal_id")); |
| | | a.setAlm_level(rs.getInt("alm_level")); |
| | | a.setAlm_start_time(rs.getTimestamp("alm_start_time")); |
| | | a.setAlm_end_time(rs.getTimestamp("alm_end_time")); |
| | | a.setAlm_value(rs.getFloat("alm_value")); |
| | | a.setAlm_is_confirmed(rs.getInt("alm_is_confirmed")); |
| | | a.setAlm_confirmed_time(rs.getTimestamp("alm_confirmed_time")); |
| | | a.setAlm_cleared_type(rs.getInt("alm_cleared_type")); |
| | | a.setUsr_Id(rs.getInt("usr_Id")); |
| | | list.add(a); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally { |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(list!=null&&list.size()>0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Battalarm_data ad=(Battalarm_data) list.get(i); |
| | | //将旧的告警放入历史告警 |
| | | String insertSql="insert into db_alarm.tb_battalarm_data_history(battgroupid,monnum,record_id,alm_id,alm_signal_id,alm_level,alm_start_time,alm_end_time,alm_value,alm_is_confirmed,alm_confirmed_time,alm_cleared_type,usr_id) " |
| | | + " values(" |
| | | + ad.getBattGroupId()+"," |
| | | + ad.getMonNum()+"," |
| | | + ad.getRecord_Id()+"," |
| | | + ad.getAlm_id()+"," |
| | | + ad.getAlm_signal_id()+"," |
| | | + ad.getAlm_level()+",'" |
| | | + BadBatt_thread.sdf.format(ad.getAlm_start_time())+"','" |
| | | + BadBatt_thread.sdf.format(ad.getAlm_end_time())+"'," |
| | | + ad.getAlm_value()+"," |
| | | + ad.getAlm_is_confirmed()+",'" |
| | | + BadBatt_thread.sdf.format(ad.getAlm_confirmed_time())+"'," |
| | | + ad.getAlm_cleared_type()+"," |
| | | + ad.getUsr_Id()+"" |
| | | + ")"; |
| | | sql_str.add(insertSql); |
| | | } |
| | | } |
| | | //删除旧的该电池组的实时告警 |
| | | String deleteSql="delete from db_alarm.tb_battalarm_data where battgroupid="+adata.getBattGroupId()+" and alm_id in("+BattCapFactory.Alarm_CapChange+","+BattCapFactory.Alarm_CapAlarm+")"; |
| | | sql_str.add(deleteSql); |
| | | boolean bl=MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str); |
| | | return bl; |
| | | } |
| | | //7.2落后单体筛选出来后,往告警表添加前的判断 |
| | | public int judge(Object obj,MySqlPool m_ConnPool){ |
| | | Battalarm_data adata = (Battalarm_data) obj; |
| | | String sql=" SELECT COUNT(num) AS nums FROM "+balarm+" WHERE battgroupid="+adata.getBattGroupId()+" and monnum="+adata.getMonNum()+" and alm_id in("+AlarmDaoFactory.Alarm_CapAlarm+","+AlarmDaoFactory.Alarm_CapChange+") and alm_cleared_type="+adata.getAlm_cleared_type(); |
| | | //System.out.println(sql); |
| | | List list=new ArrayList(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | int nums=rs.getInt("nums"); |
| | | list.add(nums); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | int flag=0;//返回标识符 |
| | | if(list!=null&&list.size()>0){ |
| | | int nums=(Integer) list.get(list.size()-1); |
| | | if(nums>0){ |
| | | flag=1; |
| | | }else{ |
| | | flag=0; |
| | | } |
| | | } |
| | | //System.out.println(adata.getBattGroupId()+" "+adata.getMonNum()+" "+adata.getAlm_id()+" "+flag); |
| | | return flag; |
| | | } |
| | | //查询表batt_param_low中的参数 |
| | | public List batt_paramsearchSql(Batt_param_low param,MySqlPool m_ConnPool){ |
| | | String sql="select "+bparam+".num,"+bparam+".low_type,"+bparam+".low_nametype,"+bparam+".low_value,"+bparam+".low_method from "+bparam+" where "+bparam+".low_type="+param.getLow_type()+" and "+bparam+".low_nametype="+param.getLow_nametype()+" limit 1"; |
| | | //修改进程监控表中的实时时间 |
| | | public boolean processupdateSql(Date nowdate,String ProcessName,MySqlPool m_ConnPool_){ |
| | | String sql=" update "+Mysql_database_param.web_site+Mysql_database_param.tb_Process_survey+" " |
| | | +" set ProcessTime='"+BadBatt_thread.sdf.format(nowdate) |
| | | +"' where ProcessName='"+ProcessName+"'"; |
| | | Connection conn=m_ConnPool_.getConn(); |
| | | //System.out.println(sql); |
| | | List list=new ArrayList(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | Batt_param_low blow=new Batt_param_low(); |
| | | blow.setNum(rs.getInt("num")); |
| | | blow.setLow_type(rs.getInt("low_type")); |
| | | blow.setLow_nametype(rs.getInt("low_nametype")); |
| | | blow.setLow_value(rs.getFloat("low_value")); |
| | | blow.setLow_method(rs.getInt("low_method")); |
| | | list.add(blow); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally { |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return list; |
| | | |
| | | boolean bl=m_ConnPool_.sqlMysqlUpdate(conn, sql); |
| | | return bl; |
| | | } |
| | | //获取当前天23点59分59秒的time |
| | | public long getDateTIme() { |
| | | Calendar calendar2 = Calendar.getInstance(); |
| | | |
| | | calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH), |
| | | 23,59, 0); |
| | | Date endOfDate = calendar2.getTime(); |
| | | //String time=BadBatt_thread.sdf.format(endOfDate); |
| | | long time=endOfDate.getTime(); |
| | | return time; |
| | | } |
| | | //查询电池告警参数表alarm_param |
| | | public List batt_alarmparamSql(int alm_id,MySqlPool m_ConnPool){ |
| | |
| | | } |
| | | return list; |
| | | } |
| | | //判断此次的筛选出来的放电记录与数据库中存放的是否一致 |
| | | public int badbatt_judgeInorNotSql(Object obj,MySqlPool m_ConnPool){ |
| | | Batttestdata_inf tinf=(Batttestdata_inf) obj; |
| | | String sql="select count(num) as nums from "+bad_mon+" " |
| | | + " WHERE "+bad_mon+".battgroupid="+tinf.getBattGroupId()+" " |
| | | + " and "+bad_mon+".test_starttime='"+BadBatt_thread.sdf.format(tinf.getTest_starttime())+"' LIMIT 1"; |
| | | //查询出落后单体 |
| | | public List Batt_selectBadSql(int battgroupid,int recourd_count,int record_num,String record_time,MySqlPool m_ConnPool){ |
| | | String usesql=tdata+battgroupid; |
| | | String sql="select num,BattGroupId,test_record_count,test_type,data_new,data_available,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol " |
| | | + " from "+usesql |
| | | + " where test_record_count="+recourd_count+" and record_num="+record_num+" and record_time='"+record_time+"'"; |
| | | //System.out.println(sql); |
| | | List<Batttestdatastop> list=new ArrayList(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | int nums=0;//表示位 |
| | | try { |
| | | while(rs.next()){ |
| | | nums=rs.getInt("nums"); |
| | | Batttestdatastop tstop=new Batttestdatastop(); |
| | | tstop.setNum(rs.getInt("num")); |
| | | tstop.setBattGroupId(rs.getInt("BattGroupId")); |
| | | tstop.setTest_record_count(rs.getInt("test_record_count")); |
| | | tstop.setTest_type(rs.getInt("test_type")); |
| | | tstop.setData_new(rs.getInt("data_new")); |
| | | tstop.setData_available(rs.getInt("data_available")); |
| | | tstop.setRecord_num(rs.getInt("record_num")); |
| | | tstop.setTest_starttime(rs.getTimestamp("test_starttime")); |
| | | tstop.setRecord_time(rs.getTimestamp("record_time")); |
| | | tstop.setTest_timelong(rs.getInt("test_timelong")); |
| | | tstop.setGroup_vol(rs.getFloat("group_vol")); |
| | | tstop.setTest_curr(rs.getFloat("test_curr")); |
| | | tstop.setTest_cap(rs.getFloat("test_cap")); |
| | | tstop.setMon_num(rs.getInt("mon_num")); |
| | | tstop.setMon_vol(rs.getFloat("mon_vol")); |
| | | list.add(tstop); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return nums; |
| | | return list; |
| | | } |
| | | //1.查询所有的电池组 |
| | | public List<BattInf> getAllBinf(MySqlPool m_ConnPool){ |
| | | String sql="select distinct * from db_battinf.tb_battinf order by BattGroupId asc "; |
| | | List list=new ArrayList(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | BattInf binf=new BattInf(); |
| | | binf.setBattGroupId(rs.getInt("battGroupId")); |
| | | binf.setStationName1(rs.getString("stationName1")); |
| | | binf.setStationName(rs.getString("stationName")); |
| | | binf.setBattProducer(rs.getString("battProducer")); |
| | | if(rs.getString("battInUseDate")!=null) |
| | | binf.setBattInUseDate(rs.getDate("battInUseDate")); |
| | | binf.setMonVolStd(rs.getFloat("monVolStd")); |
| | | binf.setMonCapStd(rs.getFloat("monCapStd")); |
| | | binf.setBattGroupName(rs.getString("battGroupName")); |
| | | binf.setMonCount(rs.getInt("moncount")); |
| | | list.add(binf); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return list; |
| | | |
| | | } |
| | | //创建单体落后的表badBatt_Mon |
| | | public ArrayList badBatt_Moninsert(Object obj){ |
| | | List<Batt_Maint_Dealarm> list=(List) obj; |
| | | //2.查询每个电池组的有效放电记录,如果找不到将整组单体标记为"无法判断",将 |
| | | public Batttestdata_inf getEffectiveTinf(int battGroupId,MySqlPool m_ConnPool) { |
| | | String sql="select tb_batttestdata_inf.BattGroupId ,test_record_count,record_num, test_curr, max_monvol, min_monvol, test_cap" |
| | | + " , test_starttime,record_time, test_timelong" |
| | | + " from db_batt_testdata.tb_batttestdata_inf " |
| | | + " where db_batt_testdata.tb_batttestdata_inf.data_available = 1 " |
| | | + " and test_type = 3 " |
| | | + " and (test_stoptype in (3, 4, 6) " |
| | | + " or (test_stoptype = 2 and test_timelong >= 7200)) " |
| | | + " and BattGroupId="+battGroupId |
| | | + " ORDER BY tb_batttestdata_inf.BattGroupId asc, test_starttime desc " |
| | | + " limit 1"; |
| | | //System.out.println(sql); |
| | | List<Batttestdata_inf> list=new ArrayList<>(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | Batttestdata_inf tinf=new Batttestdata_inf(); |
| | | tinf.setBattGroupId(rs.getInt("battGroupId")); |
| | | if(rs.getString("test_starttime")!=null) |
| | | tinf.setTest_starttime(rs.getTimestamp("test_starttime")); |
| | | if(rs.getString("record_time")!=null) |
| | | tinf.setRecord_time(rs.getTimestamp("record_time")); |
| | | tinf.setTest_timelong(rs.getInt("test_timelong")); |
| | | tinf.setTest_cap(rs.getFloat("test_cap")); |
| | | tinf.setMax_monvol(rs.getFloat("max_monvol")); |
| | | tinf.setMin_monvol(rs.getFloat("min_monvol")); |
| | | tinf.setTest_curr(rs.getFloat("test_curr")); |
| | | tinf.setTest_record_count(rs.getInt("test_record_count")); |
| | | tinf.setRecord_num(rs.getInt("record_num")); |
| | | list.add(tinf); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(list.size()>0) { |
| | | return list.get(list.size()-1); |
| | | }else { |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | //标记为无法判断:flag为4并插入 |
| | | public void insertUnjudge(BattInf binf,String note,int flag,MySqlPool m_ConnPool) { |
| | | ArrayList sql_str=new ArrayList(); |
| | | |
| | | //创建数据表 |
| | | createbadbatt_monSql="CREATE TABLE IF NOT EXISTS "+bad_mon+" " |
| | | + "(" |
| | | + "`num` int(11) NOT NULL AUTO_INCREMENT," |
| | | + "`battgroupid` int NOT NULL DEFAULT '0'," |
| | | + " `mon_num` int NOT NULL DEFAULT '0'," |
| | | + "`record_num` int NOT NULL DEFAULT '0'," |
| | | + "`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_vol` float NOT NULL DEFAULT '0'," |
| | | + "`real_cap` float NOT NULL DEFAULT '0'," |
| | | + "`stdcap` float NOT NULL DEFAULT '0'," |
| | | + "`note` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' '," |
| | | + "PRIMARY KEY (`num`)," |
| | | + "KEY `index_num` (`battgroupid`)" |
| | | + ")"; |
| | | sql_str.add(createbadbatt_monSql); |
| | | |
| | | //删除数据表 |
| | | // deletebadbatt_monSql="DELETE FROM "+bad_mon+" WHERE num>0";//truncate table .... |
| | | //sql_str.add(deletebadbatt_monSql); |
| | | |
| | | //向tb_badbatt_mon表中插入数据 |
| | | if(list.size()>0&&list!=null){ |
| | | |
| | | insertbadbatt_monSql="insert into "+bad_mon+" " |
| | | String deletebadbatt_monSql="DELETE FROM "+bad_mon+" WHERE battgroupid="+binf.getBattGroupId()+" "; |
| | | sql_str.add(deletebadbatt_monSql); |
| | | String insertbadbatt_monSql="insert into "+bad_mon+" " |
| | | + "(" |
| | | + "battgroupid," |
| | | + "mon_num," |
| | |
| | | + "mon_vol," |
| | | + "real_cap," |
| | | + "stdcap," |
| | | + "note" |
| | | + "note," |
| | | + "flag" |
| | | + ") " |
| | | + " values "; |
| | | for(int i=0;i<list.size();i++){ |
| | | Batttestdatastop tsop=list.get(i).getTstop(); |
| | | int battgroupid=0; |
| | | deletebadbatt_monSql="DELETE FROM "+bad_mon+" WHERE battgroupid="+tsop.getBattGroupId()+" "; |
| | | if(battgroupid!=tsop.getBattGroupId()){ |
| | | battgroupid=tsop.getBattGroupId(); |
| | | sql_str.add(deletebadbatt_monSql); |
| | | } |
| | | for(int i=0;i<binf.getMonCount();i++){ |
| | | if(i>0){ |
| | | insertbadbatt_monSql+=" , "; |
| | | } |
| | | insertbadbatt_monSql=insertbadbatt_monSql |
| | | + "(" |
| | | + tsop.getBattGroupId()+"," |
| | | + tsop.getMon_num()+"," |
| | | + tsop.getRecord_num()+"," |
| | | + "'"+BadBatt_thread.sdf.format(tsop.getTest_starttime())+"'," |
| | | + tsop.getGroup_vol()+"," |
| | | + tsop.getTest_curr()+"," |
| | | + tsop.getMon_vol()+"," |
| | | + tsop.getTest_cap()+"," |
| | | + list.get(i).getBinf().getMonCapStd()+"," |
| | | + tsop.getNum().toString()+"" |
| | | + binf.getBattGroupId()+"," |
| | | + (i+1)+"," |
| | | + 0+"," |
| | | + "'1972-01-01 00:00:00'," |
| | | + 0+"," |
| | | + 0+"," |
| | | + 0+"," |
| | | + 0+"," |
| | | + binf.getMonCapStd()+"," |
| | | + "'"+note+"'," |
| | | + flag+"" |
| | | + ")";//如果对应是字符几个带上单引号 |
| | | |
| | | } |
| | | //System.out.println("insertbadbatt_monSql:"+insertbadbatt_monSql); |
| | | sql_str.add(insertbadbatt_monSql); |
| | | |
| | | MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str); |
| | | } |
| | | return sql_str; |
| | | } |
| | | //创建badBatt_Mon_flag表 |
| | | public void badBatt_Mon_flagcreate(MySqlPool m_ConnPool){ |
| | | //创建落后单体的表示表 |
| | | createbadbatt_mon_flagSql="CREATE TABLE IF NOT EXISTS "+bad_mon_flag+" " |
| | | + "(" |
| | | + "`num` int(11) NOT NULL AUTO_INCREMENT," |
| | | + "`count` int NOT NULL DEFAULT '0'," |
| | | + "PRIMARY KEY (`num`)" |
| | | + ")"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | Boolean bl=m_ConnPool.sqlMysqlUpdate(conn, createbadbatt_mon_flagSql); |
| | | //System.out.println("createbadbatt_mon_flagSql:"+bl); |
| | | } |
| | | //清空badBatt_Mon_flag表 |
| | | public boolean badBatt_Mon_flagdelete(MySqlPool m_ConnPool){ |
| | | deletebadbatt_mon_flagSql="DELETE FROM "+bad_mon_flag+" WHERE num>0"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | Boolean bl=m_ConnPool.sqlMysqlUpdate(conn, deletebadbatt_mon_flagSql); |
| | | return bl; |
| | | } |
| | | //检测badBatt_Mon_flag表数据量 |
| | | public boolean badBatt_Mon_flagsearch(MySqlPool m_ConnPool){ |
| | | searchbadbatt_mon_flagSql=" select count(num) as nums from "+bad_mon_flag+" limit 1"; |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, searchbadbatt_mon_flagSql); |
| | | boolean bl=false; |
| | | try { |
| | | while(rs.next()){ |
| | | int nums=rs.getInt("nums"); |
| | | if(nums>0){ |
| | | bl=true; |
| | | } |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally { |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return bl; |
| | | } |
| | | //7.1落后单体筛选中当单体电<标存电压*0.9时的测试电容就是实际电容 |
| | | public float Batt_serchRealCap(int battgroupid,int test_record_count,float mon_vol,int mon_num,MySqlPool m_ConnPool){ |
| | | String sql="select test_cap from "+tdata+battgroupid+" "+ |
| | | " WHERE test_record_count="+test_record_count+" and mon_vol>"+mon_vol+" and mon_num="+mon_num+" " + |
| | | " order by record_time DESC " + |
| | | " LIMIT 1 "; |
| | | List list=new ArrayList(); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | try { |
| | | while(rs.next()){ |
| | | float test_cap=rs.getFloat("test_cap"); |
| | | list.add(Math.abs(test_cap)); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | float test_cap=0f; |
| | | if(list!=null&&list.size()>0){ |
| | | test_cap=(Float) list.get(list.size()-1); |
| | | } |
| | | return test_cap; |
| | | |
| | | } |
| | | //param容量参数有效值的设置 |
| | | public float setParam(MySqlPool m_ConnPool){ |
| | | float pre_param=0; |
| | | Batt_param_low capLow=new Batt_param_low(); |
| | | capLow.setLow_type(BattCapFactory.CapType_type);//2 |
| | | capLow.setLow_nametype(BattCapFactory.CapType_name);//1 |
| | | capLow.setLow_method(BattCapFactory.CapType_method);//0 |
| | | |
| | | List<Batt_param_low> listC=batt_paramsearchSql(capLow, m_ConnPool); |
| | | if(listC!=null&&listC.size()>0){ |
| | | pre_param=listC.get(listC.size()-1).getLow_value();//0.01 |
| | | } |
| | | return pre_param; |
| | | } |
| | | //电池组最近一次放电记录的筛选(测试容量大于0.1*标称容量) |
| | | public List recent_Test1(Object obj){ |
| | | List<Batt_Maint_Dealarm> listE=(List<Batt_Maint_Dealarm>) obj; |
| | | int flag=0;//该次放电是否有效判断 |
| | | List<Batt_Maint_Dealarm> list=new ArrayList();//存放放电有效的测试 |
| | | if(listE!=null&&listE.size()>0){ |
| | | for(int i=0;i<listE.size();i++){ |
| | | STDAH=listE.get(i).getBinf().getMonCapStd(); |
| | | float testCap=listE.get(i).getTinf().getTest_cap();//此次放电量统计 |
| | | flag=BattCapFactory.Judge(testCap, param, STDAH); |
| | | //System.out.println("testCap:"+testCap+" param:"+param+" STDAH:"+STDAH); |
| | | if(flag==1){ |
| | | if(list.size()>0){ |
| | | int tdata_battgroupid=listE.get(i).getTinf().getBattGroupId(); |
| | | int e_battgroupid=list.get(list.size()-1).getTinf().getBattGroupId(); |
| | | if(tdata_battgroupid!=e_battgroupid){ |
| | | list.add(listE.get(i)); |
| | | }else{ |
| | | continue; |
| | | } |
| | | }else{ |
| | | list.add(listE.get(i)); |
| | | } |
| | | flag=0; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | //电池组最近一次放电记录的筛选(测试容量小于0.1*标称容量) |
| | | public List recent_Test2(Object obj){ |
| | | List<Batt_Maint_Dealarm> listE=(List<Batt_Maint_Dealarm>) obj; |
| | | int flag=0;//该次放电是否有效判断 |
| | | List<Batt_Maint_Dealarm> list=new ArrayList();//存放放电有效的测试 |
| | | if(listE!=null&&listE.size()>0){ |
| | | for(int i=0;i<listE.size();i++){ |
| | | STDAH=listE.get(i).getBinf().getMonCapStd(); |
| | | float testCap=listE.get(i).getTinf().getTest_cap();//此次放电量统计 |
| | | flag=BattCapFactory.Judge(testCap, param, STDAH); |
| | | float max_testcap=0; |
| | | Batt_Maint_Dealarm bmd=new Batt_Maint_Dealarm(); |
| | | //System.out.println("testCap:"+testCap+" param:"+param+" STDAH:"+STDAH); |
| | | if(flag==0){ |
| | | if(list.size()>0){ |
| | | int tdata_battgroupid=listE.get(i).getTinf().getBattGroupId(); |
| | | int e_battgroupid=list.get(list.size()-1).getTinf().getBattGroupId(); |
| | | if(tdata_battgroupid!=e_battgroupid){ |
| | | list.add(listE.get(i)); |
| | | max_testcap=0; |
| | | }else{ |
| | | if(Math.abs(testCap)>Math.abs(max_testcap)) { |
| | | list.set(list.size()-1, listE.get(i)); |
| | | } |
| | | max_testcap=testCap; |
| | | bmd=listE.get(i); |
| | | } |
| | | }else{ |
| | | list.add(listE.get(i)); |
| | | max_testcap=testCap; |
| | | bmd=listE.get(i); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | //将list1核list2整合 |
| | | public List getlist(List<Batt_Maint_Dealarm> list1, List<Batt_Maint_Dealarm> list2) { |
| | | List list=new ArrayList();//存放最后的结果 |
| | | int flag=0; |
| | | if(list1.size()>0) { |
| | | for(int k=0;k<list1.size();k++) { |
| | | list.add(list1.get(k)); |
| | | |
| | | } |
| | | } |
| | | if(list1.size()>0&&list2.size()>0) { |
| | | for(int i=0;i<list2.size();i++) { |
| | | int list2_battgroupid=list2.get(i).getTinf().getBattGroupId(); |
| | | for(int j=0;j<list1.size();j++) { |
| | | int list1_battgroupid=list1.get(j).getTinf().getBattGroupId(); |
| | | if(list2_battgroupid== list1_battgroupid){ |
| | | flag=0; |
| | | break; |
| | | }else { |
| | | flag=1; |
| | | } |
| | | } |
| | | if(flag==1) { |
| | | list.add(list2.get(i)); |
| | | flag=0; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | //电池组最近一次放电记录的筛选(测试容量大于0.1*标称容量) |
| | | public List getRecent(Object obj){ |
| | | List<Batt_Maint_Dealarm> listE=(List<Batt_Maint_Dealarm>) obj; |
| | | int battGroupId=0;//该次放电是否有效判断 |
| | | List<Batt_Maint_Dealarm> list=new ArrayList();//存放放电有效的测试 |
| | | if(listE!=null&&listE.size()>0){ |
| | | for (Batt_Maint_Dealarm bmd : listE) { |
| | | int battGroupIdE=bmd.getTinf().getBattGroupId(); |
| | | if(battGroupId!=battGroupIdE) { |
| | | list.add(bmd); |
| | | battGroupId=battGroupIdE; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | //删除旧的数据 |
| | | public void badbatt_delete(Object obj,MySqlPool m_ConnPool){ |
| | | Batttestdata_inf tinf=(Batttestdata_inf) obj; |
| | | //删除数据表 |
| | | deletebadbatt_monSql="DELETE FROM "+bad_mon+" WHERE battgroupid="+tinf.getBattGroupId();//truncate table .... |
| | | ArrayList sql_str=new ArrayList(); |
| | | sql_str.add(deletebadbatt_monSql); |
| | | boolean bl=MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str); |
| | | //System.out.println(bl+"................"+tinf.getBattGroupId()); |
| | | } |
| | | //根据标称电压和测试容量查询出当前测试容量对应标准曲线的单体电压 |
| | | public double getStandard_monvol(double monvolstd,double moncapstd,double test_cap) { |
| | | double cap=0; |
| | | if(monvolstd==12) { |
| | | cap=150; |
| | | }else { |
| | | if(moncapstd<=300) { |
| | | cap=300; |
| | | }else { |
| | | cap=500; |
| | | } |
| | | } |
| | | |
| | | String sql="select ROUND(avg(mon_vol),3) as standard_mon_vol from db_battinf.tb_battmon_testcap where monvolstd="+monvolstd+" and test_cap="+test_cap+" and moncapstd="+cap+" limit 1"; |
| | | //String sql=" select distinct ROUND(mon_vol,3) as standard_mon_vol from db_battinf.tb_battmon_testcap where monvolstd="+monvolstd+" and test_cap<="+test_cap+" and moncapstd="+cap+" order by test_cap desc limit 1 "; |
| | | System.out.println(sql); |
| | | Connection conn=m_ConnPool.getConn(); |
| | | ResultSet rs=m_ConnPool.sqlMysqlQuery(conn, sql); |
| | | double standard_monvol=0f; |
| | | try { |
| | | while(rs.next()){ |
| | | standard_monvol=rs.getDouble("standard_mon_vol"); |
| | | } |
| | | } catch (SQLException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | }finally{ |
| | | try { |
| | | if(rs != null){ |
| | | rs.close(); |
| | | } |
| | | m_ConnPool.close_con(conn); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return standard_monvol; |
| | | } |
| | | //落后单体筛选 |
| | | public List badbatt_serch(Object obj,float aparam,float Cparam,int Caplevel,int Changelevel){ |
| | | List<Batt_Maint_Dealarm> list=(List<Batt_Maint_Dealarm>) obj; |
| | | List<Batt_Maint_Dealarm> listB=new ArrayList();//存放落后单体 |
| | | for (int j = 0; j < list.size(); j++) { |
| | | /*//判断此次的筛选出来的放电记录与数据库中存放的是否一致 |
| | | int badbattInorNot=badbatt_judgeInorNotSql(list.get(j).getTinf(),m_ConnPool); |
| | | if(badbattInorNot!=0){ |
| | | //System.out.println("badbattInorNot: "+list.get(j).getTinf().getBattGroupId()+" "+badbattInorNot); |
| | | continue; |
| | | }*/ |
| | | //删除旧的数据 |
| | | //System.out.println(list.get(j).getTinf().getBattGroupId()+"=================="); |
| | | badbatt_delete(list.get(j).getTinf(),m_ConnPool); |
| | | //System.out.println(list.get(j).getBinf().getBattGroupId()+" "+list.get(j).getTinf().getBattGroupId()+" "+BadBatt_thread.sdf.format(list.get(j).getTinf().getRecord_time())+" "+list.get(j).getTinf().getTest_cap()+" "+list.get(j).getTinf().getTest_record_count()); |
| | | List<Batt_Maint_Dealarm> listT=Batt_selectBadSql(list.get(j).getTinf().getBattGroupId(), list.get(j).getTinf().getTest_record_count(),BadBatt_thread.sdf.format(list.get(j).getTinf().getRecord_time()), m_ConnPool ); |
| | | //System.out.println(listT.get(listT.size()-1).getTstop().getBattGroupId()+" "+"listT.size():"+listT.size()); |
| | | BattInf binf=list.get(j).getBinf();//存取求实际容量的参数 |
| | | Batttestdata_inf tinf=list.get(j).getTinf(); |
| | | |
| | | if(listT!=null&&listT.size()>0){ |
| | | for(int z=0;z<listT.size();z++){ |
| | | if(z%12==0){ |
| | | //修改进程监控表中的实时时间 |
| | | boolean b=processupdateSql(new Date(),Mysql_database_param.BMS_FBSDEV_BADBATT_MON, m_ConnPool); |
| | | } |
| | | STDAH=binf.getMonCapStd(); |
| | | MonomerVolType=binf.getMonVolStd(); |
| | | |
| | | //current=listT.get(z).getTstop().getTest_curr();实际电流 = 测试容量*3600/放电时长 |
| | | current=(listT.get(z).getTstop().getTest_cap()*3600)/listT.get(z).getTstop().getTest_timelong(); |
| | | SumAH=listT.get(z).getTstop().getTest_cap(); |
| | | MaxMonomerVol=tinf.getMax_monvol();//最大电压 |
| | | /*//测试容量对应的标准单体电压 |
| | | double standard_monvol=getStandard_monvol(MonomerVolType,STDAH, SumAH); |
| | | if(standard_monvol==0) { |
| | | MonomerVol=standard_monvol; |
| | | }else { |
| | | MonomerVol=listT.get(z).getTstop().getMon_vol(); |
| | | }*/ |
| | | MonomerVol=listT.get(z).getTstop().getMon_vol(); |
| | | hourRate=BattCapFactory.GetHourRate(STDAH, current); |
| | | //System.out.println(listT.get(z).getTstop().getBattGroupId()+" "+listT.get(z).getTstop().getTest_record_count()+" "+listT.get(z).getTstop().getMon_num()+" "+listT.get(z).getTstop().getMon_vol()+" "+binf.getMonVolStd()*BattCapFactory.test_stop); |
| | | if(listT.get(z).getTstop().getMon_vol()>binf.getMonVolStd()*BattCapFactory.test_stop){ |
| | | realCap=BattCapFactory.GetMonomerCap(STDAH, hourRate, SumAH, MaxMonomerVol, MonomerVol, MonomerVolType, BattCapFactory.CapType_Real); |
| | | }else{ |
| | | realCap=Batt_serchRealCap(listT.get(z).getTstop().getBattGroupId(),listT.get(z).getTstop().getTest_record_count(),binf.getMonVolStd()*BattCapFactory.test_stop,listT.get(z).getTstop().getMon_num(),m_ConnPool); |
| | | } |
| | | //System.out.println(listT.get(z).getTstop().getBattGroupId()+" realCap:"+realCap+" STDAH:"+STDAH+" MonomerVolType:"+MonomerVolType+" current:"+current+" SumAH:"+SumAH+" MaxMonomerVol:"+MaxMonomerVol+" MonomerVol:"+MonomerVol+" hourRate:"+hourRate); |
| | | int flag=1;//标识位 |
| | | flag=BattCapFactory.JudgeAlarm(realCap, aparam,Cparam, STDAH); |
| | | if(flag!=1){ |
| | | listT.get(z).getTstop().setNum(flag); |
| | | listT.get(z).setBinf(binf);//将电池组信息设置进去 |
| | | if(flag==AlarmDaoFactory.Alarm_CapAlarm){ |
| | | listT.get(z).getTstop().setData_available(Caplevel);//存放告警等级 |
| | | listT.get(z).getTstop().setTest_type(AlarmDaoFactory.Alarm_IGNAL_ID_CapAlarmLow);//存放alm_signal_id |
| | | listT.get(z).getTstop().setTest_cap(Float.parseFloat(String.valueOf(realCap))); |
| | | }else if(flag==AlarmDaoFactory.Alarm_CapChange){ |
| | | listT.get(z).getTstop().setData_available(Changelevel);//存放告警等级 |
| | | listT.get(z).getTstop().setTest_type(AlarmDaoFactory.Alarm_IGNAL_ID_CapChangeLow);//存放alm_signal_id |
| | | listT.get(z).getTstop().setTest_cap(Float.parseFloat(String.valueOf(realCap))); |
| | | } |
| | | listB.add(listT.get(z)); |
| | | } |
| | | flag=1; |
| | | } |
| | | } |
| | | try { |
| | | Thread.sleep(10); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return listB; |
| | | } |
| | | //电池单体查询并创建 |
| | | public void serchBadBattandInsert(){ |
| | | List<Batt_Maint_Dealarm> listE=Batt_selecteffectiveBatt(m_ConnPool);//电池组处于在线监测的节能放电的放电记录 |
| | | //System.out.println("listE.size():"+listE.size()); |
| | | param=setParam(m_ConnPool);//param容量参数有效值的设置0.1 |
| | | /*//电池组最近一次放电记录的筛选(测试容量大于0.1*标称容量) |
| | | List<Batt_Maint_Dealarm> list1=recent_Test1(listE); |
| | | //电池组最近一次放电记录的筛选(测试容量小于0.1*标称容量) |
| | | List<Batt_Maint_Dealarm> list2=recent_Test2(listE); |
| | | //将list1核list2整合 |
| | | List<Batt_Maint_Dealarm> list=getlist(list1,list2);//存放最后筛选的放电记录*/ |
| | | List<Batt_Maint_Dealarm> list=getRecent(listE); |
| | | System.out.println("list开始---------------------"+" "+list.size()); |
| | | float aparam=1; |
| | | int Caplevel=1; |
| | | int Changelevel=0;//告警等级 |
| | | //System.out.println(selectAlarmparamSql); |
| | | //计算出落后单体 |
| | | public List calculatorBadBatt(int battGroupId,double monCapStd,double monVolStd,double maxVol,List<Batttestdatastop> stopList,MySqlPool m_ConnPool) { |
| | | //查询告警落后和更换的参数值 |
| | | float aparam=1; |
| | | int Caplevel=1; |
| | | List<Alarm_param> listA=batt_alarmparamSql(AlarmDaoFactory.Alarm_CapAlarm, m_ConnPool); |
| | | if(listA!=null&&listA.size()>0){ |
| | | aparam=listA.get(listA.size()-1).getAlm_low_coe(); |
| | | Caplevel=listA.get(listA.size()-1).getAlm_low_level(); |
| | | } |
| | | float Cparam=0;//容量更换告警参数 |
| | | int Changelevel=0;//告警等级 |
| | | List<Alarm_param> listC1=batt_alarmparamSql(AlarmDaoFactory.Alarm_CapChange, m_ConnPool); |
| | | if(listC1!=null&&listC1.size()>0){ |
| | | Cparam=listC1.get(listC1.size()-1).getAlm_low_coe(); |
| | | Changelevel=listC1.get(listC1.size()-1).getAlm_low_level(); |
| | | } |
| | | //System.out.println("aparam:"+aparam+" cparam:"+Cparam); |
| | | //落后单体筛选 |
| | | List<Batt_Maint_Dealarm> listB=badbatt_serch(list,aparam,Cparam,Caplevel,Changelevel);//存放落后单体 |
| | | /*for (Batt_Maint_Dealarm b : listB) { |
| | | System.out.println(b.getTstop()); |
| | | }*/ |
| | | System.out.println("落后单体的数据量:"+listB.size()); |
| | | ArrayList sql_str=badBatt_Moninsert(listB); |
| | | boolean b=MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str); |
| | | System.out.println("是否将落后单体插入到表中"+b); |
| | | //System.out.println("number:"+listB.size()); |
| | | boolean bflag=badBatt_Mon_flagdelete(m_ConnPool); |
| | | System.out.println("清空落后单体表示表"+bflag); |
| | | |
| | | ArrayList sql_str1=Batt_insertalarmSql(listB,m_ConnPool);//告警插入语句 |
| | | //System.out.println(sql_str1); |
| | | boolean bla=MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str1); |
| | | System.out.println("将落后告警体插入到告警表中:"+bla); |
| | | |
| | | } |
| | | |
| | | //修改进程监控表中的实时时间 |
| | | public boolean processupdateSql(Date nowdate,String ProcessName,MySqlPool m_ConnPool_){ |
| | | String sql=" update "+Mysql_database_param.web_site+Mysql_database_param.tb_Process_survey+" " |
| | | +" set ProcessTime='"+BadBatt_thread.sdf.format(nowdate) |
| | | +"' where ProcessName='"+ProcessName+"'"; |
| | | Connection conn=m_ConnPool_.getConn(); |
| | | //System.out.println(sql); |
| | | boolean bl=m_ConnPool_.sqlMysqlUpdate(conn, sql); |
| | | return bl; |
| | | List<BadbattMon> list=new ArrayList<>(); |
| | | if(stopList!=null&&stopList.size()>0){ |
| | | for(int i=0;i<stopList.size();i++){ |
| | | Batttestdatastop stop=stopList.get(i); |
| | | if(i%12==0){ |
| | | //修改进程监控表中的实时时间 |
| | | boolean b=processupdateSql(new Date(),Mysql_database_param.BMS_FBSDEV_BADBATT_MON, m_ConnPool); |
| | | } |
| | | STDAH=monCapStd; |
| | | MonomerVolType=monVolStd; |
| | | current=stop.getTest_curr(); |
| | | SumAH=stop.getTest_cap(); |
| | | MaxMonomerVol=maxVol;//组内最大电压 |
| | | MonomerVol=stop.getMon_vol(); |
| | | //小时率 |
| | | hourRate=BattCapFactory.GetHourRate(STDAH, current); |
| | | //实际容量 |
| | | realCap=BattCapFactory.GetMonomerCap(STDAH, hourRate, SumAH, MaxMonomerVol, MonomerVol, MonomerVolType, BattCapFactory.CapType_Real); |
| | | int flag=1;//标识位 |
| | | flag=BattCapFactory.JudgeAlarm(realCap, aparam,Cparam, STDAH); |
| | | BadbattMon badMon=new BadbattMon(); |
| | | badMon.setBattgroupid(stop.getBattGroupId()); |
| | | badMon.setMonNum(stop.getMon_num()); |
| | | badMon.setRecordNum(stop.getRecord_num()); |
| | | badMon.setTestStarttime(stop.getTest_starttime()); |
| | | badMon.setGroupVol(stop.getGroup_vol()); |
| | | badMon.setTestCurr(stop.getTest_curr()); |
| | | badMon.setMonVol(stop.getMon_vol()); |
| | | badMon.setStdcap((float) monCapStd); |
| | | badMon.setRealCap((float) realCap); |
| | | badMon.setNote(String.valueOf(flag)); |
| | | switch (flag) { |
| | | case 1:badMon.setFlag(3);break; |
| | | case BattCapFactory.Alarm_CapAlarm:badMon.setFlag(2);break; |
| | | case BattCapFactory.Alarm_CapChange:badMon.setFlag(1);break; |
| | | } |
| | | list.add(badMon); |
| | | } |
| | | }else { |
| | | BattInf binf=new BattInf(); |
| | | binf.setBattGroupId(battGroupId); |
| | | binf.setMonCapStd((float) monCapStd); |
| | | insertUnjudge(binf,"2",4,m_ConnPool); |
| | | } |
| | | try { |
| | | Thread.sleep(10); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | //获取当前天23点59分59秒的time |
| | | public long getDateTIme() { |
| | | Calendar calendar2 = Calendar.getInstance(); |
| | | |
| | | calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH), |
| | | 23,59, 0); |
| | | Date endOfDate = calendar2.getTime(); |
| | | //String time=BadBatt_thread.sdf.format(endOfDate); |
| | | long time=endOfDate.getTime(); |
| | | return time; |
| | | |
| | | //4.将数据插入badBattMon表 |
| | | public void insertBadBatt(List<BadbattMon> badList,MySqlPool m_ConnPool) { |
| | | ArrayList sql_str=new ArrayList(); |
| | | String insertbadbatt_monSql="insert into "+bad_mon+" " |
| | | + "(" |
| | | + "battgroupid," |
| | | + "mon_num," |
| | | + "record_num," |
| | | + "test_starttime," |
| | | + "group_vol," |
| | | + "test_curr," |
| | | + "mon_vol," |
| | | + "real_cap," |
| | | + "stdcap," |
| | | + "note," |
| | | + "flag" |
| | | + ") " |
| | | + " values "; |
| | | for(int i=0;i<badList.size();i++){ |
| | | BadbattMon badMon=badList.get(i); |
| | | if(i>0){ |
| | | insertbadbatt_monSql+=" , "; |
| | | }else { |
| | | String deletebadbatt_monSql="DELETE FROM "+bad_mon+" WHERE battgroupid="+badMon.getBattgroupid()+" "; |
| | | sql_str.add(deletebadbatt_monSql); |
| | | } |
| | | insertbadbatt_monSql=insertbadbatt_monSql |
| | | + "(" |
| | | + badMon.getBattgroupid()+"," |
| | | + badMon.getMonNum()+"," |
| | | + badMon.getRecordNum()+"," |
| | | + "'"+badMon.getTestStarttime()+"'," |
| | | + badMon.getGroupVol()+"," |
| | | + badMon.getTestCurr()+"," |
| | | + badMon.getMonVol()+"," |
| | | + badMon.getRealCap()+"," |
| | | + badMon.getStdcap()+"," |
| | | + badMon.getNote()+"," |
| | | + badMon.getFlag()+"" |
| | | + ")";//如果对应是字符几个带上单引号 |
| | | } |
| | | sql_str.add(insertbadbatt_monSql); |
| | | MySqlPool.makeManualCommit(m_ConnPool.getConn(), sql_str); |
| | | } |
| | | //山西太供最新版实际容量算法 |
| | | public void serchBadBattandInsert_TG(){ |
| | | //1.查询所有的电池组 |
| | | List<BattInf> binfList=getAllBinf(m_ConnPool); |
| | | //2.查询每个电池组的有效放电记录,如果找不到将整组单体标记为"无法判断",将 |
| | | for (BattInf binf : binfList) { |
| | | Batttestdata_inf tinf=getEffectiveTinf(binf.getBattGroupId(),m_ConnPool); |
| | | if(tinf!=null) { |
| | | //3.计算每个单体的实际容量并判断是否为告警或更换或优秀(1,2,3) |
| | | List<Batttestdatastop> stopList=Batt_selectBadSql(binf.getBattGroupId(), tinf.getTest_record_count(),tinf.getRecord_num(),BadBatt_thread.sdf.format(tinf.getRecord_time()), m_ConnPool ); |
| | | //计算出落后单体 |
| | | List<BadbattMon> badList=calculatorBadBatt(binf.getBattGroupId(),binf.getMonCapStd(),binf.getMonVolStd(),tinf.getMax_monvol(),stopList,m_ConnPool); |
| | | //4.将数据插入badBattMon表 |
| | | insertBadBatt(badList,m_ConnPool); |
| | | }else { |
| | | //标记为无法判断:flag为4并插入 |
| | | insertUnjudge(binf,"0",4,m_ConnPool); |
| | | } |
| | | } |
| | | } |
| | | public void run(){ |
| | | System.out.println("启动定时查询落后单体信息表和落后告警插入表!------badbatt_thread启动"); |
| | | serchBadBattandInsert(); |
| | | serchBadBattandInsert_TG(); |
| | | //long tenHouerAgo=(new Date()).getTime()-12*60*60*1000; |
| | | while(true){ |
| | | badBatt_Mon_flagcreate(m_ConnPool); |
| | |
| | | //修改进程监控表中的实时时间 |
| | | boolean b=processupdateSql(new Date(),Mysql_database_param.BMS_FBSDEV_BADBATT_MON, m_ConnPool); |
| | | if(bl){ |
| | | serchBadBattandInsert(); |
| | | serchBadBattandInsert_TG(); |
| | | }else{ |
| | | try { |
| | | Thread.sleep(60*1000); |
| | |
| | | long nowtime=new Date().getTime(); |
| | | //System.out.println(getDateTIme()+" "+nowtime); |
| | | if(Math.abs((getDateTIme()-nowtime))<30*1000) { |
| | | serchBadBattandInsert(); |
| | | serchBadBattandInsert_TG(); |
| | | } |
| | | /*if((nowtime-tenHouerAgo)>=12*60*60*1000){ |
| | | serchBadBattandInsert(); |
| | |
| | | BadBatt_thread bd_t=new BadBatt_thread(mPool); |
| | | //bd_t.Batt_selecteffectiveBatt(); |
| | | //bd_t.start(); |
| | | bd_t.serchBadBattandInsert(); |
| | | |
| | | |
| | | bd_t.serchBadBattandInsert_TG(); |
| | | } |
| | | } |