@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.IOException ;
import java.io.IOException ;
import java.util.* ;
import java.util.* ;
import java.util.stream.Collectors ;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception ;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception ;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.* ;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.* ;
@ -72,6 +73,7 @@ public class InstantServiceImpl implements InstantService {
//PCA回算的http请求地址
//PCA回算的http请求地址
@Value ( "${PCA.calcurl}" )
@Value ( "${PCA.calcurl}" )
private String PCA_CALC_URL ;
private String PCA_CALC_URL ;
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
@LogRecord ( type = SYSTEM_INSTANT_TYPE , subType = SYSTEM_INSTANT_CREATE_SUB_TYPE , bizNo = "{{#role.id}}" ,
@LogRecord ( type = SYSTEM_INSTANT_TYPE , subType = SYSTEM_INSTANT_CREATE_SUB_TYPE , bizNo = "{{#role.id}}" ,
@ -85,6 +87,7 @@ public class InstantServiceImpl implements InstantService {
String modelVersion = versionMapper . selectById ( createReqVO . getModelVersionId ( ) ) . getVersion ( ) ;
String modelVersion = versionMapper . selectById ( createReqVO . getModelVersionId ( ) ) . getVersion ( ) ;
createReqVO . setModelVersion ( modelVersion ) ;
createReqVO . setModelVersion ( modelVersion ) ;
//插入除instantInfo外的所有数据,获取到id
//插入除instantInfo外的所有数据,获取到id
// 2. 插入到数据库-status、visible默认值
// 2. 插入到数据库-status、visible默认值
InstantTableDO instant = BeanUtils . toBean ( createReqVO , InstantTableDO . class )
InstantTableDO instant = BeanUtils . toBean ( createReqVO , InstantTableDO . class )
@ -120,7 +123,7 @@ public class InstantServiceImpl implements InstantService {
unitList . add ( pointInfoList . get ( i ) . getUnit ( ) ) ;
unitList . add ( pointInfoList . get ( i ) . getUnit ( ) ) ;
// 如果pointInfoList.get(i)有type字段,或者createReqVO对象中的算法是PCA就加一些重构值、时间值、偏差值
// 如果pointInfoList.get(i)有type字段,或者createReqVO对象中的算法是PCA就加一些重构值、时间值、偏差值
if ( pointInfoList . get ( i ) . getType ( ) ! = null | | Objects . equals ( createReqVO . getAlgorithmId ( ) , "1" )
if ( pointInfoList . get ( i ) . getType ( ) ! = null | | Objects . equals ( createReqVO . getAlgorithmId ( ) , "1" )
| | createReqVO . getAlgorithmId ( ) . equals ( 1L ) ) {
| | createReqVO . getAlgorithmId ( ) . equals ( 1L ) ) {
//构建重构值对象
//构建重构值对象
outpoint = HEAD + "M" + String . format ( "%04d" , insertId ) + String . format ( "%04d" , i + 1 ) + "R" ;
outpoint = HEAD + "M" + String . format ( "%04d" , insertId ) + String . format ( "%04d" , i + 1 ) + "R" ;
point = new Point ( ) ;
point = new Point ( ) ;
@ -236,43 +239,77 @@ public class InstantServiceImpl implements InstantService {
public void createWarn1 ( InstantTableDO instant , InstantSaveReqVO createReqVO ) {
public void createWarn1 ( InstantTableDO instant , InstantSaveReqVO createReqVO ) {
try {
try {
//调用预警表和评估报告表的mapper
//如果createReqVO中算法是pca,则读取评估报告从而获取上下限;如果是ANN,则直接读取modelInfo中的上下限
// 从instant对象获取modelid和version字段
if ( createReqVO . getAlgorithmId ( ) = = 2 ) {
Long modelId = instant . getModelId ( ) ;
String modelInfoStr = versionMapper . selectById ( createReqVO . getModelVersionId ( ) ) . getModelInfo ( ) ;
String version = instant . getModelVersion ( ) ;
// 解析modelInfo为RunModelInfoVO类
RunModelInfoVO modelInfo = JsonUtils . parseObject ( modelInfoStr , RunModelInfoVO . class ) ;
// 调用reportMapper获取对应记录(假设存在selectByModelIdAndVersion方法)
// 从modelInfo中获取上下限列表(ANN的上下限是存在模型中的,PCA是存在评估报告中的)
ReportDO report = reportMapper . selectByModelIdAndVersion ( modelId , version ) ;
List < Double > pre_s = modelInfo . getPara ( ) . getPre_s ( ) ;
// 如果report不为空且report字段不为空,则解析为Report类
//createReqVO.getOutPointInfo()已经是上一步筛选好的数据,筛选条件---type=true,如果是ANN就表示是输出,PCA是全部点
if ( report ! = null & & StrUtil . isNotBlank ( report . getReport ( ) ) ) {
// 遍历筛选后的输出点信息
Report reportObj = JsonUtils . parseObject ( report . getReport ( ) , Report . class ) ;
for ( Integer i = 0 ; i < createReqVO . getOutPointInfo ( ) . size ( ) ; i + + ) {
// 此处可根据业务需求处理解析后的Report对象(如后续预警逻辑)
// 循环getInputInfo构建并插入预警记录
for ( int j = 0 ; j < reportObj . getAssess ( ) . size ( ) ; j + + ) {
WarnSaveReqVO warnSaveReqVO = new WarnSaveReqVO ( ) ;
WarnSaveReqVO warnSaveReqVO = new WarnSaveReqVO ( ) ;
// 设置预警ID(假设insertId为当前预警主记录ID)
// 设置预警ID(假设insertId为当前预警主记录ID)
// warn.setId(insertId);
// warn.setId(insertId);
//设置实例id
//设置实例id
warnSaveReqVO . setMpId ( instant . getMpId ( ) ) ;
warnSaveReqVO . setMpId ( instant . getMpId ( ) ) ;
warnSaveReqVO . setPointOrModel ( "point" ) ;
warnSaveReqVO . setPointOrModel ( "point" ) ;
warnSaveReqVO . setPointId ( createReqVO . getInputInfo ( ) . get ( i ) ) ;
warnSaveReqVO . setPointId ( createReqVO . getInputInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setPointName ( createReqVO . getInputName ( ) . get ( i ) ) ;
warnSaveReqVO . setPointName ( createReqVO . getInputName ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setGzpName ( createReqVO . getInputName ( ) . get ( i ) ) ;
warnSaveReqVO . setGzpName ( createReqVO . getInputName ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setEquation ( "[" + createReqVO . getBiasPointInfo ( ) . get ( i ) + "]>UPLIMIT or [" + createReqVO . getBiasPointInfo ( ) . get ( i ) + "]<LOWLIMIT" ) ;
warnSaveReqVO . setEquation ( "[" + createReqVO . getBiasPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) + "]>UPLIMIT or [" + createReqVO . getBiasPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) + "]<LOWLIMIT" ) ;
warnSaveReqVO . setUplimit ( pre_s . get ( i ) ) ;
warnSaveReqVO . setUplimit ( reportObj . getAssess ( ) . get ( j ) . getAmplitude ( ) ) ;
warnSaveReqVO . setLowlimit ( - pre_s . get ( i ) ) ;
warnSaveReqVO . setLowlimit ( - reportObj . getAssess ( ) . get ( j ) . getAmplitude ( ) ) ;
warnSaveReqVO . setOutputPoint ( createReqVO . getOutPointInfo ( ) . get ( i ) ) ;
warnSaveReqVO . setOutputPoint ( createReqVO . getOutPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setUnit ( createReqVO . getUnit ( ) . get ( i ) ) ;
warnSaveReqVO . setUnit ( createReqVO . getUnit ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
// 设置其他必要字段(根据实际业务补充)
// 设置其他必要字段(根据实际业务补充)
warnSaveReqVO . setWarnStatus ( 1L ) ; // 示例:设置初始状态
warnSaveReqVO . setWarnStatus ( 1L ) ; // 示例:设置初始状态
// 插入数据库
// 插入数据库
warnService . createWarn ( warnSaveReqVO ) ;
warnService . createWarn ( warnSaveReqVO ) ;
}
}
} else if ( createReqVO . getAlgorithmId ( ) = = 1 ) {
//调用预警表和评估报告表的mapper
// 从instant对象获取modelid和version字段
Long modelId = instant . getModelId ( ) ;
String version = instant . getModelVersion ( ) ;
// 调用reportMapper获取对应记录(假设存在selectByModelIdAndVersion方法)
ReportDO report = reportMapper . selectByModelIdAndVersion ( modelId , version ) ;
// 如果report不为空且report字段不为空,则解析为Report类
if ( report ! = null & & StrUtil . isNotBlank ( report . getReport ( ) ) ) {
Report reportObj = JsonUtils . parseObject ( report . getReport ( ) , Report . class ) ;
// 此处可根据业务需求处理解析后的Report对象(如后续预警逻辑)
// 循环getInputInfo构建并插入预警记录
for ( int j = 0 ; j < reportObj . getAssess ( ) . size ( ) ; j + + ) {
WarnSaveReqVO warnSaveReqVO = new WarnSaveReqVO ( ) ;
// 设置预警ID(假设insertId为当前预警主记录ID)
// warn.setId(insertId);
//设置实例id
warnSaveReqVO . setMpId ( instant . getMpId ( ) ) ;
warnSaveReqVO . setPointOrModel ( "point" ) ;
warnSaveReqVO . setPointId ( createReqVO . getInputInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setPointName ( createReqVO . getInputName ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setGzpName ( createReqVO . getInputName ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setEquation ( "[" + createReqVO . getBiasPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) + "]>UPLIMIT or [" + createReqVO . getBiasPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) + "]<LOWLIMIT" ) ;
warnSaveReqVO . setUplimit ( reportObj . getAssess ( ) . get ( j ) . getAmplitude ( ) ) ;
warnSaveReqVO . setLowlimit ( - reportObj . getAssess ( ) . get ( j ) . getAmplitude ( ) ) ;
warnSaveReqVO . setOutputPoint ( createReqVO . getOutPointInfo ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
warnSaveReqVO . setUnit ( createReqVO . getUnit ( ) . get ( reportObj . getAssess ( ) . get ( j ) . getIndex ( ) ) ) ;
// 设置其他必要字段(根据实际业务补充)
warnSaveReqVO . setWarnStatus ( 1L ) ; // 示例:设置初始状态
// 插入数据库
warnService . createWarn ( warnSaveReqVO ) ;
}
}
} else {
throw exception ( CREATE_INSTANT_ERROR , "模型实例创建失败: 算法缺失" ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
log . error ( "模型实例创建失败,错误信息: " , e ) ;
log . error ( "模型实例创建失败,错误信息: " , e ) ;
@ -314,7 +351,9 @@ public class InstantServiceImpl implements InstantService {
//构造第一个图表数据
//构造第一个图表数据
//获取数据库modelInfo字段,从而获取Kesi_99值
//获取数据库modelInfo字段,从而获取Kesi_99值
RunModelInfoVO runModelInfoVO = JsonUtils . parseObject ( instant . getModelInfo ( ) , RunModelInfoVO . class ) ;
RunModelInfoVO runModelInfoVO = JsonUtils . parseObject ( instant . getModelInfo ( ) , RunModelInfoVO . class ) ;
Double Kesi_99 = runModelInfoVO . getPara ( ) . getModel_info ( ) . getKesi_99 ( ) ;
//这个字段不知道咋回事没有了
// Double Kesi_99 = runModelInfoVO.getPara().getModel_info().getKesi_99();
Double Kesi_99 = 99 . 0 ;
//获取数据库instantInfo字段
//获取数据库instantInfo字段
InstantInfoVO instantInfoVO = JsonUtils . parseObject ( instant . getInstantInfo ( ) , InstantInfoVO . class ) ;
InstantInfoVO instantInfoVO = JsonUtils . parseObject ( instant . getInstantInfo ( ) , InstantInfoVO . class ) ;
@ -536,7 +575,7 @@ public class InstantServiceImpl implements InstantService {
throw exception ( CALCULATE_ERROR , "计算失败" ) ;
throw exception ( CALCULATE_ERROR , "计算失败" ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
throw exception ( CALCULATE_ERROR , "结果有误,返回结果为: " + jsonResult + ",异常信息为: " + e . getMessage ( ) ) ;
throw exception ( CALCULATE_ERROR , "结果有误,返回结果为: " + jsonResult + ",异常信息为: " + e . getMessage ( ) ) ;
}
}
// 解析返回结果
// 解析返回结果
String rtn = jsonResult . getString ( "rtn" ) ;
String rtn = jsonResult . getString ( "rtn" ) ;