代码调整
This commit is contained in:
@@ -23,12 +23,18 @@ import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
||||
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -48,6 +54,9 @@ public class SocketDevResponseService {
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
private final DetectionServiceImpl detectionServiceImpl;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 存储的装置相序数据
|
||||
*/
|
||||
@@ -240,7 +249,6 @@ public class SocketDevResponseService {
|
||||
System.out.println(successXieyi3.size() + "=====" + monitorIdListComm.size());
|
||||
if (successXieyi3.size() == monitorIdListComm.size()) {
|
||||
|
||||
|
||||
SocketDataMsg temMsg = new SocketDataMsg();
|
||||
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
|
||||
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||
@@ -248,34 +256,36 @@ public class SocketDevResponseService {
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg));
|
||||
|
||||
|
||||
System.out.println("开始相序校验++++++++++");
|
||||
System.out.println("开始相序校验,向源下参数++++++++++");
|
||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||
issueParam.setPlanId(param.getPlanId());
|
||||
issueParam.setSourceId(param.getSourceId());
|
||||
issueParam.setDevIds(param.getDevIds());
|
||||
//issueParam.setScriptId("2973cb938b591b93d0df2547592b8cd8");
|
||||
issueParam.setScriptId("a303b2224845fcc6f60198b8ca23dca9");
|
||||
|
||||
SocketMsg xuMsg = new SocketMsg();
|
||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
List<SourceIssue> sourceIssues;
|
||||
if (SourceOperateCodeEnum.FORMAL_TEST.getValue().equals(param.getOperateType())) {
|
||||
//正式检测
|
||||
issueParam.setIsPhaseSequence(true);
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.Test_VOL.getValue());
|
||||
} else if (SourceOperateCodeEnum.PRE_TEST.getValue().equals(param.getOperateType())) {
|
||||
//预检测
|
||||
issueParam.setIsPhaseSequence(false);
|
||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
||||
SocketManager.addSourceList(sourceIssues);
|
||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
||||
SocketManager.initMap(sourceIssueMap);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.get(0).getType());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
|
||||
} else if (SourceOperateCodeEnum.PRE_TEST.getValue().equals(param.getOperateType())) {
|
||||
//预检测的相序检测
|
||||
issueParam.setIsPhaseSequence(true);
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||
}
|
||||
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||
if (CollUtil.isNotEmpty(sourceIssues)) {
|
||||
if(SourceOperateCodeEnum.FORMAL_TEST.getValue().equals(param.getOperateType())){
|
||||
SocketManager.addSourceTarget(SourceOperateCodeEnum.Test_VOL.getValue(), sourceIssues.get(0));
|
||||
}
|
||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
successComm.clear();
|
||||
}
|
||||
successComm.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,24 +428,42 @@ public class SocketDevResponseService {
|
||||
String data = socketDataMsg.getData();
|
||||
DevData devData = JSON.parseObject(data, DevData.class);
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
|
||||
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
|
||||
test(devData, dictDataEnumByCode, sourceIssue, socketDataMsg, param);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void test(DevData devData, SourceResponseCodeEnum dictDataEnumByCode, SourceIssue sourceIssue, SocketDataMsg socketDataMsg, PreDetectionParam param) {
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//List<DevData.SqlDataDTO> sqlDataDTOList = devData.getSqlData();
|
||||
devDataList.add(devData);
|
||||
successComm.add(socketDataMsg.getRequestId());
|
||||
System.out.println("devData............."+devDataList.size());
|
||||
System.out.println("获取devData数量............." + devDataList.size());
|
||||
|
||||
if (successComm.size() == monitorIdListComm.size()) {
|
||||
SourceIssue sourceIssue = SocketManager.getSourceTarget(socketDataMsg.getRequestId());
|
||||
System.out.println("获取sourceIssue"+sourceIssue);
|
||||
System.out.println(sourceIssue.getType() +"_"+ sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
|
||||
System.out.println(JSON.toJSONString(sourceIssue));
|
||||
|
||||
//开启线程进行入库原始数据操作
|
||||
Map<String, Integer> flag = detectionServiceImpl.text(devDataList, param.getErrorSysId(), devIdMapComm, sourceIssue, DictDataEnum.AT_WILL_VALUE);
|
||||
System.out.println(flag);
|
||||
|
||||
long tem = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
||||
SocketManager.addTargetMap(sourceIssue.getSubType(), tem);
|
||||
|
||||
System.out.println("该大项还有"+tem+"个小项没有进行检测!!!!!!!!");
|
||||
|
||||
if (tem == 0) {
|
||||
System.out.println(sourceIssue.getType() + sourceIssue.getIndex() + "当前测试大项已经全部结束》》》》》》》》");
|
||||
//当val为0则认为大项中的小项已经全部跑完,开始组装信息推送给前端
|
||||
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
|
||||
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1] + "_End");
|
||||
|
||||
//组装实体推送给前台
|
||||
List<DevLineTestResult> devListRes = new ArrayList<>();
|
||||
devList.forEach(dev -> {
|
||||
@@ -455,8 +483,28 @@ public class SocketDevResponseService {
|
||||
webSocketVO.setData(devListRes);
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
}
|
||||
|
||||
|
||||
//开始进行下一个大项检测
|
||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
|
||||
|
||||
//正式检测
|
||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
}
|
||||
|
||||
//当小项结束后需要删除集合中的小项
|
||||
SocketManager.delSource(sourceIssue.getIndex());
|
||||
System.out.println("当前小项结束进行删除============"+sourceIssue.getType()+"_"+sourceIssue.getIndex());
|
||||
successComm.clear();
|
||||
devDataList.clear();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -484,7 +532,6 @@ public class SocketDevResponseService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -685,4 +732,20 @@ public class SocketDevResponseService {
|
||||
}
|
||||
|
||||
|
||||
private LocalDateTime timeFormat(String dateTimeStr, DateTimeFormatter formatter) {
|
||||
//DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; // ISO 8601格式
|
||||
try {
|
||||
// 假设输入是UTC时间,将其解析为ZonedDateTime
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr, formatter.withZone(ZoneId.of("UTC")));
|
||||
// 将ZonedDateTime转换为LocalDateTime(去除时区信息)
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
System.out.println("LocalDateTime: " + localDateTime);
|
||||
|
||||
return localDateTime;
|
||||
} catch (DateTimeParseException e) {
|
||||
System.err.println("日期时间字符串格式错误: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler;
|
||||
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -65,7 +66,7 @@ public class SocketSourceResponseService {
|
||||
break;
|
||||
//正式检测
|
||||
case FORMAL_REAL:
|
||||
openSource(param, socketDataMsg);
|
||||
senParamToDev(param, socketDataMsg);
|
||||
break;
|
||||
case QUITE_SOURCE:
|
||||
quitDeal(socketDataMsg,param);
|
||||
@@ -169,35 +170,39 @@ public class SocketSourceResponseService {
|
||||
|
||||
|
||||
/**
|
||||
* 正式检测源输出
|
||||
* 组装和装置要数据
|
||||
*
|
||||
* @param param
|
||||
* @param socketDataMsg
|
||||
*/
|
||||
private void openSource(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
private void senParamToDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//向前端推送信息
|
||||
// webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
|
||||
String s = param.getUserPageId() + DEV;
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.Test_VOL.getValue());
|
||||
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
|
||||
String comm = sourceIssue.getDevValueTypeList().get(0);
|
||||
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&"+sourceIssue.getType());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
|
||||
List<String> moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream())
|
||||
.map(PreDetection.MonitorListDTO::getLineId)
|
||||
.collect(Collectors.toList());
|
||||
List<String> moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream()).map(PreDetection.MonitorListDTO::getLineId).collect(Collectors.toList());
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
|
||||
System.out.println("向装置下发的参数"+comm);
|
||||
phaseSequenceParam.setMoniterIdList(moniterIdList);
|
||||
phaseSequenceParam.setDataType(Arrays.asList("real$VRMS"));
|
||||
phaseSequenceParam.setReadCount(20);
|
||||
phaseSequenceParam.setDataType(Arrays.asList(comm));
|
||||
phaseSequenceParam.setReadCount(5);
|
||||
phaseSequenceParam.setIgnoreCount(10);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
|
||||
|
||||
//告诉前端当前项开始了
|
||||
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
|
||||
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1]+"_Start");
|
||||
List<DevLineTestResult> devListRes = new ArrayList<>();
|
||||
@@ -239,6 +244,8 @@ public class SocketSourceResponseService {
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case MESSAGE_PARSING_ERROR:
|
||||
break;
|
||||
|
||||
default:
|
||||
WebSocketVO webSocketVO = new WebSocketVO();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DetectionServiceImpl {
|
||||
param.setScriptId(sourceIssue.getScriptId());
|
||||
param.setErrorSysId(errorSysId);
|
||||
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysIdAndTypes(param);
|
||||
switch ("V") {
|
||||
switch (sourceIssue.getType()) {
|
||||
/**
|
||||
* 频率
|
||||
*/
|
||||
@@ -82,7 +82,7 @@ public class DetectionServiceImpl {
|
||||
* 电压
|
||||
*/
|
||||
case "V":
|
||||
System.out.println(isQualified(dev, devIdMapComm, pqErrSysDtls, F, sourceIssue, dataRule, "FREQ"));
|
||||
//System.out.println(isQualified(dev, devIdMapComm, pqErrSysDtls, F, sourceIssue, dataRule, "FREQ"));
|
||||
return isQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "VRMS").getResultFlag();
|
||||
/**
|
||||
* 电流
|
||||
|
||||
@@ -76,12 +76,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
socketDataMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
socketDataMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
|
||||
try {
|
||||
channel.writeAndFlush(JSON.toJSONString(socketDataMsg)).sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SocketManager.sendMsg(param.getUserPageId()+source,JSON.toJSONString(socketDataMsg));
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
|
||||
@@ -5,8 +5,10 @@ import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* @Description: webSocket存储的通道
|
||||
@@ -64,23 +66,53 @@ public class SocketManager {
|
||||
|
||||
|
||||
/**
|
||||
* 用于存储源操作的脚本信息
|
||||
* key:
|
||||
* key:大类型code value:对应小项数量(成功一个后减一)
|
||||
*/
|
||||
private static final Map<String, SourceIssue> targetMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, Long> targetMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static void addSourceTarget(String sourceTag, SourceIssue sourceIssue) {
|
||||
targetMap.put(sourceTag, sourceIssue);
|
||||
/**
|
||||
* 存储所有检测小项
|
||||
*/
|
||||
private static List<SourceIssue> sourceIssueList = new CopyOnWriteArrayList<>();
|
||||
|
||||
|
||||
|
||||
public static void addSourceList(List<SourceIssue> sList) {
|
||||
sourceIssueList = sList;
|
||||
System.out.println(sList);
|
||||
}
|
||||
|
||||
public static List<SourceIssue> getSourceList() {
|
||||
return sourceIssueList;
|
||||
}
|
||||
|
||||
|
||||
public static void delSource(Integer index) {
|
||||
sourceIssueList.removeIf(s -> index.equals(s.getIndex()));
|
||||
}
|
||||
|
||||
public static void delSourceTarget(String sourceTag) {
|
||||
targetMap.remove(sourceTag);
|
||||
}
|
||||
|
||||
public static SourceIssue getSourceTarget(String sourceTag) {
|
||||
return targetMap.get(sourceTag);
|
||||
|
||||
public static void initMap(Map<String, Long> map) {
|
||||
targetMap = map;
|
||||
}
|
||||
|
||||
public static void addTargetMap(String scriptType,Long count) {
|
||||
targetMap.put(scriptType,count);
|
||||
}
|
||||
|
||||
public static Long getSourceTarget(String scriptType) {
|
||||
return targetMap.get(scriptType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SourceIssue {
|
||||
/**
|
||||
* 总检测下的检测脚本序号
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@JSONField(serialize = true)
|
||||
private Integer index;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user