package com.whyc.service;
|
|
import com.whyc.dto.DevA200AlarmDto;
|
import com.whyc.mapper.CallBack;
|
import com.whyc.pojo.db_alarm.DevLithiumAlarmDataYear;
|
import com.whyc.pojo.db_lithium_testdata.BattLithiumTestData;
|
import com.whyc.util.ThreadLocalUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
@Service
|
public class SubTablePageInfoService {
|
@Autowired
|
private MybatisSqlExecuteService sqlExecuteService;
|
//获取设备某次记录详细的单体放电过程
|
public List<BattLithiumTestData> 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 record_num asc ";
|
List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
|
@Override
|
public List getResults(ResultSet rs) throws SQLException {
|
List<BattLithiumTestData> list=new ArrayList<>();
|
while (rs.next()){
|
BattLithiumTestData tdata=new BattLithiumTestData();
|
tdata.setNum(rs.getInt("num"));
|
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(rs.getInt("record_num"));
|
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.setMonNum(rs.getInt("mon_num"));
|
tdata.setMonVol(rs.getDouble("mon_vol"));
|
tdata.setMonTmp(rs.getDouble("mon_tmp"));
|
tdata.setMonCurr(rs.getDouble("mon_curr"));
|
tdata.setMonCap(rs.getDouble("mon_cap"));
|
tdata.setMonWh(rs.getDouble("mon_wh"));
|
tdata.setMonState(rs.getString("mon_state"));
|
tdata.setMonFault(rs.getString("mon_fault"));
|
tdata.setNeedTest(rs.getInt("need_test"));
|
list.add(tdata);
|
}
|
return list;
|
}
|
});
|
return list;
|
}
|
|
//获取设备某次记录详细的单体放电过程
|
public List<BattLithiumTestData> getTdataByIdWithListA200(Integer devId, Integer testRecordCount) {
|
String sql="select * from db_lithium_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;
|
BattLithiumTestData 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 BattLithiumTestData();
|
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(DevA200AlarmDto dto) {
|
String sql="select count(distinct num) as number from db_alarm." +dto.getTableName()
|
+" where 1=1 ";
|
|
if(dto.getStartTime()!=null){
|
sql+=" and alm_starttime >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
|
}
|
if(dto.getEndTime()!=null){
|
sql+=" and alm_endtime <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
|
}
|
if(dto.getDevType()!=null){
|
sql+=" and FLOOR(dev_id/100000000)="+dto.getDevType();
|
}
|
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 {
|
LinkedList<Object> temp = new LinkedList<>();
|
try {
|
while (rs.next())
|
temp.add(rs.getInt("number"));
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
return temp;
|
}
|
});
|
int num =0;
|
if(list!=null){
|
num= (int) list.get(0);
|
}
|
return num;
|
}
|
//查询devalm历史告警
|
public List getListDevAlm(DevA200AlarmDto dto){
|
String sql="select * from db_alarm." +dto.getTableName()
|
+" where 1=1 ";
|
|
if(dto.getStartTime()!=null){
|
sql+=" and alm_starttime >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
|
}
|
if(dto.getEndTime()!=null){
|
sql+=" and alm_endtime <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
|
}
|
if(dto.getDevType()!=null){
|
sql+=" and FLOOR(dev_id/100000000)="+dto.getDevType();
|
}
|
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 limit "+dto.getLimitStart()+","+dto.getLimitEnd()+" ";
|
List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
|
@Override
|
public List getResults(ResultSet rs) throws SQLException {
|
List<DevLithiumAlarmDataYear> list=new ArrayList<>();
|
while (rs.next()){
|
DevLithiumAlarmDataYear dataYear=new DevLithiumAlarmDataYear();
|
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<BattLithiumTestData> 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 list=new ArrayList<>();
|
List<Float> monVols=null;
|
List<Float> monCurrs=null;
|
List<Float> monCaps=null;
|
List<Float> monWhs=null;
|
List<Integer> monNums=null;
|
BattLithiumTestData 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 BattLithiumTestData();
|
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;
|
}
|
}
|