|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.alert.service.instant; |
|
|
import cn.hutool.core.util.ObjUtil; |
|
|
import cn.hutool.core.util.ObjUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|
|
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.json.JsonUtils; |
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.Point; |
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.Point; |
|
|
@ -13,16 +14,14 @@ 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.instant.InstantTableDO; |
|
|
import cn.iocoder.yudao.module.alert.dal.dataobject.report.Report; |
|
|
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.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.InstantMapper; |
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.instant.InstantTableMapper; |
|
|
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.model.VersionMapper; |
|
|
import cn.iocoder.yudao.module.alert.dal.mysql.report.ReportMapper; |
|
|
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.service.warn.WarnService; |
|
|
import cn.iocoder.yudao.module.alert.utils.EXAUtils; |
|
|
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.google.common.annotations.VisibleForTesting; |
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
import com.mzt.logapi.context.LogRecordContext; |
|
|
import com.mzt.logapi.context.LogRecordContext; |
|
|
import com.mzt.logapi.service.impl.DiffParseFunction; |
|
|
import com.mzt.logapi.service.impl.DiffParseFunction; |
|
|
@ -36,13 +35,8 @@ import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.time.Instant; |
|
|
import java.util.*; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
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.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
|
|
import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; |
|
|
import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; |
|
|
@ -50,6 +44,7 @@ import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; |
|
|
@Service |
|
|
@Service |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class InstantServiceImpl implements InstantService { |
|
|
public class InstantServiceImpl implements InstantService { |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private InstantMapper instantMapper; |
|
|
private InstantMapper instantMapper; |
|
|
@Resource |
|
|
@Resource |
|
|
@ -63,7 +58,11 @@ public class InstantServiceImpl implements InstantService { |
|
|
|
|
|
|
|
|
private WarnService warnService; |
|
|
private WarnService warnService; |
|
|
|
|
|
|
|
|
|
|
|
// 新增:注入WarnCalcMapper用于查询预警计算配置
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private WarnCalcMapper warnCalcMapper; |
|
|
EXAUtils exaUtils = new EXAUtils(); |
|
|
EXAUtils exaUtils = new EXAUtils(); |
|
|
|
|
|
// 新增:从配置文件注入exaip
|
|
|
@Value("${point.head}") |
|
|
@Value("${point.head}") |
|
|
private String HEAD; |
|
|
private String HEAD; |
|
|
@Value("${EXA.ip}") |
|
|
@Value("${EXA.ip}") |
|
|
@ -488,4 +487,60 @@ 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(JsonUtils.toJsonString(instant.getModelInfo())); |
|
|
|
|
|
calcReqVO.setInstantInfo_Str( JsonUtils.toJsonString(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"; |
|
|
|
|
|
// 调用http接口,获取计算结果
|
|
|
|
|
|
String result = HttpUtils.post(url, null, JsonUtils.toJsonString(calcReqVO)); |
|
|
|
|
|
// 解析返回结果
|
|
|
|
|
|
instantCalcResultVO = JsonUtils.parseObject(result, InstantCalcResultVO.class); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 记录操作日志上下文
|
|
|
|
|
|
LogRecordContext.putVariable("instant", calcReqVO); |
|
|
|
|
|
return instantCalcResultVO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|