Browse Source

修改智能诊断任务闭环

zhongwei
tyty 1 year ago
parent
commit
ebc4ddf2cc
  1. 2
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/EquipmentConstants.java
  2. 2
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java
  3. 93
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java

2
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/EquipmentConstants.java

@ -3,7 +3,7 @@ package com.hnac.hzims;
import lombok.Getter; import lombok.Getter;
public class EquipmentConstants { public class EquipmentConstants {
public final static String APP_NAME = "hzims-equipment"; public final static String APP_NAME = "hzims-equipment-ty";
public enum TaskTypeEnum{ public enum TaskTypeEnum{
MANUAL("1","手动"), MANUAL("1","手动"),

2
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java

@ -208,7 +208,7 @@ public class ThreadTask {
diagnoseFaultReq.setTaskId(req.getId().toString()); diagnoseFaultReq.setTaskId(req.getId().toString());
diagnoseFaultReq.setFaultId(req.getFaultId()); diagnoseFaultReq.setFaultId(req.getFaultId());
diagnoseFaultReq.setConfidence(1.0); diagnoseFaultReq.setConfidence(1.0);
diagnoseFaultReq.setLifeTime(1); diagnoseFaultReq.setLifeTime(24*3);//设置有效期3天
diagnoseFaultReq.setPriority(2); diagnoseFaultReq.setPriority(2);
diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName()); diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName());

93
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java

@ -76,6 +76,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -127,7 +128,7 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
public String updateFaultState; public String updateFaultState;
private final static String JOINT_RELAY_SIGNAGE = "joint_relay";//合位继电器 private final static String JOINT_RELAY_SIGNAGE = "joint_relay";//合位继电器
private final static String KEY_FOR_FDP_TASK_ID = "fdp_task_id";//redis保存key
@Override @Override
public List<MonitorBandingReq> getMonitorBanding() { public List<MonitorBandingReq> getMonitorBanding() {
@ -298,8 +299,8 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
@Override @Override
public List<FdpMonitorEntity> list(FdpMonitorDTO req) { public List<FdpMonitorEntity> list(FdpMonitorDTO req) {
LambdaQueryWrapper<FdpMonitorEntity> qw = Wrappers.lambdaQuery(); LambdaQueryWrapper<FdpMonitorEntity> qw = Wrappers.lambdaQuery();
if(CollectionUtil.isNotEmpty(req.getMonitorIds())) { if (CollectionUtil.isNotEmpty(req.getMonitorIds())) {
qw.in(FdpMonitorEntity::getFdpId,req.getMonitorIds()); qw.in(FdpMonitorEntity::getFdpId, req.getMonitorIds());
} }
return this.list(qw); return this.list(qw);
} }
@ -461,11 +462,43 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
// /**获取实时、历史数据**/ // /**获取实时、历史数据**/
// FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); // FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
// String key = UUID.randomUUID().toString(); // String key = UUID.randomUUID().toString();
//拿到最近一次未完成的任务
FdpTaskEntity fdpTaskEntity = fdpTaskService.getOne(new LambdaQueryWrapper<FdpTaskEntity>() {{
eq(FdpTaskEntity::getFaultId, taskDTO.getFaultId());
eq(FdpTaskEntity::getIsDeleted, 0);
in(FdpTaskEntity::getStatus, 1, 2);//未开始或者未完成
orderByDesc(FdpTaskEntity::getCreateTime);
last("limit 1");
}});
String key;
if (Func.isNotEmpty(fdpTaskEntity)) {
Boolean hasKey = redisTemplate.hasKey(KEY_FOR_FDP_TASK_ID + "_" + fdpTaskEntity.getId().toString());
//Redis中存在,该任务没过期。用该任务Id
if (hasKey) {
key = fdpTaskEntity.getId().toString();
} else {
//该任务过期,更改状态为过期,新增一个任务
fdpTaskEntity.setStatus(4);
fdpTaskService.updateById(fdpTaskEntity);
boolean flag = fdpTaskService.save(taskDTO); boolean flag = fdpTaskService.save(taskDTO);
if (!flag) { if (!flag) {
return R.fail("诊断任务保存失败"); return R.fail("诊断任务保存失败");
} }
String key = taskDTO.getId().toString(); key = taskDTO.getId().toString();
redisTemplate.opsForValue().set(KEY_FOR_FDP_TASK_ID + "_" + key, key);
Boolean expire = redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + key,3, TimeUnit.DAYS);
System.out.println(expire);
}
} else {
//没有未完成的任务,新增一个任务
boolean flag = fdpTaskService.save(taskDTO);
if (!flag) {
return R.fail("诊断任务保存失败");
}
key = taskDTO.getId().toString();
redisTemplate.opsForValue().set(KEY_FOR_FDP_TASK_ID + "_" + key, key);
redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + key, 3, TimeUnit.DAYS);
}
// //异步处理 20230426 此接口弃用 // //异步处理 20230426 此接口弃用
ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, key); ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, key);
//获取数据成功-》 告知前端 //获取数据成功-》 告知前端
@ -478,7 +511,8 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
public R getNextstepData(String id) { public R getNextstepData(String id) {
Object o = redisTemplate.opsForValue().get(fdpReturnValuePath + "_" + id); Object o = redisTemplate.opsForValue().get(fdpReturnValuePath + "_" + id);
if (ObjectUtil.isNotEmpty(o)) { if (ObjectUtil.isNotEmpty(o)) {
R r = JSONObject.parseObject(o.toString(), new TypeReference<R>() {{}}); R r = JSONObject.parseObject(o.toString(), new TypeReference<R>() {{
}});
return r; return r;
} }
return R.data("-1"); return R.data("-1");
@ -495,18 +529,26 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
if (ObjectUtil.isEmpty(fdpFaultEntity)) { if (ObjectUtil.isEmpty(fdpFaultEntity)) {
throw new ServiceException("获取对应故障对象失败"); throw new ServiceException("获取对应故障对象失败");
} }
/**推送数据**/ Boolean hasKey = redisTemplate.hasKey(KEY_FOR_FDP_TASK_ID + "_" + diagnoseFaultReq.getTaskId().toString());
FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); //Redis中不存在,该任务过期
if (!hasKey) {
return R.fail("该任务已过期,请重新生成任务");
}
/**更新故障状态**/ /**更新故障状态**/
DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq();
faultAllReq.setAutoData(pushResp); /**推送数据**/
//20230710取消实时数据推送
// FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
// faultAllReq.setAutoData(pushResp);
faultAllReq.setStationId(fdpFaultEntity.getStationId()); faultAllReq.setStationId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setLifeTime(24*3);//一旦用户进行修改,智能诊断时效性刷新为3天
faultAllReq.setManualData(diagnoseFaultReq); faultAllReq.setManualData(diagnoseFaultReq);
String jsonString = JSONObject.toJSONString(faultAllReq); String jsonString = JSONObject.toJSONString(faultAllReq);
System.out.println(jsonString); System.out.println(jsonString);
HttpResponse r = HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq)); HttpResponse r = HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq));
redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + diagnoseFaultReq.getTaskId(), 3, TimeUnit.DAYS);
return JSONObject.parseObject(r.getData(), BaseResp.class).convert2R(); return JSONObject.parseObject(r.getData(), BaseResp.class).convert2R();
} }
@ -524,13 +566,13 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
@Override @Override
public String getFaultList() { public String getFaultList() {
List<String> list = this.baseMapper.selectStationIds(); List<String> list = this.baseMapper.selectStationIds();
if(CollectionUtil.isEmpty(list)){ if (CollectionUtil.isEmpty(list)) {
return null; return null;
} }
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
paramMap.put("stationIds", list.toArray(new String[0])); paramMap.put("stationIds", list.toArray(new String[0]));
String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST");
if(StringUtil.isBlank(result)){ if (StringUtil.isBlank(result)) {
return null; return null;
} }
return JSONObject.parseObject(result).get("data").toString(); return JSONObject.parseObject(result).get("data").toString();
@ -556,7 +598,7 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
// 描述 // 描述
paramMap.put("info", state.getInfo()); paramMap.put("info", state.getInfo());
String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST");
if(StringUtil.isBlank(result)){ if (StringUtil.isBlank(result)) {
return null; return null;
} }
return JSONObject.parseObject(result).get("data").toString(); return JSONObject.parseObject(result).get("data").toString();
@ -809,33 +851,36 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
} }
return vo; return vo;
} }
@Override @Override
public R dataBackV2(String faultId) { public R dataBackV2(String faultId) {
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
resultMap.put("faultId", faultId); resultMap.put("faultId", faultId);
String post = HttpRequestUtil.postCallObjectParam(resultMap, getRealByFault, "POST"); String post = HttpRequestUtil.postCallObjectParam(resultMap, getRealByFault, "POST");
FdpHttpResponseVo fdpHttpResponseVo = JSONObject.parseObject(post, new TypeReference<FdpHttpResponseVo>() {}); FdpHttpResponseVo fdpHttpResponseVo = JSONObject.parseObject(post, new TypeReference<FdpHttpResponseVo>() {
if (1==fdpHttpResponseVo.getSuccess()) { });
if (1 == fdpHttpResponseVo.getSuccess()) {
if (Func.isNotEmpty(fdpHttpResponseVo.getData())) { if (Func.isNotEmpty(fdpHttpResponseVo.getData())) {
List<FdpFaultRealDataDTO> list = JSONObject.parseObject(fdpHttpResponseVo.getData(), new TypeReference<List<FdpFaultRealDataDTO>>() {}); List<FdpFaultRealDataDTO> list = JSONObject.parseObject(fdpHttpResponseVo.getData(), new TypeReference<List<FdpFaultRealDataDTO>>() {
if (CollectionUtil.isEmpty(list)){ });
if (CollectionUtil.isEmpty(list)) {
return R.success("暂无数据,请稍后重试"); return R.success("暂无数据,请稍后重试");
} }
List<FdpFaultRealDataVO> res =new ArrayList<>(); List<FdpFaultRealDataVO> res = new ArrayList<>();
for (FdpFaultRealDataDTO fdpFaultRealDataDTO : list) { for (FdpFaultRealDataDTO fdpFaultRealDataDTO : list) {
if (null!=fdpFaultRealDataDTO.getReal()){ if (null != fdpFaultRealDataDTO.getReal()) {
for (int i = 0; i < fdpFaultRealDataDTO.getReal().size(); i++ ) { for (int i = 0; i < fdpFaultRealDataDTO.getReal().size(); i++) {
FdpFaultRealDataVO dataVO=new FdpFaultRealDataVO(); FdpFaultRealDataVO dataVO = new FdpFaultRealDataVO();
BeanUtils.copyProperties(fdpFaultRealDataDTO,dataVO); BeanUtils.copyProperties(fdpFaultRealDataDTO, dataVO);
dataVO.setReal(fdpFaultRealDataDTO.getReal().get(i)); dataVO.setReal(fdpFaultRealDataDTO.getReal().get(i));
dataVO.setRealTime(fdpFaultRealDataDTO.getRealTime().get(i)); dataVO.setRealTime(fdpFaultRealDataDTO.getRealTime().get(i));
dataVO.setRealName(fdpFaultRealDataDTO.getRealName().get(i)); dataVO.setRealName(fdpFaultRealDataDTO.getRealName().get(i));
dataVO.setRealIdentifier(fdpFaultRealDataDTO.getRealIdentifier().get(i)); dataVO.setRealIdentifier(fdpFaultRealDataDTO.getRealIdentifier().get(i));
res.add(dataVO); res.add(dataVO);
} }
}else { } else {
FdpFaultRealDataVO dataVO=new FdpFaultRealDataVO(); FdpFaultRealDataVO dataVO = new FdpFaultRealDataVO();
BeanUtils.copyProperties(fdpFaultRealDataDTO,dataVO); BeanUtils.copyProperties(fdpFaultRealDataDTO, dataVO);
res.add(dataVO); res.add(dataVO);
} }
} }
@ -1041,7 +1086,7 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
XxlJobLogger.log(fdpDeviceCode+"实时数据返回:"+ JSON.toJSONString(realDataByAnalyzeCode)); XxlJobLogger.log(fdpDeviceCode + "实时数据返回:" + JSON.toJSONString(realDataByAnalyzeCode));
if (realDataByAnalyzeCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByAnalyzeCode.getData())) { if (realDataByAnalyzeCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByAnalyzeCode.getData())) {
FieldsData fieldsData = realDataByAnalyzeCode.getData().get(0); FieldsData fieldsData = realDataByAnalyzeCode.getData().get(0);
if (0 == fieldsData.getQ() && "1".equals(fieldsData.getValue())) { if (0 == fieldsData.getQ() && "1".equals(fieldsData.getValue())) {

Loading…
Cancel
Save