@@ -10,14 +10,17 @@ import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls ;
import com.njcn.gather.device.err.service.IPqErrSysDtlsService ;
import com.njcn.gather.device.script.pojo.po.SourceIssue ;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult ;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult ;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum ;
import lombok.RequiredArgsConstructor ;
import org.springframework.stereotype.Service ;
import java.lang.reflect.Field ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
/**
@@ -43,11 +46,11 @@ public class DetectionServiceImpl {
* 开始处理指标类型
* 一共20组数据, 开始处理格式
*/
public Map < String , Integer > text ( List < DevData > dev , Map < String , String > devIdMapComm , SourceIssue issue , DictDataEnum dataRule ) {
public Map < String , Integer > text ( List < DevData > dev , String errorSysId , Map < String , String > devIdMapComm , SourceIssue issue , DictDataEnum dataRule ) {
Map < String , List < DevData > > devDataMap = dev . stream ( ) . collect ( Collectors . groupingBy ( DevData : : getId ) ) ;
Map < String , Integer > stringBooleanMap = new LinkedHashMap < > ( ) ;
devDataMap . forEach ( ( ( key , value ) - > {
stringBooleanMap . put ( key , DetectionIndexProcessing ( value , devIdMapComm , dataRule , issue ) ) ;
stringBooleanMap . put ( key , DetectionIndexProcessing ( value , errorSysId , devIdMapComm , dataRule , issue ) ) ;
} ) ) ;
return stringBooleanMap ;
}
@@ -62,26 +65,29 @@ public class DetectionServiceImpl {
* @param sourceIssue 源下发的参数
* @return
*/
public Integer DetectionIndexProcessing ( List < DevData > dev , Map < String , String > devIdMapComm , DictDataEnum dataRule , SourceIssue sourceIssue ) {
public Integer DetectionIndexProcessing ( List < DevData > dev , String errorSysId , Map < String , String > devIdMapComm , DictDataEnum dataRule , SourceIssue sourceIssue ) {
PqErrSysParam . DetectionParam param = new PqErrSysParam . DetectionParam ( ) ;
param . setIndex ( sourceIssue . getIndex ( ) ) ;
param . setScriptId ( sourceIssue . getScriptId ( ) ) ;
param . setErrorSysId ( errorSysId ) ;
List < PqErrSysDtls > pqErrSysDtls = pqErrSysDtlsService . listPqErrSysDtlsByPqErrSysIdAndTypes ( param ) ;
switch ( " V " ) {
/**
* 频率
*/
case " FREQ " :
return isQualified ( dev , devIdMapComm , pqErrSysDtls , F , sourceIssue , dataRule , " FREQ " ) . getResultFlag ( ) ;
return isQualified ( dev , devIdMapComm , pqErrSysDtls , F , sourceIssue , dataRule , " FREQ " ) . getResultFlag ( ) ;
/**
* 电压
*/
case " V " :
System . out . println ( isQualified ( dev , devIdMapComm , pqErrSysDtls , F , sourceIssue , dataRule , " FREQ " ) ) ;
return isQualified ( dev , devIdMapComm , pqErrSysDtls , U , sourceIssue , dataRule , " VRMS " ) . getResultFlag ( ) ;
System . out . println ( isQualified ( dev , devIdMapComm , pqErrSysDtls , F , sourceIssue , dataRule , " FREQ " ) ) ;
return isQualified ( dev , devIdMapComm , pqErrSysDtls , U , sourceIssue , dataRule , " VRMS " ) . getResultFlag ( ) ;
/**
* 电流
*/
case " I " :
return isQualified ( dev , devIdMapComm , pqErrSysDtls , I , sourceIssue , dataRule , " IRMS " ) . getResultFlag ( ) ;
return isQualified ( dev , devIdMapComm , pqErrSysDtls , I , sourceIssue , dataRule , " IRMS " ) . getResultFlag ( ) ;
/**
* 谐波类
*/
@@ -98,8 +104,8 @@ public class DetectionServiceImpl {
case " F " :
break ;
/**
* 暂态
*/
* 暂态
*/
case " VOLTAGE " :
break ;
}
@@ -181,9 +187,10 @@ public class DetectionServiceImpl {
* @param type (电压还是电流)
* @param sourceIssue 源下发所对应的参数
* @param dataRule 数据处理原则
* @param code 源下发的装置通道code(->desc)
* @return
*/
public AdNonHarmonicResult isQualified ( List < DevData > dev , Map < String , String > devIdMapComm , List < PqErrSysDtls > pqErrSysDtls , String type , SourceIssue sourceIssue , DictDataEnum dataRule , String code ) {
public AdNonHarmonicResult isQualified ( List < DevData > dev , Map < String , String > devIdMapComm , List < PqErrSysDtls > pqErrSysDtls , String type , SourceIssue sourceIssue , DictDataEnum dataRule , String code ) {
Map < String , List < Double > > map = devListMap ( dev , dataRule , code ) ;
Double fData = 1 . 0 ;
if ( U . equals ( type ) ) {
@@ -195,16 +202,16 @@ public class DetectionServiceImpl {
if ( F . equals ( type ) ) {
fData = sourceIssue . getFFreq ( ) ;
}
AdNonHarmonicResult result = new AdNonHarmonicResult ( ) ;
AdNonHarmonicResult result = new AdNonHarmonicResult ( ) ;
String [ ] split = dev . get ( 0 ) . getId ( ) . split ( " _ " ) ;
String devID = devIdMapComm . get ( split ) ;
result . setMonitorId ( devID + " _ " + split [ 1 ] ) ;
String devID = devIdMapComm . get ( split [ 0 ] ) ;
result . setMonitorId ( devID + " _ " + split [ 1 ] ) ;
result . setScriptId ( sourceIssue . getScriptId ( ) ) ;
result . setIndex ( sourceIssue . getIndex ( ) ) ;
result . setDataType ( " avg " ) ;
if ( map . containsKey ( TYPE_T ) ) {
DetectionData t = rangeComparisonList ( map . get ( TYPE_T ) , pqErrSysDtls , fData , 1 . 0 , dataRule ) ;
result . setTValue ( t . getData ( ) + " _ " + t . getIsData ( ) ) ;
result . setTValue ( t . getData ( ) + " _ " + t . getIsData ( ) ) ;
result . setResultFlag ( t . getIsData ( ) ) ;
} else {
//取出源所对应的相别信息
@@ -212,32 +219,32 @@ public class DetectionServiceImpl {
. filter ( x - > ( type + " a " ) . equals ( x . getChannelType ( ) ) )
. collect ( Collectors . toList ( ) ) ;
DetectionData a = rangeComparisonList ( map . get ( TYPE_A ) , pqErrSysDtls , fData , channelTypeAList . get ( 0 ) . getFAmp ( ) , dataRule ) ;
result . setAValue ( a . getData ( ) + " _ " + a . getIsData ( ) ) ;
result . setAValue ( a . getData ( ) + " _ " + a . getIsData ( ) ) ;
List < SourceIssue . ChannelListDTO > channelTypeBList = sourceIssue . getChannelList ( ) . stream ( )
. filter ( x - > ( type + " b " ) . equals ( x . getChannelType ( ) ) )
. collect ( Collectors . toList ( ) ) ;
DetectionData b = rangeComparisonList ( map . get ( TYPE_B ) , pqErrSysDtls , fData , channelTypeBList . get ( 0 ) . getFAmp ( ) , dataRule ) ;
result . setBValue ( b . getData ( ) + " _ " + b . getIsData ( ) ) ;
result . setBValue ( b . getData ( ) + " _ " + b . getIsData ( ) ) ;
List < SourceIssue . ChannelListDTO > channelTypeCList = sourceIssue . getChannelList ( ) . stream ( )
. filter ( x - > ( type + " c " ) . equals ( x . getChannelType ( ) ) )
. collect ( Collectors . toList ( ) ) ;
DetectionData c = rangeComparisonList ( map . get ( TYPE_C ) , pqErrSysDtls , fData , channelTypeCList . get ( 0 ) . getFAmp ( ) , dataRule ) ;
result . setCValue ( c . getData ( ) + " _ " + c . getIsData ( ) ) ;
result . setCValue ( c . getData ( ) + " _ " + c . getIsData ( ) ) ;
List < Integer > numbers = Arrays . asList ( a . getIsData ( ) , b . getIsData ( ) , a . getIsData ( ) ) ;
if ( numbers . stream ( ) . allMatch ( n - > n = = 1 ) ) {
if ( numbers . stream ( ) . allMatch ( n - > n = = 1 ) ) {
result . setResultFlag ( 1 ) ;
}
if ( numbers . stream ( ) . allMatch ( n - > n = = 2 ) ) {
result . setResultFlag ( 1 ) ;
if ( numbers . stream ( ) . allMatch ( n - > n = = 2 ) ) {
result . setResultFlag ( 2 ) ;
}
if ( numbers . stream ( ) . allMatch ( n - > n = = 3 ) ) {
result . setResultFlag ( 1 ) ;
if ( numbers . contains ( 4 ) ) {
result . setResultFlag ( 4 ) ;
}
}
return result ;
return result ;
}
/**
@@ -251,7 +258,7 @@ public class DetectionServiceImpl {
* @param num 处理数组下标位数
* @return
*/
public Boolean isHarmQualified ( List < DevData > dev , List < PqErrSysDtls > pqErrSysDtls , String type , SourceIssue sourceIssue , DictDataEnum dataRule , Integer num ) {
public AdHarmonicResult isHarmQualified ( List < DevData > dev , Map < String , String > devIdMapComm , List < PqErrSysDtls > pqErrSysDtls , String type , SourceIssue sourceIssue , DictDataEnum dataRule , Integer num ) {
Map < String , Map < Integer , List < Double > > > devMap = devHarmListMap ( dev , sourceIssue , dataRule , num ) ;
Double fData = 1 . 0 ;
if ( U . equals ( type ) ) {
@@ -260,25 +267,54 @@ public class DetectionServiceImpl {
if ( I . equals ( type ) ) {
fData = sourceIssue . getFIn ( ) ;
}
Map < Integer , Boolean > integerBooleanMap A = harmRangeComparison ( pqErrSysDtls , type , TYPE_A , sourceIssue , dataRule , devMap . get ( TYPE_A ) , fData ) ;
Map < Integer , Boolean > integerBooleanMap B = harmRangeComparison ( pqErrSysDtls , type , TYPE_B , sourceIssue , dataRule , devMap . get ( TYPE_B ) , fData ) ;
Map < Integer , Boolean > integerBooleanMap C = harmRangeComparison ( pqErrSysDtls , type , TYPE_C , sourceIssue , dataRule , devMap . get ( TYPE_C ) , fData ) ;
List < Boolean > lis t = new ArrayList < > ( ) ;
list . addAll ( integerBooleanMapA . values ( ) ) ;
list . addAll ( integerBooleanMapB . values ( ) ) ;
list . addAll ( integerBooleanMapC . values ( ) ) ;
if ( CollUtil . isNotEmpty ( list ) ) {
List < Boolean > integerList = list . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x ) ) . collect ( Collectors . toList ( ) ) ;
if ( integerList . size ( ) = = list . size ( ) ) {
List < Boolean > booleans = integerList . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( booleans . size ( ) > 1 ) {
return false ;
} else {
return booleans . get ( 0 ) ;
}
}
List < DetectionData > integerBooleanA = harmRangeComparison ( pqErrSysDtls , type , TYPE_A , sourceIssue , dataRule , devMap . get ( TYPE_A ) , fData ) ;
List < DetectionData > integerBooleanB = harmRangeComparison ( pqErrSysDtls , type , TYPE_B , sourceIssue , dataRule , devMap . get ( TYPE_B ) , fData ) ;
List < DetectionData > integerBooleanC = harmRangeComparison ( pqErrSysDtls , type , TYPE_C , sourceIssue , dataRule , devMap . get ( TYPE_C ) , fData ) ;
AdHarmonicResult harmonicResul t = new AdHarmonicResult ( ) ;
String [ ] split = dev . get ( 0 ) . getId ( ) . split ( " _ " ) ;
String devID = devIdMapComm . get ( split [ 0 ] ) ;
harmonicResult . setMonitorId ( devID + " _ " + split [ 1 ] ) ;
harmonicResult . setScriptId ( sourceIssue . getScriptId ( ) ) ;
harmonicResult . setIndex ( sourceIssue . getIndex ( ) ) ;
harmonicResult . setDataType ( " avg " ) ;
reflectHarmonic ( " a " , integerBooleanA , harmonicResult ) ;
reflectHarmonic ( " b " , integerBooleanA , harmonicResult ) ;
reflectHarmonic ( " c " , integerBooleanA , harmonicResult ) ;
List < Integer > list = new ArrayList < > ( ) ;
list . addAll ( integerBooleanA . stream ( ) . map ( DetectionData : : getIsData ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
list . addAll ( integerBooleanB . stream ( ) . map ( DetectionData : : getIsData ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
list . addAll ( integerBooleanC . stream ( ) . map ( DetectionData : : getIsData ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
if ( list . stream ( ) . allMatch ( n - > n = = 1 ) ) {
harmonicResult . setResultFlag ( 1 ) ;
}
return null ;
if ( list . stream ( ) . allMatch ( n - > n = = 2 ) ) {
harmonicResult . setResultFlag ( 2 ) ;
}
if ( list . contains ( 4 ) ) {
harmonicResult . setResultFlag ( 4 ) ;
}
return harmonicResult ;
}
private void reflectHarmonic ( String phase , List < DetectionData > integerBooleanA , AdHarmonicResult harmonicResult ) {
Map < Integer , DetectionData > dataMap = integerBooleanA . stream ( ) . collect ( Collectors . toMap ( DetectionData : : getNum , Function . identity ( ) ) ) ;
dataMap . forEach ( ( key , value ) - > {
try {
// 设置 id 字段
Field idField = AdHarmonicResult . class . getDeclaredField ( phase + " Value " + key ) ;
idField . setAccessible ( true ) ;
if ( ObjectUtil . isNull ( value . getIsData ( ) ) ) {
idField . set ( harmonicResult , value . getData ( ) ) ;
} else {
idField . set ( harmonicResult , value . getData ( ) + " _ " + value . getIsData ( ) ) ;
}
} catch ( IllegalAccessException e ) {
throw new RuntimeException ( e ) ;
} catch ( NoSuchFieldException e ) {
throw new RuntimeException ( e ) ;
}
} ) ;
}
@@ -330,8 +366,8 @@ public class DetectionServiceImpl {
* @param fData
* @return
*/
public Map < Integer , Boolean > harmRangeComparison ( List < PqErrSysDtls > pqErrSysDtls , String type , String phase , SourceIssue sourceIssue , DictDataEnum dataRule , Map < Integer , List < Double > > devMap , Double fData ) {
Map < Integer , Boolean > map = new LinkedHashMap < > ( ) ;
public List < DetectionData > harmRangeComparison ( List < PqErrSysDtls > pqErrSysDtls , String type , String phase , SourceIssue sourceIssue , DictDataEnum dataRule , Map < Integer , List < Double > > devMap , Double fData ) {
List < DetectionData > info = new ArrayList < > ( ) ;
//根据谐波几次相值/额定值
Map < Integer , Double > issueHarmMap = sourceIssue . getChannelList ( ) . stream ( )
. filter ( x - > ( type + phase . toLowerCase ( ) ) . equals ( x . getChannelType ( ) ) )
@@ -352,49 +388,70 @@ public class DetectionServiceImpl {
}
} ) ;
devMap . forEach ( ( harm , harmDataList ) - > {
Boolean harmBigNum = getHarmNum ( dataRule , harmDataList , errSysDtlMap . get ( harm ) , issueHarmMap . get ( harm ) , fData ) ;
if ( ObjectUtil . isNotNull ( harmBigNum ) ) {
map . put ( harm , harmBigNum ) ;
PqErrSysDtls errSysDtl = errSysDtlMap . get ( harm ) ;
DetectionData data = new DetectionData ( ) ;
data . setIsData ( 4 ) ;
data . setNum ( harm ) ;
data . setData ( harmDataList . get ( 0 ) ) ;
if ( ObjectUtil . isNotNull ( errSysDtl ) ) {
if ( 0 = = errSysDtl . getErrorValueType ( ) ) {
errSysDtl . setMaxErrorValue ( multiply ( errSysDtl . getMaxErrorValue ( ) , fData , 0 ) ) ;
}
Double v = issueHarmMap . get ( harm ) ;
setDetection ( dataRule , harmDataList , errSysDtl , data , v ) ;
}
info . add ( data ) ;
} ) ;
return map ;
return info ;
}
public Boolean getHarmNum ( DictDataEnum dataRule , List < Double > harmDataList , PqErrSysDtls errSysDtl , Double channelData , Double fData ) {
if ( ObjectUtil . isNotNull ( errSysDtl ) ) {
if ( 0 = = errSysDtl . getErrorValueType ( ) ) {
errSysDtl . setMaxErrorValue ( multiply ( errSysDtl . getMaxErrorValue ( ) , fData , 0 ) ) ;
}
List < Double > qualifiedList = harmDataList . stream ( )
. filter ( x - > NumberUtil . isIn ( devSubtractChannelData ( x , channelData , errSysDtl . getErrorValueType ( ) ) ,
BigDecimal . valueOf ( - errSysDtl . getMaxErrorValue ( ) ) ,
BigDecimal . valueOf ( errSysDtl . getMaxErrorValue ( ) ) ) ) . collect ( Collectors . toList ( ) ) ;
/**
* @param dataRule 数据处理原则
* @param harmDataList 原始数据集合
* @param errSysDtl 误差体系
* @param data 初始化原始数据
* @param v 源下发的数据
* @Description:
* @Author: wr
* @Date: 2024/12/29 18:10
*/
private void setDetection ( DictDataEnum dataRule , List < Double > harmDataList , PqErrSysDtls errSysDtl , DetectionData data , Double v ) {
List < Double > qualifiedList = harmDataList . stream ( )
. filter ( x - > NumberUtil . isIn ( devSubtractChannelData ( x , v , errSysDtl . getErrorValueType ( ) ) ,
BigDecimal . valueOf ( - errSysDtl . getMaxErrorValue ( ) ) ,
BigDecimal . valueOf ( errSysDtl . getMaxErrorValue ( ) ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollUtil . isNotEmpty ( qualifiedList ) ) {
data . setData ( qualifiedList . get ( 0 ) ) ;
switch ( dataRule ) {
case AT_WILL_VALUE :
case CP95_VALUE :
case AVG_VALUE :
if ( qualifiedList . size ( ) > 0 ) {
return true ;
data . setIsData ( 1 ) ;
} else {
data . setIsData ( 2 ) ;
}
break ;
case SECTION_VALUE :
case Own_value :
if ( qualifiedList . size ( ) = = harmDataList . size ( ) ) {
return true ;
data . setIsData ( 1 ) ;
} else {
data . setIsData ( 2 ) ;
}
break ;
}
return fa lse;
} e lse {
data . setIsData ( 2 ) ;
}
return null ;
}
public Map < String , Map < Integer , List < Double > > > devHarmListMap ( List < DevData > dev , SourceIssue sourceIssue , DictDataEnum dataRule , Integer num ) {
Map < String , Map < Integer , List < Double > > > map = new HashMap < > ( 3 ) ;
List < Integer > harmNum = sourceIssue . getChannelList ( ) . stream ( )
. flatMap ( x - > x . getHarmList ( ) . stream ( ) . map ( f - > f . getHarm ( ) ) )
. sorted ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
Map < String , Map < Integer , List < Double > > > map = new HashMap < > ( 3 ) ;
for ( DevData devData : dev ) {
DevData . SqlDataDTO fund = devData . getSqlData ( ) . stream ( ) . collect ( Collectors . toList ( ) ) . stream ( ) . findFirst ( ) . get ( ) ;
DevData . SqlDataHarmDTO harm = devData . getSqlDataHarm ( ) . stream ( ) . filter ( x - > 49 = = x . getNum ( ) ) . collect ( Collectors . toList ( ) ) . stream ( ) . findFirst ( ) . get ( ) ;
@@ -441,7 +498,7 @@ public class DetectionServiceImpl {
* @returnd
*/
public DetectionData rangeComparisonList ( List < Double > listT , List < PqErrSysDtls > pqErrSysDtls , Double data , Double channelData , DictDataEnum dataRule ) {
DetectionData detectionData = new DetectionData ( ) ;
DetectionData detectionData = new DetectionData ( ) ;
detectionData . setIsData ( 4 ) ;
detectionData . setData ( listT . get ( 0 ) ) ;
//先根据源所下发的数据,是否在误差体系范围内在则可以进行误差体系判断
@@ -456,33 +513,7 @@ public class DetectionServiceImpl {
if ( 0 = = errSysDtl . getErrorValueType ( ) ) {
errSysDtl . setMaxErrorValue ( multiply ( errSysDtl . getMaxErrorValue ( ) , data , 0 ) ) ;
}
List < Double > qualifiedList = listT . stream ( ) . filter ( x - > NumberUtil . isIn ( devSubtractChannelData ( x , channelData , errSysDtl . getErrorValueType ( ) ) ,
BigDecimal . valueOf ( - errSysDtl . getMaxErrorValue ( ) ) ,
BigDecimal . valueOf ( errSysDtl . getMaxErrorValue ( ) ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollUtil . isNotEmpty ( qualifiedList ) ) {
detectionData . setData ( qualifiedList . get ( 0 ) ) ;
switch ( dataRule ) {
case AT_WILL_VALUE :
case CP95_VALUE :
case AVG_VALUE :
if ( qualifiedList . size ( ) > 0 ) {
detectionData . setIsData ( 1 ) ;
} else {
detectionData . setIsData ( 2 ) ;
}
break ;
case SECTION_VALUE :
case Own_value :
if ( qualifiedList . size ( ) = = listT . size ( ) ) {
detectionData . setIsData ( 1 ) ;
} else {
detectionData . setIsData ( 2 ) ;
}
break ;
}
} else {
detectionData . setIsData ( 2 ) ;
}
setDetection ( dataRule , listT , errSysDtl , detectionData , channelData ) ;
}
return detectionData ;
}