@@ -8,6 +8,12 @@ import cn.hutool.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper ;
import com.njcn.common.pojo.enums.common.DataStateEnum ;
import com.njcn.common.pojo.exception.BusinessException ;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum ;
import com.njcn.gather.detection.pojo.param.PreDetectionParam ;
import com.njcn.gather.detection.pojo.po.DevData ;
import com.njcn.gather.detection.service.impl.DetectionServiceImpl ;
import com.njcn.gather.detection.util.socket.MsgUtil ;
import com.njcn.gather.device.pojo.po.PqDev ;
import com.njcn.gather.device.service.IPqDevService ;
import com.njcn.gather.plan.pojo.po.AdPlan ;
import com.njcn.gather.plan.service.IAdPlanService ;
@@ -20,23 +26,30 @@ import com.njcn.gather.result.pojo.vo.ResultVO;
import com.njcn.gather.result.pojo.vo.TreeDataVO ;
import com.njcn.gather.result.service.IResultService ;
import com.njcn.gather.script.mapper.PqScriptMapper ;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam ;
import com.njcn.gather.script.pojo.po.PqScriptCheckData ;
import com.njcn.gather.script.pojo.po.PqScriptDtls ;
import com.njcn.gather.script.pojo.po.SourceIssue ;
import com.njcn.gather.script.service.IPqScriptCheckDataService ;
import com.njcn.gather.script.service.IPqScriptDtlsService ;
import com.njcn.gather.script.util.ScriptDtlsDesc ;
import com.njcn.gather.storage.mapper.TableGenMapper ;
import com.njcn.gather.storage.pojo.param.StorageParam ;
import com.njcn.gather.storage.pojo.po.AdBaseResult ;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult ;
import com.njcn.gather.storage.pojo.vo.RawDataVO ;
import com.njcn.gather.storage.service.AdHarmonicService ;
import com.njcn.gather.storage.service.AdNonHarmonicService ;
import com.njcn.gather.system.config.pojo.po.SysTestConfig ;
import com.njcn.gather.system.config.service.ISysTestConfigService ;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum ;
import com.njcn.gather.system.dictionary.pojo.po.DictTree ;
import com.njcn.gather.system.dictionary.service.IDictTreeService ;
import com.njcn.web.utils.ExcelUtil ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.util.* ;
import java.util.function.Function ;
@@ -60,6 +73,8 @@ public class ResultServiceImpl implements IResultService {
private final PqScriptMapper scriptMapper ;
private final IDictTreeService dictTreeService ;
private final IPqScriptCheckDataService pqScriptCheckDataService ;
private final TableGenMapper tableGenMapper ;
private final DetectionServiceImpl detectionServiceImpl ;
/**
* 谐波类code, 取树形字典表中的code
@@ -127,10 +142,10 @@ public class ResultServiceImpl implements IResultService {
. eq ( StrUtil . isNotBlank ( param . getScriptId ( ) ) , PqScriptDtls : : getScriptId , param . getScriptId ( ) )
. eq ( StrUtil . isNotBlank ( param . getScriptType ( ) ) , PqScriptDtls : : getScriptType , param . getScriptType ( ) )
. ne ( PqScriptDtls : : getScriptIndex , - 1 )
. eq ( StrUtil . isNotBlank ( param . getDevId ( ) ) , PqScriptDtls : : getEnable , DataStateEnum . ENABLE . getCode ( ) )
. eq ( StrUtil . isNotBlank ( param . getDevId ( ) ) , PqScriptDtls : : getEnable , DataStateEnum . ENABLE . getCode ( ) )
) ;
Map < Integer , Set < Integer > > resultMap = new HashMap < > ( 5 ) ;
if ( StrUtil . isNotBlank ( param . getDevId ( ) ) ) {
if ( StrUtil . isNotBlank ( param . getDevId ( ) ) ) {
List < AdBaseResult > allResultList = new ArrayList < > ( ) ;
List < Integer > indexList = new ArrayList < > ( ) ;
if ( StrUtil . isNotBlank ( param . getScriptType ( ) ) ) {
@@ -176,7 +191,7 @@ public class ResultServiceImpl implements IResultService {
subTypeMap . forEach ( ( subKey , subValue ) - > {
if ( ! " VOLTAGE " . equals ( dictTree . getCode ( ) ) ) {
TreeDataVO subType = new TreeDataVO ( ) ;
subType . setScriptTypeName ( ! subName . containsKey ( subKey ) ? " " : subName . get ( subKey ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
subType . setScriptTypeName ( ! subName . containsKey ( subKey ) ? " " : subName . get ( subKey ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
subType . setScriptTypeCode ( subKey ) ;
LinkedHashMap < Integer , List < PqScriptDtls > > indexMap = subValue . stream ( )
. sorted ( Comparator . comparing ( PqScriptDtls : : getScriptIndex ) )
@@ -213,13 +228,13 @@ public class ResultServiceImpl implements IResultService {
. collect ( Collectors . groupingBy ( PqScriptDtls : : getScriptSubType , LinkedHashMap : : new , Collectors . toList ( ) ) ) ;
if ( CollUtil . isNotEmpty ( subSingleTypeMap ) ) {
TreeDataVO subType = new TreeDataVO ( ) ;
subType . setScriptTypeName ( ! subName . containsKey ( " Single " ) ? " " : subName . get ( " Single " ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
subType . setScriptTypeName ( ! subName . containsKey ( " Single " ) ? " " : subName . get ( " Single " ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
subType . setScriptTypeCode ( dictTree . getCode ( ) ) ;
//单影响量下频率准测量集合
List < TreeDataVO > subSingleList = new ArrayList < > ( ) ;
subSingleTypeMap . forEach ( ( subKey , subValue ) - > {
TreeDataVO treeDataVO = new TreeDataVO ( ) ;
treeDataVO . setScriptTypeName ( ! subName . containsKey ( subKey ) ? " " : subName . get ( subKey ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
treeDataVO . setScriptTypeName ( ! subName . containsKey ( subKey ) ? " " : subName . get ( subKey ) . replace ( " XX " , dictTree . getName ( ) ) ) ;
treeDataVO . setScriptTypeCode ( subKey ) ;
List < TreeDataVO > subTypeList = new ArrayList < > ( ) ;
@@ -272,7 +287,7 @@ public class ResultServiceImpl implements IResultService {
. collect ( Collectors . toList ( ) ) ;
TreeDataVO vo = new TreeDataVO ( ) ;
vo . setScriptTypeName ( name ) ;
vo . setScriptTypeCode ( " Base_ " + start + " _ " + end ) ;
vo . setScriptTypeCode ( " Base_ " + start + " _ " + end ) ;
TreeDataVO dlt ;
for ( PqScriptDtls dtls : dip ) {
dlt = new TreeDataVO ( ) ;
@@ -839,6 +854,13 @@ public class ResultServiceImpl implements IResultService {
}
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void changeErrorSystem ( ResultParam . ChangeErrorSystemParam param ) {
this . createTempResultTable ( param . getCode ( ) + " " ) ;
this . insertTempResultTable ( param . getPlanId ( ) , param . getScriptId ( ) , param . getCode ( ) + " " , param . getErrorSysId ( ) , param . getDeviceId ( ) ) ;
}
private Integer conform ( Set < Integer > numbers ) {
if ( CollUtil . isNotEmpty ( numbers ) ) {
if ( numbers . size ( ) > 1 ) {
@@ -859,4 +881,105 @@ public class ResultServiceImpl implements IResultService {
}
return false ;
}
/**
* 拷贝结果表
*
* @param code
*/
private void createTempResultTable ( String code ) {
tableGenMapper . genAdHarmonicTable ( " drop table if exists AD_Non_Harmonic_Result_ " + code + " _temp,AD_Harmonic_Result_ " + code + " _temp " ) ;
tableGenMapper . genAdNonHarmonicResultTable ( code + " _temp " ) ;
StringBuilder A = new StringBuilder ( ) ;
StringBuilder B = new StringBuilder ( ) ;
StringBuilder C = new StringBuilder ( ) ;
for ( int i = 1 ; i < = 50 ; i + + ) {
if ( i = = 1 ) {
A . append ( " A_Value_ " ) . append ( i ) . append ( " json NULL COMMENT 'A相基波', " ) ;
B . append ( " B_Value_ " ) . append ( i ) . append ( " json NULL COMMENT 'B相基波', " ) ;
C . append ( " C_Value_ " ) . append ( i ) . append ( " json NULL COMMENT 'C相基波', " ) ;
} else {
A . append ( " A_Value_ " ) . append ( i ) . append ( " json NULL COMMENT ' " ) . append ( i ) . append ( " 次A相谐波', " ) ;
B . append ( " B_Value_ " ) . append ( i ) . append ( " json NULL COMMENT ' " ) . append ( i ) . append ( " 次B相谐波', " ) ;
C . append ( " C_Value_ " ) . append ( i ) . append ( " json NULL COMMENT ' " ) . append ( i ) . append ( " 次C相谐波', " ) ;
}
}
String sql1 = " CREATE TABLE if not exists AD_Harmonic_Result_ " + code + " _temp ( \ n " +
" Monitor_Id CHAR(60) NOT NULL COMMENT '监测点Id', \ n " +
" Time_Id DATETIME NULL COMMENT '时间', \ n " +
" Script_Id CHAR(32) NOT NULL COMMENT '检测脚本子表Id, 字典表', \ n " +
" Sort int(5) NOT NULL COMMENT '总检测脚本中的测试项序号', \ n " +
" AD_Type CHAR(32) NOT NULL COMMENT '检测指标,字典表', \ n " +
" Data_Type CHAR(32) NOT NULL COMMENT '数据指标, 只有数据源为分钟统计时候才会使用( 最大、最小、平均、CP95, 默认平均值) , 字典表', \ n " +
" Result_Flag int(1) NOT NULL COMMENT '1合格 2不合格 4无法处理', \ n " +
A + B + C +
" PRIMARY KEY (Monitor_Id, Script_Id, Sort, AD_Type) \ n " +
" ) COMMENT='监测数据表'; " ;
tableGenMapper . genAdHarmonicTable ( sql1 ) ;
}
/**
* 修改拷贝后的结果表(根据误差体系修改)
*
* @param planId
* @param code
* @param errorSysId
* @param devId
*/
private void insertTempResultTable ( String planId , String scriptId , String code , String errorSysId , String devId ) {
PreDetectionParam param = new PreDetectionParam ( ) ;
param . setCode ( code ) ;
param . setErrorSysId ( errorSysId ) ;
param . setDevIds ( Arrays . asList ( devId ) ) ;
param . setCode ( code + " _temp " ) ;
Map < String , String > devIdMapComm = new HashMap < > ( ) ;
PqDev dev = pqDevService . getById ( devId ) ;
devIdMapComm . put ( devId , devId ) ;
SysTestConfig oneConfig = sysTestConfigService . getOneConfig ( ) ;
DictDataEnum dataRule ;
if ( ObjectUtil . isNotNull ( oneConfig ) ) {
dataRule = DictDataEnum . getDictDataEnumByCode ( oneConfig . getDataRule ( ) ) ;
} else {
dataRule = DictDataEnum . AT_WILL_VALUE ;
}
List < AdNonHarmonicResult > allNonHarmonicRawData = adNonHarmonicService . listAll ( code , devId ) ;
LinkedHashMap < Integer , List < AdNonHarmonicResult > > map = allNonHarmonicRawData . stream ( ) . sorted ( Comparator . comparing ( AdNonHarmonicResult : : getSort ) )
. collect ( Collectors . groupingBy ( AdNonHarmonicResult : : getSort , LinkedHashMap : : new , Collectors . toList ( ) ) ) ;
PqScriptIssueParam issueParam = new PqScriptIssueParam ( ) ;
issueParam . setPlanId ( planId ) ;
// issueParam.setSourceId();
// issueParam.setScriptType();
// issueParam.setScriptSubType();
issueParam . setDevIds ( Arrays . asList ( devId ) ) ;
issueParam . setScriptId ( scriptId ) ;
issueParam . setIsPhaseSequence ( SourceOperateCodeEnum . FORMAL_TEST . getValue ( ) ) ;
List < SourceIssue > sourceIssues = pqScriptDtlsService . listSourceIssue ( issueParam ) ;
sourceIssues . forEach ( sourceIssue - > {
List < DevData > realDataXiList = MsgUtil . toList ( map . get ( sourceIssue . getIndex ( ) ) , null ) ;
for ( int i = 0 ; i < realDataXiList . size ( ) ; i + + ) {
DevData devData = realDataXiList . get ( i ) ;
List < DevData . SqlDataDTO > sqlData = devData . getSqlData ( ) ;
if ( CollUtil . isNotEmpty ( sqlData ) ) {
for ( int j = 0 ; j < sqlData . size ( ) ; j + + ) {
DevData . SqlDataDTO sqlDataDTO = sqlData . get ( j ) ;
String desc = sqlDataDTO . getDesc ( ) ;
if ( StrUtil . isNotBlank ( desc ) ) {
DictTree dictTree = dictTreeService . getById ( desc ) ;
if ( ObjectUtil . isNotNull ( dictTree ) ) {
sqlDataDTO . setDesc ( dictTree . getCode ( ) ) ;
}
}
}
}
}
detectionServiceImpl . processing ( realDataXiList , param , devIdMapComm , sourceIssue , dataRule ) ;
} ) ;
}
}