whyclxw
5 天以前 210efc8a9b3d3c5a6a3f453dd4ce14f735d63f9b
src/main/java/com/whyc/service/SubTablePageInfoService.java
@@ -3,20 +3,26 @@
import com.whyc.dto.AlmHis.BattAlmPar;
import com.whyc.dto.AlmHis.DevAlmPar;
import com.whyc.dto.AlmHis.PwrAlmPar;
import com.whyc.dto.Real.CompareDto;
import com.whyc.dto.Real.QuarterDto;
import com.whyc.dto.AnalysisAlm.ResAnalysis;
import com.whyc.dto.Real.*;
import com.whyc.dto.Statistic.QuarterPwr7Res;
import com.whyc.mapper.CallBack;
import com.whyc.pojo.db_alarm.BattalarmDataHistory;
import com.whyc.pojo.db_alarm.DevalarmDataHistory;
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
import com.whyc.pojo.db_data_history.BattRealdataId;
import com.whyc.pojo.db_data_history.PwrdevHistorydataId;
import com.whyc.pojo.db_pwrdev_alarm.PwrdevAlarmHistory;
import com.whyc.util.ActionUtil;
import com.whyc.util.ThreadLocalUtil;
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 {
@@ -198,7 +204,7 @@
                    data.setProvice(rs.getString("provice"));
                    data.setCity(rs.getString("city"));
                    data.setCountry(rs.getString("country"));
                    data.setBattGroupName(rs.getString("battgroup_name"));
                    data.setBattgroupName(rs.getString("battgroup_name"));
                    list.add(data);
                }
                return list;
@@ -316,6 +322,7 @@
                    ph.setNum(rs.getLong("num"));
                    ph.setDevId(rs.getInt("dev_id"));
                    ph.setDevIp(rs.getString("dev_ip"));
                    ph.setAlmId(rs.getInt("alm_id"));
                    ph.setAlmLevel(rs.getInt("alm_level"));
                    ph.setAlmStartTime(rs.getTimestamp("alm_start_time"));
                    ph.setAlmEndTime(rs.getTimestamp("alm_end_time"));
@@ -529,7 +536,7 @@
        });
       return list;
    }
    //找这次放电的最后一笔数据
    //找这次放电的指定一笔数据
    public List<BatttestdataId> getLastDataByBattgroupId(Integer battgroupId, Integer testRecordCount, Integer recordNum) {
        String sql="select   distinct * from db_batt_testdata.tb_batttestdata_"+battgroupId
                +" where test_record_count="+testRecordCount+" and record_num="+recordNum+ " order by mon_num asc";
@@ -557,4 +564,424 @@
        });
        return list;
    }
    //系统概览获取半小时核容设备信息(组端信息取一个单体信息即可)
    public List<BattHisRealDto> getHalfHourBattDevData(String tableName,Integer granularity,String halfHourAgoTime) {
        String sql="select  distinct mon_num,record_time,group_vol,online_vol,group_curr,group_tmp,load_curr " +
                "from (select a.*, (@i:= @i+1) as number " +
                "     from (select * from "+tableName+" "+
                "                    where record_time>='"+halfHourAgoTime+"' and mon_num=1) a, " +
                "                   (select @i:=0) b) c "+
                " where c.number%"+granularity+"=0 or c.number=1 ";
        sql+=" order by record_time asc";
        List<BattHisRealDto> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<BattHisRealDto> list=new ArrayList<>();
                while (rs.next()){
                    BattHisRealDto data=new BattHisRealDto();
                    data.setRecordTime(rs.getTimestamp("record_time"));
                    data.setGroupVol(rs.getFloat("group_vol"));
                    data.setOnlineVol(rs.getFloat("online_vol"));
                    data.setGroupCurr(rs.getFloat("group_curr"));
                    data.setGroupTmp(rs.getFloat("group_tmp"));
                    data.setLoadCurr(rs.getFloat("load_curr"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    //系统概览获取半小时交流输入统计
    public List<PwrHisRealAcInDto> getHalfHourPwrHisAcinData(String tableName,Integer granularity,Date recordDatetime,Date recordDatetime1) {
        String sql=" select  distinct record_datetime,acin1_vola,acin1_volb,acin1_volc,acin2_vola,acin2_volb,acin2_volc " +
                " ,acin1_curra,acin1_currb,acin1_currc,acin2_curra,acin2_currb,acin2_currc  " +
                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+
                "' and record_num%"+granularity+"=0 or record_num=1 or record_num=100 ";
        sql+=" order by record_datetime asc";
        List<PwrHisRealAcInDto> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<PwrHisRealAcInDto> list=new ArrayList<>();
                while (rs.next()){
                    PwrHisRealAcInDto data=new PwrHisRealAcInDto();
                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
                    data.setAcin1Vola(rs.getFloat("acin1_vola"));
                    data.setAcin1Volb(rs.getFloat("acin1_volb"));
                    data.setAcin1Volc(rs.getFloat("acin1_volc"));
                    data.setAcin2Vola(rs.getFloat("acin2_vola"));
                    data.setAcin2Volb(rs.getFloat("acin2_volb"));
                    data.setAcin2Volc(rs.getFloat("acin2_volc"));
                    data.setAcin1Curra(rs.getFloat("acin1_curra"));
                    data.setAcin1Currb(rs.getFloat("acin1_currb"));
                    data.setAcin1Currc(rs.getFloat("acin1_currc"));
                    data.setAcin2Curra(rs.getFloat("acin2_curra"));
                    data.setAcin2Currb(rs.getFloat("acin2_currb"));
                    data.setAcin2Currc(rs.getFloat("acin2_currc"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    public List<PwrHisRealDcoutInDto> getHalfHourPwrHisDcoutData(String tableName,Integer granularity,String halfHourAgoTime) {
        String sql="select  distinct * " +
                "from (select a.*, (@i:= @i+1) as number " +
                "     from (select * from "+tableName+" "+
                "                    where record_datetime>='"+halfHourAgoTime+"') a, " +
                "                   (select @i:=0) b) c "+
                " where c.number%"+granularity+"=0 or c.number=1 ";
        sql+=" order by record_datetime asc";
        List<PwrHisRealDcoutInDto> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<PwrHisRealDcoutInDto> list=new ArrayList<>();
                while (rs.next()){
                    PwrHisRealDcoutInDto data=new PwrHisRealDcoutInDto();
                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
                    data.setMOutputvol(rs.getFloat("m_outputvol"));
                    data.setM1Outcurr(rs.getFloat("m1_outcurr"));
                    data.setM2Outcurr(rs.getFloat("m2_outcurr"));
                    data.setM3Outcurr(rs.getFloat("m3_outcurr"));
                    data.setM4Outcurr(rs.getFloat("m4_outcurr"));
                    data.setM5Outcurr(rs.getFloat("m5_outcurr"));
                    data.setM6Outcurr(rs.getFloat("m6_outcurr"));
                    data.setM7Outcurr(rs.getFloat("m7_outcurr"));
                    data.setM8Outcurr(rs.getFloat("m8_outcurr"));
                    data.setM9Outcurr(rs.getFloat("m9_outcurr"));
                    data.setM10Outcurr(rs.getFloat("m10_outcurr"));
                    data.setM11Outcurr(rs.getFloat("m11_outcurr"));
                    data.setM12Outcurr(rs.getFloat("m12_outcurr"));
                    data.setM13Outcurr(rs.getFloat("m13_outcurr"));
                    data.setM14Outcurr(rs.getFloat("m14_outcurr"));
                    data.setM15Outcurr(rs.getFloat("m15_outcurr"));
                    data.setM16Outcurr(rs.getFloat("m16_outcurr"));
                    data.setM1OutVol(rs.getFloat("m1_out_vol"));
                    data.setM2OutVol(rs.getFloat("m2_out_vol"));
                    data.setM3OutVol(rs.getFloat("m3_out_vol"));
                    data.setM4OutVol(rs.getFloat("m4_out_vol"));
                    data.setM5OutVol(rs.getFloat("m5_out_vol"));
                    data.setM6OutVol(rs.getFloat("m6_out_vol"));
                    data.setM7OutVol(rs.getFloat("m7_out_vol"));
                    data.setM8OutVol(rs.getFloat("m8_out_vol"));
                    data.setM9OutVol(rs.getFloat("m9_out_vol"));
                    data.setM10OutVol(rs.getFloat("m10_out_vol"));
                    data.setM11OutVol(rs.getFloat("m11_out_vol"));
                    data.setM12OutVol(rs.getFloat("m12_out_vol"));
                    data.setM13OutVol(rs.getFloat("m13_out_vol"));
                    data.setM14OutVol(rs.getFloat("m14_out_vol"));
                    data.setM15OutVol(rs.getFloat("m15_out_vol"));
                    data.setM16OutVol(rs.getFloat("m16_out_vol"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    //历史测试记录具体某一次放电数据详情
    public List<BatttestdataId> getTinfDataWithTestRecordCount(String tableName, Integer testRecordCount, Integer recordNum, Integer granularity) {
        String sql="select distinct * from "+tableName+" "+
                " where test_record_count="+testRecordCount+" " +
                " and  record_num%"+granularity+"=0 or record_num=1 or record_num="+recordNum;
        sql+=" order by record_time asc";
        List<BatttestdataId> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<BatttestdataId> list=new ArrayList<>();
                while (rs.next()){
                    BatttestdataId data=new BatttestdataId();
                    data.setNum(rs.getInt("num"));
                    data.setBattgroupId(rs.getInt("battgroup_id"));
                    data.setTestRecordCount(rs.getInt("test_record_count"));
                    data.setTestType(rs.getInt("test_type"));
                    data.setRecordNum(rs.getInt("record_num"));
                    data.setDataNew(rs.getInt("data_new"));
                    data.setDataAvailable(rs.getInt("data_available"));
                    data.setTestTimelong(rs.getInt("test_timelong"));
                    data.setTestCurr(rs.getFloat("test_curr"));
                    data.setTestCap(rs.getFloat("test_cap"));
                    data.setMonNum(rs.getInt("mon_num"));
                    data.setMonVol(rs.getFloat("mon_vol"));
                    data.setMonTmp(rs.getFloat("mon_tmp"));
                    data.setMonRes(rs.getFloat("mon_res"));
                    data.setTestStarttime(rs.getTimestamp("test_starttime"));
                    data.setRecordTime(rs.getTimestamp("record_time"));
                    data.setGroupVol(rs.getFloat("group_vol"));
                    data.setOnlineVol(rs.getFloat("online_vol"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    //判断电池组历史实时表是否存在
    public int judgeTable_realdata( String table){
        String sql="select count(*) as tableNum " +
                "        from INFORMATION_SCHEMA.TABLES " +
                "        where TABLE_SCHEMA = 'db_data_history' " +
                "          and TABLE_NAME = 'tb_batt_realdata_"+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 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  " +
                "               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)+"' "+
                "               and (record_num-"+minRecordNum+")%"+granularity+"=0 or record_num="+maxRecordNum+" or record_num="+minRecordNum ;
        List<RealDateDTO> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<RealDateDTO> list=new ArrayList<>();
                while (rs.next()){
                    RealDateDTO ph=new RealDateDTO();
                    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"));
                    list.add(ph);
                }
                return list;
            }
        });
        return list;
    }
    //电池数据历史实时处理(预警分析)
    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)+"' " +
                "               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<ResAnalysis> list=new ArrayList<>();
                while (rs.next()){
                    ResAnalysis ph=new ResAnalysis();
                    ph.setRecordTime(rs.getTimestamp("record_time"));
                    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;
            }
        });
        return list;
    }
    //获取指定时间段内最大最小recordNum确保数据的完整
    public List getMaxAndMinRecordNum(BattRealdataId realdata) {
        String sql="select max(record_num) as maxRecordNum,min(record_num) as minRecordNum " +
                " 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)+"'  " +
                " limit 1";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List list = new ArrayList<>();
                while (rs.next()) {
                    list.add(rs.getInt("maxRecordNum"));
                    list.add(rs.getInt("minRecordNum"));
                }
                return list;
            }
           });
         return list;
    }
    //1.2.7优良电源统计上一季度的电源某一属性和参数阈值超过的次数
    public List<PwrdevHistorydataId> getPwrQuarter7(String tableName,List<String> propertyNameList) {
        String result = propertyNameList.stream().collect(Collectors.joining(","));
        String sql=" select  distinct record_datetime,"+result+" " +
                " from "+tableName+" " ;
        sql+=" order by record_datetime asc";
        List<PwrdevHistorydataId> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<PwrdevHistorydataId> list=new ArrayList<>();
                while (rs.next()){
                    PwrdevHistorydataId data=new PwrdevHistorydataId();
                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
                    for (int i=0;i<propertyNameList.size();i++){
                        try {
                            Float value = rs.getFloat(propertyNameList.get(i));
                            String propertyName = ActionUtil.toCamelCase(propertyNameList.get(i));
                            Field fieldValue = PwrdevHistorydataId.class.getDeclaredField(propertyName);
                            fieldValue.setAccessible(true);
                            fieldValue.set(data,value);
                        } catch (NoSuchFieldException e) {
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }
                    }
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    //获取具体的放电数据
    public List<BatttestdataId> exportTinfDataByTestRecordCount(Integer battgroupId, Integer testRecordCount, String tableName) {
        String sql="select distinct * from "+tableName+" "+
                " where test_record_count="+testRecordCount;
        sql+=" order by record_time asc";
        List<BatttestdataId> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<BatttestdataId> list=new ArrayList<>();
                while (rs.next()){
                    BatttestdataId data=new BatttestdataId();
                    data.setNum(rs.getInt("num"));
                    data.setBattgroupId(rs.getInt("battgroup_id"));
                    data.setTestRecordCount(rs.getInt("test_record_count"));
                    data.setTestType(rs.getInt("test_type"));
                    data.setRecordNum(rs.getInt("record_num"));
                    data.setDataNew(rs.getInt("data_new"));
                    data.setDataAvailable(rs.getInt("data_available"));
                    data.setTestTimelong(rs.getInt("test_timelong"));
                    data.setTestCurr(rs.getFloat("test_curr"));
                    data.setTestCap(rs.getFloat("test_cap"));
                    data.setMonNum(rs.getInt("mon_num"));
                    data.setMonVol(rs.getFloat("mon_vol"));
                    data.setMonTmp(rs.getFloat("mon_tmp"));
                    data.setMonRes(rs.getFloat("mon_res"));
                    data.setTestStarttime(rs.getTimestamp("test_starttime"));
                    data.setRecordTime(rs.getTimestamp("record_time"));
                    data.setGroupVol(rs.getFloat("group_vol"));
                    data.setOnlineVol(rs.getFloat("online_vol"));
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
}