状态清空

This commit is contained in:
caozehui
2026-04-20 09:08:25 +08:00
parent 27f25d2404
commit e03c3e3607
3 changed files with 58 additions and 0 deletions

View File

@@ -349,8 +349,28 @@ public class SocketFreqConverterDevService {
} }
public void cleanup(String devTag) { public void cleanup(String devTag) {
String currentUserId = this.userId;
FormalTestManager.freqConverterDevStep = null; FormalTestManager.freqConverterDevStep = null;
FormalTestManager.isRemoveSocket = true; FormalTestManager.isRemoveSocket = true;
SocketManager.removeUser(devTag); SocketManager.removeUser(devTag);
clearStateIfStopped(currentUserId);
this.userId = null;
this.monitorId = null;
}
/**
* 如果设备已停止,则清除共享的运行时状态
* @param currentUserId 当前用户ID
*/
private void clearStateIfStopped(String currentUserId) {
if (StrUtil.isBlank(currentUserId)) {
FormalTestManager.clearFreqConverterRuntimeState();
return;
}
String freqConverterTag = currentUserId + CnSocketUtil.FREQ_CONVERTER_TAG;
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成变频器无法使用全局变量
if (!SocketManager.isChannelActive(freqConverterTag)) {
FormalTestManager.clearFreqConverterRuntimeState();
}
} }
} }

View File

@@ -9,6 +9,7 @@ import com.njcn.gather.detection.pojo.dto.FreqConverterRespDTO;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg; import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg; import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.FormalTestManager; import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.cilent.NettyClient; import com.njcn.gather.detection.util.socket.cilent.NettyClient;
@@ -168,11 +169,15 @@ public class SocketFreqConverterService {
} }
public void cleanup(String converterChannelTag) { public void cleanup(String converterChannelTag) {
String currentUserId = this.userId;
clearScheduleTask(); clearScheduleTask();
FormalTestManager.freqConverterStep = null; FormalTestManager.freqConverterStep = null;
// FormalTestManager.stopFlag = false; // FormalTestManager.stopFlag = false;
FormalTestManager.isRemoveSocket = true; FormalTestManager.isRemoveSocket = true;
SocketManager.removeUser(converterChannelTag); SocketManager.removeUser(converterChannelTag);
updateCurrentTestStatus();
clearStateIfStopped(currentUserId);
this.userId = null;
} }
private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
@@ -253,6 +258,28 @@ public class SocketFreqConverterService {
} }
} }
private void updateCurrentTestStatus() {
if (StrUtil.isNotBlank(FormalTestManager.currentFreqConverterId)) {
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
}
}
/**
* 如果变频器已停止,则清除共享的运行时状态
* @param currentUserId 当前用户ID
*/
private void clearStateIfStopped(String currentUserId) {
if (StrUtil.isBlank(currentUserId)) {
FormalTestManager.clearFreqConverterRuntimeState();
return;
}
String devTag = currentUserId + CnSocketUtil.DEV_TAG;
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成设备无法使用全局变量
if (!SocketManager.isChannelActive(devTag)) {
FormalTestManager.clearFreqConverterRuntimeState();
}
}
private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) { private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) {
if (FormalTestManager.pendingDipTaskMap.isEmpty()) { if (FormalTestManager.pendingDipTaskMap.isEmpty()) {
return; return;

View File

@@ -226,6 +226,17 @@ public class FormalTestManager {
*/ */
public static boolean isXu; public static boolean isXu;
/**
* 清理变频器耐受实验运行态数据
*/
public static void clearFreqConverterRuntimeState() {
freqConverterStep = null;
freqConverterDevStep = null;
currentFreqConverterId = null;
freqConverterTableSuffix = null;
pendingDipTaskMap.clear();
}
@Data @Data
public static class PendingDipTask { public static class PendingDipTask {
private PqDipData pqDipData; private PqDipData pqDipData;