调用第三方数据校验接口
This commit is contained in:
@@ -163,6 +163,18 @@ public class ResultController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/createChecksquareTask")
|
||||
@ApiOperation("调用第三方数模数据检测接口")
|
||||
@ApiImplicitParam(name = "devId", value = "设备id", required = true)
|
||||
public HttpResult<String> createChecksquareTask(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("createChecksquareTask");
|
||||
LogUtil.njcnDebug(log, "{},调用第三方数模数据检测接口,设备id为:{}", methodDescribe, devId);
|
||||
|
||||
String result = resultService.createChecksquareTaskByDevId(devId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/getMonitorDataSourceResult")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.result.pojo.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DataCheckRequest {
|
||||
private List<String> lineIds;
|
||||
private List<String> indicatorCodes;
|
||||
private String timeStart;
|
||||
private String timeEnd;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.gather.result.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据校验通知 上下文
|
||||
*/
|
||||
@Value
|
||||
@Builder
|
||||
public class DataCheckNotifyContext {
|
||||
String notifyKey;
|
||||
String planId;
|
||||
List<String> sortedDevIds;
|
||||
List<String> lineIds;
|
||||
LocalDateTime timeStart;
|
||||
LocalDateTime timeEnd;
|
||||
String reCheckType;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.njcn.gather.result.service;
|
||||
|
||||
import com.njcn.gather.result.pojo.param.DataCheckRequest;
|
||||
import com.njcn.gather.result.pojo.vo.DataCheckNotifyContext;
|
||||
import com.njcn.gather.result.service.impl.ResultServiceImpl;
|
||||
import com.njcn.http.util.RestTemplateUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class DataCheckAsyncNotifier {
|
||||
|
||||
private final static String url="http://172.17.100.111:18091/steady/checksquare/create";
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private final RestTemplateUtil restTemplateUtil;
|
||||
|
||||
@Async
|
||||
public void notifyAsync(DataCheckNotifyContext context, Map<String, ResultServiceImpl.NotifyState> notifyStates) {
|
||||
notifyDirect(context, notifyStates);
|
||||
}
|
||||
|
||||
void notifyDirect(DataCheckNotifyContext context, Map<String, ResultServiceImpl.NotifyState> notifyStates) {
|
||||
int maxRetries = 3;
|
||||
for (int attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
DataCheckRequest request = new DataCheckRequest();
|
||||
request.setLineIds(context.getLineIds());
|
||||
request.setIndicatorCodes(Collections.emptyList());
|
||||
request.setTimeStart(FORMATTER.format(context.getTimeStart()));
|
||||
request.setTimeEnd(FORMATTER.format(context.getTimeEnd()));
|
||||
|
||||
restTemplateUtil.postJson(url, request, String.class);
|
||||
notifyStates.put(context.getNotifyKey(),
|
||||
new ResultServiceImpl.NotifyState(ResultServiceImpl.NotifyStatus.SUCCESS, attempt - 1, null, LocalDateTime.now()));
|
||||
log.info("checksquare notify success, key={}, planId={}, lineCount={}", context.getNotifyKey(), context.getPlanId(), context.getLineIds().size());
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
int failCount = attempt;
|
||||
if (failCount > maxRetries) {
|
||||
notifyStates.put(context.getNotifyKey(),
|
||||
new ResultServiceImpl.NotifyState(ResultServiceImpl.NotifyStatus.FAIL, maxRetries, ex.getMessage(), LocalDateTime.now()));
|
||||
log.error("checksquare notify failed, key={}, failCount={}", context.getNotifyKey(), maxRetries, ex);
|
||||
return;
|
||||
}
|
||||
if (!sleepBeforeRetry(context, failCount)) {
|
||||
notifyStates.put(context.getNotifyKey(),
|
||||
new ResultServiceImpl.NotifyState(ResultServiceImpl.NotifyStatus.FAIL, failCount, "retry interrupted", LocalDateTime.now()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sleepBeforeRetry(DataCheckNotifyContext context, int failCount) {
|
||||
long delayMillis = (long) Math.pow(2, failCount) * 1000L;
|
||||
log.warn("checksquare notify retry scheduled, key={}, failCount={}, delayMillis={}", context.getNotifyKey(), failCount, delayMillis);
|
||||
try {
|
||||
Thread.sleep(delayMillis);
|
||||
return true;
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.gather.result.service;
|
||||
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.report.pojo.DevReportParam;
|
||||
import com.njcn.gather.report.pojo.result.ContrastTestResult;
|
||||
@@ -17,6 +18,10 @@ import java.util.Map;
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
public interface IResultService {
|
||||
void tryNotifyThirdPartyAfterFormalTest(PreDetectionParam param);
|
||||
|
||||
String createChecksquareTaskByDevId(String devId);
|
||||
|
||||
/**
|
||||
* 检测详情表单头
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.ResultEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.AdPair;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
@@ -31,12 +32,15 @@ import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||
import com.njcn.gather.detection.service.IAdPariService;
|
||||
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.device.service.IPqStandardDevService;
|
||||
import com.njcn.gather.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
@@ -55,8 +59,10 @@ import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||
import com.njcn.gather.report.pojo.result.ContrastTestResult;
|
||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.result.pojo.param.DataCheckRequest;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.*;
|
||||
import com.njcn.gather.result.service.DataCheckAsyncNotifier;
|
||||
import com.njcn.gather.result.service.IResultService;
|
||||
import com.njcn.gather.script.mapper.PqScriptMapper;
|
||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||
@@ -85,8 +91,10 @@ import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
||||
import com.njcn.gather.util.StorageUtil;
|
||||
import com.njcn.http.util.RestTemplateUtil;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -96,6 +104,7 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -132,6 +141,13 @@ public class ResultServiceImpl implements IResultService {
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
private final IPqStandardDevService standardDevService;
|
||||
private final IPqDevSubService pqDevSubService;
|
||||
private final DataCheckAsyncNotifier dataCheckAsyncNotifier;
|
||||
private final RestTemplateUtil restTemplateUtil;
|
||||
|
||||
public static final String CHECKSQUARE_CREATE_URL = "http://172.17.100.111:18091/steady/checksquare/create";
|
||||
private static final DateTimeFormatter CHECKSQUARE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private final Map<String, NotifyState> notifyStates = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 谐波类code,取树形字典表中的code
|
||||
@@ -139,6 +155,89 @@ public class ResultServiceImpl implements IResultService {
|
||||
private final List<String> HARMONIC_TYPE_CODE = Arrays.asList("HV", "HI", "HP", "HSV", "HSI");
|
||||
|
||||
|
||||
@Override
|
||||
public void tryNotifyThirdPartyAfterFormalTest(PreDetectionParam param) {
|
||||
if (param == null || !SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType)) {
|
||||
return;
|
||||
}
|
||||
if (ObjectUtil.isNull(FormalTestManager.checkStartTime)
|
||||
|| StrUtil.isBlank(param.getPlanId())
|
||||
|| CollUtil.isEmpty(param.getDevIds())
|
||||
|| CollUtil.isEmpty(FormalTestManager.monitorIdListComm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDateTime batchEndTime = pqDevSubService.resolveBatchMaxCheckEndTime(param.getDevIds());
|
||||
if (ObjectUtil.isNull(batchEndTime)) {
|
||||
log.warn("checksquare notify skipped, batch end time is empty, planId={}, devIds={}", param.getPlanId(), param.getDevIds());
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> sortedDevIds = param.getDevIds().stream().sorted().collect(Collectors.toList());
|
||||
String notifyKey = param.getPlanId() + "|" + String.join(",", sortedDevIds) + "|"
|
||||
+ CHECKSQUARE_TIME_FORMATTER.format(FormalTestManager.checkStartTime) + "|" + FormalTestManager.reCheckType;
|
||||
if (notifyStates.get(notifyKey) != null) {
|
||||
return;
|
||||
}
|
||||
if (notifyStates.putIfAbsent(notifyKey, NotifyState.running()) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DataCheckNotifyContext context = DataCheckNotifyContext.builder()
|
||||
.notifyKey(notifyKey)
|
||||
.planId(param.getPlanId())
|
||||
.sortedDevIds(sortedDevIds)
|
||||
.lineIds(new ArrayList<>(FormalTestManager.monitorIdListComm))
|
||||
.timeStart(FormalTestManager.checkStartTime)
|
||||
.timeEnd(batchEndTime)
|
||||
.reCheckType(FormalTestManager.reCheckType)
|
||||
.build();
|
||||
dataCheckAsyncNotifier.notifyAsync(context, notifyStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createChecksquareTaskByDevId(String devId) {
|
||||
if (StrUtil.isBlank(devId)) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL, "设备id不能为空");
|
||||
}
|
||||
|
||||
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(devId));
|
||||
if (CollUtil.isEmpty(monitorList)) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL, "该设备监测点不存在");
|
||||
}
|
||||
|
||||
PqDevSub devSub = pqDevSubService.getOne(new LambdaQueryWrapper<PqDevSub>()
|
||||
.eq(PqDevSub::getDevId, devId), false);
|
||||
if (ObjectUtil.isNull(devSub)
|
||||
|| ObjectUtil.isNull(devSub.getCheckStartTime())
|
||||
|| ObjectUtil.isNull(devSub.getCheckEndTime())) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL, "该设备检测开始时间或结束时间为空");
|
||||
}
|
||||
|
||||
DataCheckRequest request = new DataCheckRequest();
|
||||
request.setLineIds(monitorList.stream().map(PqMonitor::getId).collect(Collectors.toList()));
|
||||
request.setIndicatorCodes(Collections.emptyList());
|
||||
request.setTimeStart(CHECKSQUARE_TIME_FORMATTER.format(devSub.getCheckStartTime()));
|
||||
request.setTimeEnd(CHECKSQUARE_TIME_FORMATTER.format(devSub.getCheckEndTime()));
|
||||
return restTemplateUtil.postJson(CHECKSQUARE_CREATE_URL, request, String.class);
|
||||
}
|
||||
|
||||
public enum NotifyStatus {
|
||||
RUNNING, SUCCESS, FAIL
|
||||
}
|
||||
|
||||
@Value
|
||||
public static class NotifyState {
|
||||
NotifyStatus status;
|
||||
int failCount;
|
||||
String lastError;
|
||||
LocalDateTime triggerTime;
|
||||
|
||||
public static NotifyState running() {
|
||||
return new NotifyState(NotifyStatus.RUNNING, 0, null, LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormContentVO getFormContent(ResultParam.QueryParam queryParam) {
|
||||
FormContentVO formContentVO = new FormContentVO();
|
||||
|
||||
Reference in New Issue
Block a user