| | |
| | | import com.whyc.dto.AlmHis.BattAlmPar; |
| | | import com.whyc.dto.AlmHis.DevAlmPar; |
| | | import com.whyc.dto.AlmHis.PwrAlmPar; |
| | | import com.whyc.dto.AnalysisAlm.ResAnalysis; |
| | | import com.whyc.dto.Real.*; |
| | | import com.whyc.dto.Statistic.QuarterPwr7Res; |
| | | import com.whyc.mapper.CallBack; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class SubTablePageInfoService { |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | //判断历史实时表是否存在 |
| | | //判断电池组历史实时表是否存在 |
| | | public int judgeTable_realdata( String table){ |
| | | String sql="select count(*) as tableNum " + |
| | | " from INFORMATION_SCHEMA.TABLES " + |
| | |
| | | } |
| | | return tableNum; |
| | | } |
| | | |
| | | //判断电源历史实时表是否存在 |
| | | public int judgeTable_pwrhis( String table){ |
| | | String sql="select count(*) as tableNum " + |
| | | " from INFORMATION_SCHEMA.TABLES " + |
| | | " where TABLE_SCHEMA = 'db_data_history' " + |
| | | " and TABLE_NAME = 'tb_pwrdev_historydata_"+table+"'"; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | LinkedList<Object> temp = new LinkedList<>(); |
| | | try { |
| | | while (rs.next()) |
| | | temp.add(rs.getInt("tableNum")); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return temp; |
| | | } |
| | | }); |
| | | int tableNum =0; |
| | | if(list!=null){ |
| | | tableNum= (int) list.get(0); |
| | | } |
| | | return tableNum; |
| | | } |
| | | //电池数据历史实时处理 |
| | | public List<RealDateDTO> getBattRealDataHis(BattRealdataId realdata, int granularity,Integer maxRecordNum,Integer minRecordNum) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | |
| | | return list; |
| | | } |
| | | //电池数据历史实时处理(预警分析) |
| | | public List<RealDateDTO> getBattHisRealInAlm(BattRealdataId realdata) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | public List<ResAnalysis> getBattHisRealInAlm(BattRealdataId realdata, Map<String,Integer> battMap) { |
| | | String result = String.join(",", battMap.keySet()); |
| | | String sql=" select record_time,"+result+" " + |
| | | " from db_data_history.tb_batt_realdata_"+realdata.getTableName()+" " + |
| | | " where record_time >= '"+ThreadLocalUtil.format(realdata.getRecordTime(),1)+"' " + |
| | | " and record_time <= '"+ThreadLocalUtil.format(realdata.getRecordTime1(),1)+"' "; |
| | | List<RealDateDTO> list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | " and record_time <= '"+ThreadLocalUtil.format(realdata.getRecordTime1(),1)+"' " + |
| | | " order by record_time asc,mon_num asc"; |
| | | List<ResAnalysis> list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List<RealDateDTO> list=new ArrayList<>(); |
| | | List<ResAnalysis> list=new ArrayList<>(); |
| | | while (rs.next()){ |
| | | RealDateDTO ph=new RealDateDTO(); |
| | | ResAnalysis ph=new ResAnalysis(); |
| | | ph.setRecordTime(rs.getTimestamp("record_time")); |
| | | ph.setGroupVol(rs.getFloat("group_vol")); |
| | | ph.setOnlineVol(rs.getFloat("online_vol")); |
| | | ph.setGroupCurr(rs.getFloat("group_curr")); |
| | | ph.setMonVol(rs.getFloat("mon_vol")); |
| | | ph.setMonTmp(rs.getFloat("mon_tmp")); |
| | | ph.setMonRes(rs.getFloat("mon_res")); |
| | | ph.setMonNum(rs.getInt("mon_num")); |
| | | ph.setRecordNum(rs.getInt("record_num")); |
| | | int i=1; |
| | | for (String key : battMap.keySet()) { |
| | | Integer dataType = battMap.get(key); |
| | | try { |
| | | String propertyType = "dataType"+(i); |
| | | Field fieldType = ResAnalysis.class.getDeclaredField(propertyType); |
| | | fieldType.setAccessible(true); |
| | | fieldType.set(ph,dataType); |
| | | |
| | | Float value = rs.getFloat(key); |
| | | String propertyName = "dataName"+(i); |
| | | Field fieldName = ResAnalysis.class.getDeclaredField(propertyName); |
| | | fieldName.setAccessible(true); // 如果字段是私有的,需要设置为可访问 |
| | | fieldName.set(ph,key); |
| | | |
| | | String propertyValue = "dataValue"+(i); |
| | | Field fieldValue = ResAnalysis.class.getDeclaredField(propertyValue); |
| | | fieldValue.setAccessible(true); |
| | | fieldValue.set(ph,value); |
| | | } catch (NoSuchFieldException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | i++; |
| | | } |
| | | list.add(ph); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | //电源数据历史实时处理(预警分析) |
| | | public List<ResAnalysis> getPwrHisRealInAlm(PwrdevHistorydataId pwrHis, Map<String,Integer> pwrMap) { |
| | | String result = String.join(",", pwrMap.keySet()); |
| | | String sql=" select record_datetime,"+result+" " + |
| | | " from db_data_history.tb_pwrdev_historydata_"+pwrHis.getTableName()+" " + |
| | | " where record_datetime >= '"+ThreadLocalUtil.format(pwrHis.getRecordDatetime(),1)+"' " + |
| | | " and record_datetime <= '"+ThreadLocalUtil.format(pwrHis.getRecordDatetime1(),1)+"' " + |
| | | " order by record_datetime asc "; |
| | | List<ResAnalysis> list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List<ResAnalysis> list=new ArrayList<>(); |
| | | while (rs.next()){ |
| | | ResAnalysis ph=new ResAnalysis(); |
| | | ph.setRecordTime(rs.getTimestamp("record_datetime")); |
| | | int i=1; |
| | | for (String key : pwrMap.keySet()) { |
| | | Integer dataType = pwrMap.get(key); |
| | | try { |
| | | String propertyType = "dataType"+(i); |
| | | Field fieldType = ResAnalysis.class.getDeclaredField(propertyType); |
| | | fieldType.setAccessible(true); |
| | | fieldType.set(ph,dataType); |
| | | |
| | | Float value = rs.getFloat(key); |
| | | String propertyName = "dataName"+(i); |
| | | Field fieldName = ResAnalysis.class.getDeclaredField(propertyName); |
| | | fieldName.setAccessible(true); // 如果字段是私有的,需要设置为可访问 |
| | | fieldName.set(ph,key); |
| | | |
| | | String propertyValue = "dataValue"+(i); |
| | | Field fieldValue = ResAnalysis.class.getDeclaredField(propertyValue); |
| | | fieldValue.setAccessible(true); |
| | | fieldValue.set(ph,value); |
| | | } catch (NoSuchFieldException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | i++; |
| | | } |
| | | list.add(ph); |
| | | } |
| | | return list; |