|
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.alert.service.instant; |
|
|
|
import cn.hutool.core.util.ObjUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|
|
|
import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.Point; |
|
|
|
@ -13,16 +14,15 @@ import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantDO; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.instant.InstantTableDO; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.report.Report; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.report.ReportDO; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnTableDO; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.warn.WarnCalcDO; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.instant.InstantMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.instant.InstantTableMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.model.VersionMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.report.ReportMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.warn.WarnTableMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.warn.WarnCalcMapper; |
|
|
|
import cn.iocoder.yudao.module.alert.service.warn.WarnService; |
|
|
|
import cn.iocoder.yudao.module.alert.utils.EXAUtils; |
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.mzt.logapi.context.LogRecordContext; |
|
|
|
import com.mzt.logapi.service.impl.DiffParseFunction; |
|
|
|
@ -36,13 +36,8 @@ import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.time.Instant; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.UNKNOWN; |
|
|
|
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.LogRecordConstants.*; |
|
|
|
@ -50,6 +45,7 @@ import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class InstantServiceImpl implements InstantService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private InstantMapper instantMapper; |
|
|
|
@Resource |
|
|
|
@ -63,19 +59,26 @@ public class InstantServiceImpl implements InstantService { |
|
|
|
|
|
|
|
private WarnService warnService; |
|
|
|
|
|
|
|
// 新增:注入WarnCalcMapper用于查询预警计算配置
|
|
|
|
@Resource |
|
|
|
private WarnCalcMapper warnCalcMapper; |
|
|
|
EXAUtils exaUtils = new EXAUtils(); |
|
|
|
// 新增:从配置文件注入exaip
|
|
|
|
@Value("${point.head}") |
|
|
|
private String HEAD; |
|
|
|
@Value("${EXA.ip}") |
|
|
|
private String EXA_IP; |
|
|
|
|
|
|
|
//PCA回算的http请求地址
|
|
|
|
@Value("${PCA.calcurl}") |
|
|
|
private String PCA_CALC_URL; |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@LogRecord(type = SYSTEM_INSTANT_TYPE, subType = SYSTEM_INSTANT_CREATE_SUB_TYPE, bizNo = "{{#role.id}}", |
|
|
|
success = SYSTEM_INSTANT_CREATE_SUCCESS) |
|
|
|
public List<String> createInstant(InstantSaveReqVO createReqVO, Integer type) throws IOException { |
|
|
|
|
|
|
|
try{ |
|
|
|
try { |
|
|
|
// 1. 校验角色
|
|
|
|
// validateRoleDuplicate(createReqVO.getName(), createReqVO.getCode(), null);
|
|
|
|
//根据modelversionid查询modelversion,录入instantcfg表的modelversion字段
|
|
|
|
@ -170,6 +173,7 @@ try{ |
|
|
|
|
|
|
|
|
|
|
|
createReqVO.setMpId(insertId); |
|
|
|
|
|
|
|
createReqVO.setInstantStatus(instant.getInstantStatus()); |
|
|
|
createReqVO.setVisible(instant.getVisible()); |
|
|
|
createReqVO.setInputInfo(inputInfoList); |
|
|
|
@ -227,22 +231,19 @@ try{ |
|
|
|
return resultList; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("模型实例创建失败,错误信息: ", e); |
|
|
|
throw exception(CREATE_INSTANT_ERROR,"模型实例创建失败: " + e.getMessage()); |
|
|
|
throw exception(CREATE_INSTANT_ERROR, "模型实例创建失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void createWarn1(InstantTableDO instant, InstantSaveReqVO createReqVO) { |
|
|
|
try{ |
|
|
|
try { |
|
|
|
//调用预警表和评估报告表的mapper
|
|
|
|
// 从instant对象获取modelid和version字段
|
|
|
|
Long modelId = instant.getModelId(); |
|
|
|
String version = instant.getModelVersion(); |
|
|
|
|
|
|
|
// modelId=11L;
|
|
|
|
// version="v-test";
|
|
|
|
|
|
|
|
// 调用reportMapper获取对应记录(假设存在selectByModelIdAndVersion方法)
|
|
|
|
ReportDO report = reportMapper.selectByModelIdAndVersion(modelId, version); |
|
|
|
|
|
|
|
@ -259,6 +260,8 @@ try{ |
|
|
|
// 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())); |
|
|
|
@ -276,7 +279,7 @@ try{ |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("模型实例创建失败,错误信息: ", e); |
|
|
|
throw exception(CREATE_INSTANT_ERROR,"模型实例创建失败: " + e.getMessage()); |
|
|
|
throw exception(CREATE_INSTANT_ERROR, "模型实例创建失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@ -485,4 +488,75 @@ try{ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public InstantCalcResultVO calcInstant(InstantCalcReqVO calcReqVO) { |
|
|
|
InstantCalcResultVO instantCalcResultVO = new InstantCalcResultVO(); |
|
|
|
//根据mpId读取实例信息
|
|
|
|
InstantDO instant = instantMapper.selectById(calcReqVO.getMpId()); |
|
|
|
if (instant == null) { |
|
|
|
throw exception(INSTANT_NOT_EXISTS); |
|
|
|
} |
|
|
|
|
|
|
|
calcReqVO.setExA_IP(EXA_IP); |
|
|
|
calcReqVO.setModel(instant.getModelInfo()); |
|
|
|
calcReqVO.setInstantInfo_Str(instant.getInstantInfo()); |
|
|
|
InstantInfoVO instantInfoVO = JsonUtils.parseObject(instant.getInstantInfo(), InstantInfoVO.class); |
|
|
|
List<String> pointInfoList = instantInfoVO.getInputInfo(); |
|
|
|
//循环point
|
|
|
|
// 新增:循环处理每个输入点,查询预警计算配置
|
|
|
|
List<Map<String, Object>> warnCalcMapList = new ArrayList<>(); |
|
|
|
for (String pointId : pointInfoList) { |
|
|
|
// 根据pointId查询预警计算记录(假设WarnCalcMapper有此查询方法)
|
|
|
|
WarnCalcDO warnCalc = warnCalcMapper.selectByPointId(pointId); |
|
|
|
Map<String, Object> calcInfoMap = new HashMap<>(3); |
|
|
|
if (warnCalc != null) { |
|
|
|
calcInfoMap.put("logic", warnCalc.getLastFormula().replaceAll("UPLIMIT", warnCalc.getUplimit()).replaceAll("LOWLIMIT", warnCalc.getLowlimit())); |
|
|
|
calcInfoMap.put("TimeLong", warnCalc.getTimeDurationThreshold()); |
|
|
|
calcInfoMap.put("Vaild", true); // 注意字段名是否与实体类一致
|
|
|
|
} else { |
|
|
|
calcInfoMap.put("logic", "1=1"); |
|
|
|
calcInfoMap.put("TimeLong", "0"); |
|
|
|
calcInfoMap.put("Vaild", false); // 注意字段名是否与实体类一致
|
|
|
|
} |
|
|
|
warnCalcMapList.add(calcInfoMap); |
|
|
|
|
|
|
|
} |
|
|
|
// 构建WarnInstants对象并转换为JSON字符串
|
|
|
|
Map<String, Object> warnInstantsObj = new HashMap<>(); |
|
|
|
warnInstantsObj.put("WarnInstants", warnCalcMapList); |
|
|
|
String warnInstantsJson = JsonUtils.toJsonString(warnInstantsObj); |
|
|
|
calcReqVO.setWarn_Instants_Str(warnInstantsJson); // 假设InstantCalcResultVO有此setter方法
|
|
|
|
|
|
|
|
//调用http接口,获取计算结果 http://120.26.116.243:8098/api/PCA/deepTrack
|
|
|
|
// String url = "http://120.26.116.243:8098/api/PCA/deepTrack";
|
|
|
|
String params = JsonUtils.toJsonString(calcReqVO); |
|
|
|
// 调用http接口,获取计算结果
|
|
|
|
String httpResult = HttpUtils.post(PCA_CALC_URL, null, params); |
|
|
|
JSONObject jsonResult = JsonUtils.parseObject(httpResult, JSONObject.class); |
|
|
|
try { |
|
|
|
String result = jsonResult.getString("result"); |
|
|
|
if (!"OK".equals(result)) { |
|
|
|
throw exception(CALCULATE_ERROR, "计算失败"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
throw exception(CALCULATE_ERROR, "结果有误,返回结果为: " +jsonResult+ ",异常信息为: "+e.getMessage()); |
|
|
|
} |
|
|
|
// 解析返回结果
|
|
|
|
String rtn = jsonResult.getString("rtn"); |
|
|
|
// ... 新增:检查 rtn 是否为空
|
|
|
|
if (StrUtil.isBlank(rtn)) { |
|
|
|
throw exception(CALCULATE_ERROR, "计算结果 rtn 为空"); |
|
|
|
} |
|
|
|
// ... 新增:捕获 JSON 解析异常
|
|
|
|
try { |
|
|
|
instantCalcResultVO = JsonUtils.parseObject(rtn, InstantCalcResultVO.class); |
|
|
|
} catch (Exception e) { |
|
|
|
throw exception(CALCULATE_ERROR, "解析计算结果失败,rtn: " + rtn + ",异常信息: " + e.getMessage()); |
|
|
|
} |
|
|
|
// 3. 记录操作日志上下文
|
|
|
|
LogRecordContext.putVariable("instant", calcReqVO); |
|
|
|
return instantCalcResultVO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|