| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.whyc.dto.DalmDto; |
| | | import com.whyc.mapper.CallBack; |
| | | import com.whyc.pojo.db_alarm.DevalarmData; |
| | | import com.whyc.pojo.db_alarm.DevalarmDataYear; |
| | | import com.whyc.pojo.db_batt_testdata.BatttestdataId; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | public List<BatttestdataId> getTdataById(Integer devId, Integer testRecordCount) { |
| | | String sql="select * from db_batt_testdata.tb_batttestdata_" +devId |
| | | +" where need_test=1 and test_record_count="+testRecordCount+" "; |
| | | sql+=" ORDER BY test_starttime asc "; |
| | | System.out.println(sql); |
| | | sql+=" ORDER BY record_num asc "; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | |
| | | tdata.setMonCurr(rs.getDouble("mon_curr")); |
| | | tdata.setMonCap(rs.getDouble("mon_cap")); |
| | | tdata.setMonWh(rs.getDouble("mon_wh")); |
| | | tdata.setMonState(rs.getInt("mon_state")); |
| | | tdata.setMonState(rs.getString("mon_state")); |
| | | tdata.setMonFault(rs.getString("mon_fault")); |
| | | tdata.setNeedTest(rs.getInt("need_test")); |
| | | list.add(tdata); |
| | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | /*//查询DevAlm历史告警数量 |
| | | public int getCountForDevAlm(DevAlarmHisDto alm) { |
| | | String sql="select count(distinct num) as number from db_ckpwrdev_alarm." +alm.getRecordYear() |
| | | //获取设备某次记录详细的单体放电过程 |
| | | public List<BatttestdataId> getTdataByIdWithListA200(Integer devId, Integer testRecordCount) { |
| | | String sql="select * from db_batt_testdata.tb_batttestdata_" +devId |
| | | +" where need_test=1 and test_record_count="+testRecordCount+" "; |
| | | sql+=" ORDER BY record_num asc "; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List list=new ArrayList<>(); |
| | | List<Float> monVols=null; |
| | | List<Integer> monNums=null; |
| | | BatttestdataId tdata=null; |
| | | int num=0; |
| | | try { |
| | | while (rs.next()){ |
| | | int monNum=rs.getInt("mon_num"); |
| | | float monvol=rs.getFloat("mon_vol"); |
| | | int recordNum=rs.getInt("record_num"); |
| | | if(num!=recordNum){ |
| | | if(num!=0){ |
| | | tdata.setMonVols(monVols); |
| | | tdata.setMonNums(monNums); |
| | | list.add(tdata); |
| | | } |
| | | tdata=new BatttestdataId(); |
| | | monVols=new ArrayList<>(); |
| | | monNums=new ArrayList<>(); |
| | | tdata.setDevId(rs.getInt("dev_id")); |
| | | tdata.setBattIdx(rs.getInt("batt_idx")); |
| | | tdata.setTestRecordCount(rs.getInt("test_record_count")); |
| | | tdata.setTestType(rs.getInt("test_type")); |
| | | tdata.setRecordNum(recordNum); |
| | | tdata.setTestStarttime(rs.getTimestamp("test_starttime")); |
| | | tdata.setRecordTime(rs.getTimestamp("record_time")); |
| | | tdata.setTestTimelong(rs.getInt("test_timelong")); |
| | | tdata.setGroupVol(rs.getDouble("group_vol")); |
| | | tdata.setTestCurr(rs.getDouble("test_curr")); |
| | | tdata.setTestCap(rs.getDouble("test_cap")); |
| | | tdata.setNeedTest(rs.getInt("need_test")); |
| | | tdata.setMaxTemp(rs.getFloat("max_temp")); |
| | | tdata.setMinTemp(rs.getFloat("min_temp")); |
| | | num=recordNum; |
| | | } |
| | | monVols.add(monvol); |
| | | monNums.add(monNum); |
| | | } |
| | | tdata.setMonVols(monVols); |
| | | tdata.setMonNums(monNums); |
| | | list.add(tdata); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | //查询DevAlm历史告警数量 |
| | | public int getCountForDevAlm(DalmDto dto) { |
| | | String sql="select count(distinct num) as number from db_alarm." +dto.getTableName() |
| | | +" where 1=1 "; |
| | | |
| | | if(alm.getAlmStartTime()!=null){ |
| | | sql+=" and alm_starttime >='"+ DateUtil.format_YYYY_MM_DD_HH_MM_SS(alm.getAlmStartTime())+"' "; |
| | | if(dto.getStartTime()!=null){ |
| | | sql+=" and alm_starttime >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' "; |
| | | } |
| | | if(alm.getAlmEndTime()!=null){ |
| | | sql+=" and alm_endtime <='"+DateUtil.format_YYYY_MM_DD_HH_MM_SS(alm.getAlmEndTime())+"' "; |
| | | if(dto.getEndTime()!=null){ |
| | | sql+=" and alm_endtime <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' "; |
| | | } |
| | | if(alm.getDevType()!=0){ |
| | | sql+=" and dev_type="+alm.getDevType(); |
| | | if(dto.getDevType()!=null){ |
| | | sql+=" and FLOOR(dev_id/100000000)="+dto.getDevType(); |
| | | } |
| | | if(alm.getAlmLevel()!=0){ |
| | | sql+=" and alm_level="+alm.getAlmLevel(); |
| | | if(dto.getDevId()!=null){ |
| | | sql+=" and dev_id="+dto.getDevId(); |
| | | } |
| | | if(dto.getAlmId()!=null){ |
| | | sql+=" and alm_id="+dto.getAlmId(); |
| | | } |
| | | sql+=" and dev_id in (" + |
| | | " SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" + |
| | | " where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" + |
| | | " and uid="+dto.getUid()+ |
| | | ")"; |
| | | sql+=" order by alm_starttime desc "; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | |
| | | return num; |
| | | } |
| | | //查询devalm历史告警 |
| | | public List getListDevAlm(DevAlarmHisDto alm){ |
| | | String sql="select * from db_ckpwrdev_alarm." +alm.getRecordYear() |
| | | public List getListDevAlm(DalmDto dto){ |
| | | String sql="select * from db_alarm." +dto.getTableName() |
| | | +" where 1=1 "; |
| | | if(alm.getAlmStartTime()!=null){ |
| | | sql+=" and alm_starttime >='"+ DateUtil.format_YYYY_MM_DD_HH_MM_SS(alm.getAlmStartTime())+"' "; |
| | | |
| | | if(dto.getStartTime()!=null){ |
| | | sql+=" and alm_starttime >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' "; |
| | | } |
| | | if(alm.getAlmEndTime()!=null){ |
| | | sql+=" and alm_endtime <='"+DateUtil.format_YYYY_MM_DD_HH_MM_SS(alm.getAlmEndTime())+"' "; |
| | | if(dto.getEndTime()!=null){ |
| | | sql+=" and alm_endtime <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' "; |
| | | } |
| | | if(alm.getDevType()!=0){ |
| | | sql+=" and dev_type="+alm.getDevType(); |
| | | if(dto.getDevType()!=null){ |
| | | sql+=" and FLOOR(dev_id/100000000)="+dto.getDevType(); |
| | | } |
| | | if(alm.getAlmLevel()!=0){ |
| | | sql+=" and alm_level="+alm.getAlmLevel(); |
| | | if(dto.getDevId()!=null){ |
| | | sql+=" and dev_id="+dto.getDevId(); |
| | | } |
| | | sql+=" ORDER BY alm_starttime desc limit "+alm.getLimitStart()+","+alm.getLimitEnd()+" "; |
| | | if(dto.getAlmId()!=null){ |
| | | sql+=" and alm_id="+dto.getAlmId(); |
| | | } |
| | | sql+=" and dev_id in (" + |
| | | " SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" + |
| | | " where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" + |
| | | " and uid="+dto.getUid()+ |
| | | ")"; |
| | | sql+=" ORDER BY alm_starttime desc limit "+dto.getLimitStart()+","+dto.getLimitEnd()+" "; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List<CKPowerDevAlarmHistory> list=new ArrayList<>(); |
| | | List<DevalarmDataYear> list=new ArrayList<>(); |
| | | while (rs.next()){ |
| | | CKPowerDevAlarmHistory ph=new CKPowerDevAlarmHistory(); |
| | | ph.setNum(rs.getLong("num")); |
| | | ph.setPowerDeviceId(rs.getInt("power_device_id")); |
| | | ph.setAlmId(rs.getInt("alm_id")); |
| | | ph.setAlmName(rs.getString("alm_name")); |
| | | ph.setDevType(rs.getInt("dev_type")); |
| | | ph.setAlmLevel(rs.getInt("alm_level")); |
| | | ph.setAlmStartTime(rs.getTimestamp("alm_starttime")); |
| | | ph.setAlmEndTime(rs.getTimestamp("alm_endtime")); |
| | | ph.setAlmIsConfirmed(rs.getInt("alm_is_confirmed")); |
| | | ph.setAlmConfirmedTime(rs.getTimestamp("alm_confirmed_time")); |
| | | ph.setAlmClearedType(rs.getInt("alm_cleared_type")); |
| | | list.add(ph); |
| | | DevalarmDataYear dataYear=new DevalarmDataYear(); |
| | | dataYear.setNum(rs.getInt("num")); |
| | | dataYear.setDevId(rs.getInt("dev_id")); |
| | | dataYear.setAlmId(rs.getInt("alm_id")); |
| | | dataYear.setAlmSignalId(rs.getInt("alm_signal_id")); |
| | | dataYear.setAlmStarttime(rs.getTimestamp("alm_starttime")); |
| | | dataYear.setAlmValue(rs.getFloat("alm_value")); |
| | | dataYear.setAlmIsConfirmed(rs.getInt("alm_is_confirmed")); |
| | | dataYear.setConfirmedUid(rs.getInt("confirmed_uid")); |
| | | dataYear.setConfirmedTime(rs.getTimestamp("confirmed_time")); |
| | | dataYear.setAlmEndtime(rs.getTimestamp("alm_endtime")); |
| | | dataYear.setAlmClearedType(rs.getInt("alm_cleared_type")); |
| | | list.add(dataYear); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | //查询所有的历史时间表 |
| | | public List getDevAlmHisList() { |
| | | String sql="SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'tb_ckpowerdev_alarm_history_%'"; |
| | | |
| | | |
| | | public List<BatttestdataId> getTdataByIdWithListActm(Integer devId, Integer testRecordCount) { |
| | | String sql="select * from db_batt_testdata.tb_batttestdata_" +devId |
| | | +" where need_test=1 and test_record_count="+testRecordCount+" "; |
| | | sql+=" ORDER BY record_num asc "; |
| | | List list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List<String> list=new ArrayList<>(); |
| | | while (rs.next()){ |
| | | list.add(rs.getString("table_name")); |
| | | List list=new ArrayList<>(); |
| | | List<Float> monVols=null; |
| | | List<Float> monCurrs=null; |
| | | List<Float> monCaps=null; |
| | | List<Float> monWhs=null; |
| | | List<Integer> monNums=null; |
| | | BatttestdataId tdata=null; |
| | | int num=0; |
| | | try { |
| | | while (rs.next()){ |
| | | int monNum=rs.getInt("mon_num"); |
| | | float monvol=rs.getFloat("mon_vol"); |
| | | float monCurr=rs.getFloat("mon_curr"); |
| | | float monCap=rs.getFloat("mon_cap"); |
| | | float monWh=rs.getFloat("mon_wh"); |
| | | int recordNum=rs.getInt("record_num"); |
| | | |
| | | if(num!=recordNum){ |
| | | if(num!=0){ |
| | | tdata.setMonVols(monVols); |
| | | tdata.setMonNums(monNums); |
| | | tdata.setMonCurrs(monCurrs); |
| | | tdata.setMonCaps(monCaps); |
| | | tdata.setMonWhs(monWhs); |
| | | list.add(tdata); |
| | | } |
| | | tdata=new BatttestdataId(); |
| | | monVols=new ArrayList<>(); |
| | | monNums=new ArrayList<>(); |
| | | monCurrs=new ArrayList<>(); |
| | | monCaps=new ArrayList<>(); |
| | | monWhs=new ArrayList<>(); |
| | | tdata.setDevId(rs.getInt("dev_id")); |
| | | tdata.setBattIdx(rs.getInt("batt_idx")); |
| | | tdata.setTestRecordCount(rs.getInt("test_record_count")); |
| | | tdata.setTestType(rs.getInt("test_type")); |
| | | tdata.setRecordNum(recordNum); |
| | | tdata.setTestStarttime(rs.getTimestamp("test_starttime")); |
| | | tdata.setRecordTime(rs.getTimestamp("record_time")); |
| | | tdata.setTestTimelong(rs.getInt("test_timelong")); |
| | | tdata.setGroupVol(rs.getDouble("group_vol")); |
| | | tdata.setTestCurr(rs.getDouble("test_curr")); |
| | | tdata.setTestCap(rs.getDouble("test_cap")); |
| | | tdata.setNeedTest(rs.getInt("need_test")); |
| | | tdata.setMonTmp(rs.getDouble("mon_tmp")); |
| | | num=recordNum; |
| | | } |
| | | monVols.add(monvol); |
| | | monNums.add(monNum); |
| | | monCurrs.add(monCurr); |
| | | monCaps.add(monCap); |
| | | monWhs.add(monWh); |
| | | } |
| | | |
| | | tdata.setMonVols(monVols); |
| | | tdata.setMonNums(monNums); |
| | | tdata.setMonCurrs(monCurrs); |
| | | tdata.setMonCaps(monCaps); |
| | | tdata.setMonWhs(monWhs); |
| | | list.add(tdata); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | }*/ |
| | | |
| | | } |
| | | } |