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. 61
      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;
public class EquipmentConstants {
public final static String APP_NAME = "hzims-equipment";
public final static String APP_NAME = "hzims-equipment-ty";
public enum TaskTypeEnum{
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.setFaultId(req.getFaultId());
diagnoseFaultReq.setConfidence(1.0);
diagnoseFaultReq.setLifeTime(1);
diagnoseFaultReq.setLifeTime(24*3);//设置有效期3天
diagnoseFaultReq.setPriority(2);
diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName());

61
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.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@ -127,7 +128,7 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
public String updateFaultState;
private final static String JOINT_RELAY_SIGNAGE = "joint_relay";//合位继电器
private final static String KEY_FOR_FDP_TASK_ID = "fdp_task_id";//redis保存key
@Override
public List<MonitorBandingReq> getMonitorBanding() {
@ -461,11 +462,43 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
// /**获取实时、历史数据**/
// FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
// 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);
if (!flag) {
return R.fail("诊断任务保存失败");
}
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("诊断任务保存失败");
}
String key = taskDTO.getId().toString();
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 此接口弃用
ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, key);
//获取数据成功-》 告知前端
@ -478,7 +511,8 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
public R getNextstepData(String id) {
Object o = redisTemplate.opsForValue().get(fdpReturnValuePath + "_" + id);
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.data("-1");
@ -495,18 +529,26 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
if (ObjectUtil.isEmpty(fdpFaultEntity)) {
throw new ServiceException("获取对应故障对象失败");
}
/**推送数据**/
FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
Boolean hasKey = redisTemplate.hasKey(KEY_FOR_FDP_TASK_ID + "_" + diagnoseFaultReq.getTaskId().toString());
//Redis中不存在,该任务过期
if (!hasKey) {
return R.fail("该任务已过期,请重新生成任务");
}
/**更新故障状态**/
DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq();
faultAllReq.setAutoData(pushResp);
/**推送数据**/
//20230710取消实时数据推送
// FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
// faultAllReq.setAutoData(pushResp);
faultAllReq.setStationId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId());
diagnoseFaultReq.setLifeTime(24*3);//一旦用户进行修改,智能诊断时效性刷新为3天
faultAllReq.setManualData(diagnoseFaultReq);
String jsonString = JSONObject.toJSONString(faultAllReq);
System.out.println(jsonString);
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();
}
@ -809,15 +851,18 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
}
return vo;
}
@Override
public R dataBackV2(String faultId) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("faultId", faultId);
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 (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)) {
return R.success("暂无数据,请稍后重试");
}

Loading…
Cancel
Save