调用第三方数据校验接口
This commit is contained in:
@@ -29,6 +29,7 @@ import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.result.service.IResultService;
|
||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||
@@ -46,6 +47,7 @@ import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -80,6 +82,10 @@ public class SocketDevResponseService {
|
||||
private final IAdPlanService adPlanService;
|
||||
private final IDictDataService dictDataService;
|
||||
private final IPqSourceService pqSourceService;
|
||||
private final IResultService resultService;
|
||||
|
||||
@Value("${dataCheck.enable}")
|
||||
private Boolean dataCheck;
|
||||
|
||||
/**
|
||||
* 存储的装置相序数据
|
||||
@@ -1380,6 +1386,9 @@ public class SocketDevResponseService {
|
||||
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||
|
||||
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
|
||||
if (dataCheck) {
|
||||
resultService.tryNotifyThirdPartyAfterFormalTest(param);
|
||||
}
|
||||
CnSocketUtil.quitSend(param);
|
||||
// 数模式检测全部小项完成 → 释放锁,避免用户必须点"停止"才能让出
|
||||
DetectionLockManager.getInstance()
|
||||
@@ -1806,6 +1815,7 @@ public class SocketDevResponseService {
|
||||
|
||||
FormalTestManager.overload = getOverloadResult(param);
|
||||
FormalTestManager.checkStartTime = LocalDateTime.now();
|
||||
FormalTestManager.reCheckType = param.getReCheckType();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -219,4 +219,9 @@ public class FormalTestManager {
|
||||
* 检测开始时间
|
||||
*/
|
||||
public static LocalDateTime checkStartTime;
|
||||
|
||||
/**
|
||||
* 数模式 检测类型"1"-"全部检测" , "2"-"不合格项复检"
|
||||
*/
|
||||
public static String reCheckType;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ package com.njcn.gather.device.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2025-07-04
|
||||
*/
|
||||
public interface IPqDevSubService extends IService<PqDevSub> {
|
||||
|
||||
LocalDateTime resolveBatchMaxCheckEndTime(List<String> devIds);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.njcn.common.pojo.poi.PullDown;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.EncryptionUtil;
|
||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.device.mapper.PqDevMapper;
|
||||
import com.njcn.gather.device.pojo.dto.DataCheckResDTO;
|
||||
@@ -509,8 +510,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
LambdaUpdateWrapper<PqDevSub> wrapper = new LambdaUpdateWrapper<PqDevSub>()
|
||||
.set(PqDevSub::getCheckResult, result.get(pqDevVo.getId()))
|
||||
.set(StrUtil.isNotBlank(userId), PqDevSub::getCheckBy, userId)
|
||||
.set(updateCheckNum, PqDevSub::getCheckEndTime, LocalDateTime.now())
|
||||
.set(updateCheckNum && ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, FormalTestManager.checkStartTime)
|
||||
.set(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType), PqDevSub::getCheckEndTime, LocalDateTime.now())
|
||||
.set(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType) && ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, FormalTestManager.checkStartTime)
|
||||
.eq(PqDevSub::getDevId, pqDevVo.getId());
|
||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||
if (SceneEnum.PROVINCE_PLATFORM.getValue().equals(currrentScene)) {
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package com.njcn.gather.device.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.mapper.PqDevSubMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2025-07-04
|
||||
@@ -16,5 +23,19 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqDevSubServiceImpl extends ServiceImpl<PqDevSubMapper, PqDevSub> implements IPqDevSubService {
|
||||
|
||||
|
||||
@Override
|
||||
public LocalDateTime resolveBatchMaxCheckEndTime(List<String> devIds) {
|
||||
if (CollUtil.isEmpty(devIds)) {
|
||||
return null;
|
||||
}
|
||||
return this.list(new LambdaQueryWrapper<PqDevSub>()
|
||||
.in(PqDevSub::getDevId, devIds)
|
||||
.isNotNull(PqDevSub::getCheckEndTime))
|
||||
.stream()
|
||||
.map(PqDevSub::getCheckEndTime)
|
||||
.filter(Objects::nonNull)
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -131,3 +131,6 @@ power-quality:
|
||||
activate:
|
||||
private-key: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCcUyYhVqczGxblL+o/xZzF/8nf+LjrfUE/dS1aRHM7uMDD0cgCArhjtfneFePrMxt+Z7W8yNBzSarub8qsfhaVNikV7Es7oaeTygfjQXTi2n4AFkir3fM07J08RpWhl5M8f8uWTCuvFUYAw00gq55typqmnbkmJa2VIUy/iQf+cMCP7abz4/jNhUzUR3qA7TV4oMRgTdIEDUp63YF8dOC+JH8XxYrCVeHXV6fLCwmesdMzl0lB2VTEKMfLbXhOmF5g7P9y/16VCcN8UBuZlbyYfn+GAxJOSbeHi5HshOKfoSuD7Jz+3WQZpNavOWjIFExKIU38/CvnJCOP7XBCqpSTAgMBAAECggEAYeWokWRE3TpvwiOZnUpR/aVMdVi75a3ROL5XIpqPV61B+t/bU3cEpl0GF9C5pUeiRi0IoStZb3mI9D1KPW/REKyUWkhabQO1gFYbTnRlkNOn6MILzKX4cwJjDaZeeo4EBPU7N+qHyOOXrU6hdH5FfxhMdV983ajm5eeuupxER1C2kAcIklTeVpTX6EKOgZb5LBp5ssOVm2P42pOauvcRozRcvZmqnErXmukv0H4l3EVNt4rHpTn9riHUC63e8JfiYzVaF6zuNUxv6nHEft0/SRMw11XSTnNfDzcKqgjz6ksFBS/6eQQYKESk+ONC53HUuYHFAknkwsPupDCT2W8FIQKBgQDLHT/xCU3nxGr4vFKBDNaO2D5oK20ECbBO4oDvLWWmQG7f+6TsMy8PgVdMnoL4RfqGlwFAKEpS6KVFHnBVqnNEhcdy9uCI7x7Xx8UnyUtxj1EDTm76uta9Ki9OrlqB6tImDM9+Ya3vGktW37ht4WOx2OsJRhG1dbf6RLwFlH7DWwKBgQDFBxvi5I1BR6hg6Tj7xd2SqOT2Y+BED3xuSYENhWbmMhLJDResaB7mjztbxlYaY2mOE0holWm2uDmVFFhMh4jYXik4hYH8nmDzq9mDpZCZ9pyjYqnAP8THoAa8EbgrUWB8A6BPH4iL3KbMnBfBKY0pIr2xrvnjQjNBAgta7KDRKQKBgCe6oe4wxrdF2TKsC2tIqpMoQxS3Icy/ZGgZr+SYuaBKTCWtoDW/UT40K3JGMxIDBhzbXphBCUCsVt9tM8Xd4EwP6tJW7dZ7B0pnve2pVwNwaAVAiz6p2yUHIle+jN+Koe5lZRSwYIg7WW81tWpwwsJfzqFyvjYDP6hJV4mz4ROvAoGAaRcdnKvjXApomShMqJ4lTPChD3q+SA8qg3jZSOj6tZXHx00gb2kp8jg7pPvpOTIFPy6x1Ha9aCRjMk0ju84fA6lVuzwa1S907wOehUVuF3Eeo1cgy9Y3k3KbpPyeixxgpkUY4JslLdSHc2NemD0dee951qhJyRmqVOZOQDUuoeECgYEAqBw2cAFk3vM97WY06TSldGA8ajVHx3BYRjj+zl62NTQthy8fw3tqxb3c5e8toOmZWKjZvDhg2TRLhsDDQWEYg3LZG87REqVIjgEPcpjNLidjygGX8n3JF2o0O5I/EMvl0s/+LVQONfduOBvhwDqr8QNisbLsyneiAq7umewMolo="
|
||||
public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFMmIVanMxsW5S/qP8Wcxf/J3/i4631BP3UtWkRzO7jAw9HIAgK4Y7X53hXj6zMbfme1vMjQc0mq7m/KrH4WlTYpFexLO6Gnk8oH40F04tp+ABZIq93zNOydPEaVoZeTPH/LlkwrrxVGAMNNIKuebcqapp25JiWtlSFMv4kH/nDAj+2m8+P4zYVM1Ed6gO01eKDEYE3SBA1Ket2BfHTgviR/F8WKwlXh11enywsJnrHTM5dJQdlUxCjHy214TpheYOz/cv9elQnDfFAbmZW8mH5/hgMSTkm3h4uR7ITin6Erg+yc/t1kGaTWrzloyBRMSiFN/Pwr5yQjj+1wQqqUkwIDAQAB"
|
||||
|
||||
dataCheck:
|
||||
enable: true
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.result.pojo.param.DataCheckRequest;
|
||||
import com.njcn.gather.result.service.impl.ResultServiceImpl;
|
||||
import com.njcn.http.util.RestTemplateUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ResultChecksquareCreateTest {
|
||||
|
||||
@Mock
|
||||
private IPqMonitorService pqMonitorService;
|
||||
@Mock
|
||||
private IPqDevSubService pqDevSubService;
|
||||
@Mock
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
|
||||
@Test
|
||||
public void createChecksquareTaskByDevIdBuildsRequestAndReturnsThirdPartyResponse() {
|
||||
String devId = "dev-1";
|
||||
PqMonitor monitor1 = new PqMonitor();
|
||||
monitor1.setId("line-1");
|
||||
PqMonitor monitor2 = new PqMonitor();
|
||||
monitor2.setId("line-2");
|
||||
PqDevSub devSub = new PqDevSub();
|
||||
devSub.setCheckStartTime(LocalDateTime.of(2026, 6, 22, 10, 1, 2));
|
||||
devSub.setCheckEndTime(LocalDateTime.of(2026, 6, 22, 11, 3, 4));
|
||||
|
||||
when(pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(devId))).thenReturn(Arrays.asList(monitor1, monitor2));
|
||||
when(pqDevSubService.getOne(any(), eq(false))).thenReturn(devSub);
|
||||
ArgumentCaptor<DataCheckRequest> requestCaptor = ArgumentCaptor.forClass(DataCheckRequest.class);
|
||||
when(restTemplateUtil.postJson(eq(ResultServiceImpl.CHECKSQUARE_CREATE_URL), requestCaptor.capture(), eq(String.class)))
|
||||
.thenReturn("{\"code\":0}");
|
||||
|
||||
ResultServiceImpl resultService = new ResultServiceImpl(null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null, null, pqMonitorService, null, null,
|
||||
pqDevSubService, null, restTemplateUtil);
|
||||
|
||||
String response = resultService.createChecksquareTaskByDevId(devId);
|
||||
|
||||
DataCheckRequest request = requestCaptor.getValue();
|
||||
assertEquals("{\"code\":0}", response);
|
||||
assertEquals(Arrays.asList("line-1", "line-2"), request.getLineIds());
|
||||
assertTrue(request.getIndicatorCodes().isEmpty());
|
||||
assertEquals("2026-06-22 10:01:02", request.getTimeStart());
|
||||
assertEquals("2026-06-22 11:03:04", request.getTimeEnd());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user