增加部分教学模式,微调部分代码,增加原始数据转换工具类

This commit is contained in:
wr
2025-03-05 11:44:08 +08:00
parent 273dd18405
commit 6fb6733727
7 changed files with 215 additions and 69 deletions

View File

@@ -34,7 +34,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@@ -71,6 +70,32 @@ public class PreDetectionController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 关闭检测
*/
@PostMapping("/closeCheck")
@OperateInfo
@ApiOperation("关闭检测")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> closeCheck(@RequestBody @Validated PreDetectionParam param){
String methodDescribe = getMethodDescribe("closeCheck");
preDetectionService.closeCheck(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 下一步检测
*/
@PostMapping("/nextScript")
@OperateInfo
@ApiOperation("下一步检测")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> nextScript(@RequestBody @Validated PreDetectionParam param){
String methodDescribe = getMethodDescribe("nextScript");
preDetectionService.nextScript(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 系数校验

View File

@@ -149,8 +149,6 @@ public class SocketDevResponseService {
}
/**
* 系数校验
*/
@@ -298,7 +296,6 @@ public class SocketDevResponseService {
}
private void processData(PreDetectionParam param, SocketMsg<String> xiSocket) {
System.out.println(XiNumberManager.stepNumber + "从装置中已经完成获取测试数据,准备开始计算----------------------");
Map<String, List<DevData>> realDataXiMap = FormalTestManager.realDataXiList.stream().collect(Collectors.groupingBy(it -> it.getId().split(splitTag)[0]));
@@ -948,7 +945,6 @@ public class SocketDevResponseService {
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(socketMsg));
XiNumberManager.stepNumber = 0;
XiNumberManager.devXiList.clear();
XiNumberManager.devXiNumDataMap.clear();
@@ -1047,7 +1043,7 @@ public class SocketDevResponseService {
allDevTestList.clear();
CnSocketUtil.sendToWebSocket(param.getUserPageId(), socketDataMsg.getRequestId().split(stepTag)[1] + stepEnd, null, resultList, null);
}
if (!param.getIsTeachingMode()) {
//在这一步判断是否已经触发暂停按钮
if (FormalTestManager.stopFlag && CollUtil.isNotEmpty(SocketManager.getSourceList())) {
FormalTestManager.stopTime = 0;
@@ -1081,6 +1077,7 @@ public class SocketDevResponseService {
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode());
CnSocketUtil.quitSend(param);
}
}
successComm.clear();
FormalTestManager.realDataXiList.clear();
@@ -1111,6 +1108,8 @@ public class SocketDevResponseService {
}
/*
private void processData(List<DevData> FormalTestManager.realDataXiList, List<String> successComm, SourceIssue sourceIssue, PreDetectionParam param, SocketDataMsg socketDataMsg, Object dataRule, String handlerSourceStr) {
if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) {

View File

@@ -61,4 +61,9 @@ public class PreDetectionParam {
* 自动生成,用于生成数据表后缀
*/
private String code;
/**
* 是否是教学模式
*/
private Boolean isTeachingMode=false;
}

View File

@@ -31,6 +31,8 @@ public interface PreDetectionService {
boolean restartTemTest(PreDetectionParam param);
void closeCheck(PreDetectionParam param);
void nextScript(PreDetectionParam param);
}

View File

@@ -42,10 +42,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@@ -198,6 +195,39 @@ public class PreDetectionServiceImpl implements PreDetectionService {
return true;
}
@Override
public void closeCheck(PreDetectionParam param) {
commCheck(param);
specialDeal(param);
}
@Override
public void nextScript(PreDetectionParam param) {
//开始进行下一项检测
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
long residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
if (CollUtil.isNotEmpty(sourceIssueList)) {
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
if (residueCount == 0) {
CnSocketUtil.sendToWebSocket(param.getUserPageId(), sourceIssues.getType() + "_Start", null, new ArrayList<>(), null);
}
SocketMsg<String> xuMsg = new SocketMsg<>();
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xuMsg.setData(JSON.toJSONString(sourceIssues));
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
SocketManager.sendMsg(param.getUserPageId() + "_Source", JSON.toJSONString(xuMsg));
} else {
//TODO 是否最终检测完成需要推送给用户
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode());
CnSocketUtil.quitSend(param);
}
}
/**
* 对重复发起或者异常发起的检测进行关闭源操作

View File

@@ -34,7 +34,7 @@ public class FormalTestManager {
//用于存储所有测点的试试数据
//用于存储所有测点的实时数据
public static List<DevData> realDataXiList = new ArrayList<>();

View File

@@ -1,14 +1,21 @@
package com.njcn.gather.detection.util.socket;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import java.lang.reflect.Field;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author wr
@@ -19,7 +26,6 @@ import java.util.Map;
public class MsgUtil {
public static SocketDataMsg socketDataMsg(String textMsg) {
return JSON.parseObject(textMsg, SocketDataMsg.class);
}
@@ -46,7 +52,6 @@ public class MsgUtil {
/**
*
* @param socketDataMsg
* @param devMap
* @param type 0.装置 1.监测点
@@ -71,6 +76,86 @@ public class MsgUtil {
return JSON.toJSONString(socketDataMsg);
}
public List<DevData> toList(List<AdNonHarmonicResult> nonHarm, List<AdHarmonicResult> harm) {
List<DevData> info = new ArrayList<>();
if (CollUtil.isNotEmpty(nonHarm)) {
if (CollUtil.isNotEmpty(nonHarm)) {
Map<String, List<AdNonHarmonicResult>> noHarmMap = nonHarm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN)) + "_" + x.getSort()));
noHarmMap.forEach((key, value) -> {
String[] split = key.split("_");
DevData data = new DevData();
data.setTime(split[1]);
data.setId(split[0]);
List<DevData.SqlDataDTO> sqlDataDTOS = new ArrayList<>();
DevData.SqlDataDTO sqlDataDTO;
for (AdNonHarmonicResult result : value) {
sqlDataDTO = new DevData.SqlDataDTO();
sqlDataDTO.setType(result.getDataType());
sqlDataDTO.setDesc(result.getAdType());
DevData.SqlDataDTO.ListDTO listDTO = new DevData.SqlDataDTO.ListDTO();
listDTO.setA(StrUtil.isNotBlank(result.getAValue()) ? Double.valueOf(result.getAValue()) : null);
listDTO.setB(StrUtil.isNotBlank(result.getBValue()) ? Double.valueOf(result.getBValue()) : null);
listDTO.setC(StrUtil.isNotBlank(result.getCValue()) ? Double.valueOf(result.getCValue()) : null);
listDTO.setT(StrUtil.isNotBlank(result.getTValue()) ? Double.valueOf(result.getTValue()) : null);
sqlDataDTO.setList(listDTO);
sqlDataDTOS.add(sqlDataDTO);
}
data.setSqlData(sqlDataDTOS);
info.add(data);
});
}
if (CollUtil.isNotEmpty(harm)) {
Map<String, List<AdHarmonicResult>> harmMap = harm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN))));
harmMap.forEach((key, value) -> {
List<DevData> collect = info.stream().filter(x -> key.equals(x.getId() + "_" + x.getTime())).collect(Collectors.toList());
List<DevData.SqlDataHarmDTO> sqlDataDTOS = new ArrayList<>();
DevData.SqlDataHarmDTO dataDTO;
for (AdHarmonicResult harmonicResult : value) {
dataDTO = new DevData.SqlDataHarmDTO();
dataDTO.setType(harmonicResult.getDataType());
dataDTO.setDesc(harmonicResult.getAdType());
dataDTO.setNum(49);
DevData.SqlDataHarmDTO.ListDTO listDTO = new DevData.SqlDataHarmDTO.ListDTO();
listDTO.setA(reflectHarmonicValue("a", harmonicResult));
listDTO.setB(reflectHarmonicValue("b", harmonicResult));
listDTO.setC(reflectHarmonicValue("c", harmonicResult));
dataDTO.setList(listDTO);
sqlDataDTOS.add(dataDTO);
}
if (CollUtil.isNotEmpty(collect)) {
collect.get(0).setSqlDataHarm(sqlDataDTOS);
} else {
String[] split = key.split("_");
DevData data = new DevData();
data.setTime(split[1]);
data.setId(split[0]);
data.setSqlDataHarm(sqlDataDTOS);
info.add(data);
}
});
}
}
return info;
}
private List<String> reflectHarmonicValue(String phase, AdHarmonicResult adHarmonicResult) {
List<String> info = new ArrayList<>();
for (int i = 2; i < 50; i++) {
String fieldName = phase + "Value" + i;
try {
Field idField = AdHarmonicResult.class.getDeclaredField(fieldName);
idField.setAccessible(true);
String value = idField.get(adHarmonicResult) + "";
info.add(value);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return info;
}
}