微调
This commit is contained in:
@@ -74,7 +74,7 @@ public class SocketFreqConverterDevService {
|
||||
|
||||
private void init(String userId, String converterId, String monitorId) {
|
||||
FormalTestManager.freqConverterDevStep = null;
|
||||
FormalTestManager.stopFlag = false;
|
||||
// FormalTestManager.stopFlag = false;
|
||||
FormalTestManager.isRemoveSocket = false;
|
||||
FormalTestManager.pendingDipTaskMap.clear();
|
||||
pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||
@@ -127,8 +127,17 @@ public class SocketFreqConverterDevService {
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
case SUCCESS:
|
||||
this.sendGetDipDataMsg(devTag);
|
||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
||||
// 暂态协议触发后等待5秒,将装置历史缓存的暂态数据给抛掉
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
this.sendGetDipDataMsg(devTag);
|
||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("异步调用sendGetDipDataMsg被中断", e);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||
@@ -146,9 +155,10 @@ public class SocketFreqConverterDevService {
|
||||
case NORMAL_RESPONSE:
|
||||
DevData devData = JSON.parseObject(socketDataMsg.getData(), DevData.class);
|
||||
// 如果变频器不是处于 “故障中” 状态,就保存数据,反之,这段时期内的数据不保存
|
||||
if (!FormalTestManager.stopFlag) {
|
||||
saveDipData(devData);
|
||||
}
|
||||
// if (!FormalTestManager.stopFlag) {
|
||||
// saveDipData(devData);
|
||||
// }
|
||||
saveDipData(devData);
|
||||
break;
|
||||
case DEV_ERROR:
|
||||
case DEV_TARGET:
|
||||
@@ -214,7 +224,7 @@ public class SocketFreqConverterDevService {
|
||||
|
||||
private void sendGetDipDataMsg(String devTag) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&VOLTAGE");
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&VOLTAGE");
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
@@ -222,7 +232,7 @@ public class SocketFreqConverterDevService {
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
|
||||
// 设置监测点ID列表
|
||||
phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp()+StrUtil.C_UNDERLINE+split[1]));
|
||||
phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp() + StrUtil.C_UNDERLINE + split[1]));
|
||||
|
||||
// 设置数据类型列表
|
||||
phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR"));
|
||||
@@ -280,20 +290,24 @@ public class SocketFreqConverterDevService {
|
||||
|
||||
private void initDipTestRes(PqDipData pqDipData) {
|
||||
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||
List<FreqConverterStatus> statusList = freqConverterService.getDipDurationStatusData(suffix, pqDipData.getStartTime(), LocalDateTime.now());
|
||||
List<PqFreqConverterTestRes> testResList = new ArrayList<>();
|
||||
for (FreqConverterStatus status : statusList) {
|
||||
FreqConverterStatus lastStatusData = freqConverterService.getLastStatusData(suffix, pqDipData.getStartTime());
|
||||
List<FreqConverterStatus> statusList = freqConverterService.getDipDurationStatusData(suffix, lastStatusData.getTimestamp(), pqDipData.getStartTime().plusNanos(pqDipData.getDurationMs() * 1000_000L));
|
||||
boolean originalTolerant = lastStatusData.getStatusWord1() != freqConverterConfig.getNoTolerant();
|
||||
|
||||
if (CollUtil.isNotEmpty(statusList)) {
|
||||
FreqConverterStatus status = statusList.get(statusList.size() - 1);
|
||||
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||
testRes.setDipId(pqDipData.getId());
|
||||
testRes.setStatusId(status.getId());
|
||||
testRes.setTolerant(status.getStatusWord1() != freqConverterConfig.getNoTolerant());
|
||||
testResList.add(testRes);
|
||||
}
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, testResList);
|
||||
testRes.setTolerant(originalTolerant ? status.getStatusWord1() != freqConverterConfig.getNoTolerant() : false);
|
||||
testRes.setStartTime(lastStatusData.getTimestamp());
|
||||
|
||||
int collectCount = (int) Math.ceil((freqConverterConfig.getDt()) / freqConverterConfig.getSchedulePeriod());
|
||||
if (collectCount > 0) {
|
||||
FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask(pqDipData.getId(), collectCount));
|
||||
int collectCount = (int) Math.ceil((freqConverterConfig.getDt()) / freqConverterConfig.getSchedulePeriod());
|
||||
if (collectCount > 0) {
|
||||
FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask(pqDipData.getId(), pqDipData.getStartTime(), originalTolerant, collectCount));
|
||||
} else {
|
||||
testRes.setEndTime(status.getTimestamp());
|
||||
}
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, Collections.singletonList(testRes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SocketFreqConverterService {
|
||||
public void onReconnectSuccess(String converterChannelTag) {
|
||||
log.info("变频器重连成功,恢复数据采集,converterChannelTag={}", converterChannelTag);
|
||||
|
||||
FormalTestManager.stopFlag = false;
|
||||
// FormalTestManager.stopFlag = false;
|
||||
|
||||
if (FormalTestManager.scheduler == null) {
|
||||
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||
@@ -165,7 +165,7 @@ public class SocketFreqConverterService {
|
||||
public void cleanup(String converterChannelTag) {
|
||||
clearScheduleTask();
|
||||
FormalTestManager.freqConverterStep = null;
|
||||
FormalTestManager.stopFlag = false;
|
||||
// FormalTestManager.stopFlag = false;
|
||||
FormalTestManager.isRemoveSocket = true;
|
||||
SocketManager.removeUser(converterChannelTag);
|
||||
}
|
||||
@@ -193,11 +193,11 @@ public class SocketFreqConverterService {
|
||||
|
||||
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
|
||||
// 变频器故障中,移除这段时期内的设备数据
|
||||
if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) {
|
||||
FormalTestManager.stopFlag = true;
|
||||
} else {
|
||||
FormalTestManager.stopFlag = false;
|
||||
}
|
||||
// if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) {
|
||||
// FormalTestManager.stopFlag = true;
|
||||
// } else {
|
||||
// FormalTestManager.stopFlag = false;
|
||||
// }
|
||||
freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus);
|
||||
this.consumePendingDipTasks(freqConverterStatus);
|
||||
}
|
||||
@@ -253,27 +253,26 @@ public class SocketFreqConverterService {
|
||||
return;
|
||||
}
|
||||
|
||||
List<PqFreqConverterTestRes> resList = new ArrayList<>();
|
||||
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||
List<String> finishedDipIdList = new ArrayList<>();
|
||||
List<PqFreqConverterTestRes> testResList = new ArrayList<>();
|
||||
for (FormalTestManager.PendingDipTask task : FormalTestManager.pendingDipTaskMap.values()) {
|
||||
if (task.getRemainingCount() <= 0) {
|
||||
finishedDipIdList.add(task.getDipId());
|
||||
continue;
|
||||
}
|
||||
|
||||
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||
testRes.setDipId(task.getDipId());
|
||||
testRes.setStatusId(freqConverterStatus.getId());
|
||||
testRes.setTolerant(freqConverterStatus.getStatusWord1() != freqConverterConfig.getNoTolerant());
|
||||
resList.add(testRes);
|
||||
PqFreqConverterTestRes testRes = pqFreqConverterTestResService.getByDipId(suffix, task.getDipId());
|
||||
testRes.setEndTime(freqConverterStatus.getTimestamp());
|
||||
testRes.setTolerant(testRes.getTolerant() && (freqConverterStatus.getStatusWord1() != freqConverterConfig.getNoTolerant()));
|
||||
testResList.add(testRes);
|
||||
|
||||
task.decrementRemainingCount();
|
||||
if (task.getRemainingCount() <= 0) {
|
||||
finishedDipIdList.add(task.getDipId());
|
||||
}
|
||||
}
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, resList);
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, testResList);
|
||||
|
||||
for (String dipId : finishedDipIdList) {
|
||||
FormalTestManager.pendingDipTaskMap.remove(dipId);
|
||||
|
||||
@@ -12,7 +12,9 @@ import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -223,23 +225,20 @@ public class FormalTestManager {
|
||||
*/
|
||||
public static boolean isXu;
|
||||
|
||||
@Data
|
||||
public static class PendingDipTask {
|
||||
private final String dipId;
|
||||
private LocalDateTime startTime;
|
||||
private Boolean originalTolerant;
|
||||
private int remainingCount;
|
||||
|
||||
public PendingDipTask(String dipId, int remainingCount) {
|
||||
public PendingDipTask(String dipId, LocalDateTime startTime, Boolean originalTolerant, int remainingCount) {
|
||||
this.dipId = dipId;
|
||||
this.startTime = startTime;
|
||||
this.originalTolerant = originalTolerant;
|
||||
this.remainingCount = remainingCount;
|
||||
}
|
||||
|
||||
public String getDipId() {
|
||||
return dipId;
|
||||
}
|
||||
|
||||
public int getRemainingCount() {
|
||||
return remainingCount;
|
||||
}
|
||||
|
||||
public void decrementRemainingCount() {
|
||||
this.remainingCount--;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
||||
log.info("变频器重连成功,converterChannelTag={}, 重连次数={}", converterChannelTag, reconnectAttempts);
|
||||
reconnectAttempts = 0;
|
||||
isReconnecting = false;
|
||||
FormalTestManager.stopFlag = false;
|
||||
socketFreqConverterService.onReconnectSuccess(converterChannelTag);
|
||||
}
|
||||
|
||||
@@ -99,7 +98,6 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
||||
attemptReconnect(ctx);
|
||||
} else if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
log.error("变频器重连失败,已达到最大重连次数{}次,converterChannelTag={}", MAX_RECONNECT_ATTEMPTS, converterChannelTag);
|
||||
FormalTestManager.stopFlag = true;
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
@@ -108,8 +106,6 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("变频器连接发生异常,converterChannelTag={}, error={}", converterChannelTag, cause.getMessage(), cause);
|
||||
FormalTestManager.stopFlag = true;
|
||||
log.warn("变频器连接异常,设置stopFlag=true,设备数据将不再入库");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHand
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
log.info("收到设备消息,devChannelTag={}, msg={},FormalTestManager.stopFlag={}", devChannelTag, msg, FormalTestManager.stopFlag);
|
||||
log.info("收到设备消息,devChannelTag={}, msg={}", devChannelTag, msg);
|
||||
|
||||
socketFreqConverterDevService.handleRead(devChannelTag, msg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.gather.dip.pojo.po.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-16
|
||||
*/
|
||||
@Data
|
||||
public class DipPoint {
|
||||
|
||||
/**
|
||||
* 残余电压,单位:%Ur
|
||||
*/
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
* 持续时间,单位:ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
|
||||
/**
|
||||
* 0为不耐受,1为耐受
|
||||
*/
|
||||
private Boolean tolerant;
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.njcn.gather.freqConverter.pojo.po;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-14
|
||||
@@ -20,13 +22,18 @@ public class PqFreqConverterTestRes {
|
||||
*/
|
||||
private String dipId;
|
||||
|
||||
/**
|
||||
* 变频器状态数据id
|
||||
*/
|
||||
private String statusId;
|
||||
|
||||
/**
|
||||
* 0为不耐受,1为耐受
|
||||
*/
|
||||
private Boolean tolerant;
|
||||
|
||||
/**
|
||||
* 该暂降时期对应变频器的起始时间戳
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 该暂降时期对应变频器的结束时间戳
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
|
||||
@@ -49,4 +49,6 @@ public interface IFreqConverterService extends IService<FreqConverterStatus> {
|
||||
List<TolerantPointVO> getTolerantPoints(String converterId);
|
||||
|
||||
List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,12 @@ public interface IPqFreqConverterTestResService extends IService<PqFreqConverter
|
||||
* @return 结果列表
|
||||
*/
|
||||
List<PqFreqConverterTestRes> listTestRes(Integer suffix);
|
||||
|
||||
/**
|
||||
* 根据DIPID查询结果
|
||||
* @param suffix
|
||||
* @param dipId
|
||||
* @return
|
||||
*/
|
||||
PqFreqConverterTestRes getByDipId(Integer suffix, String dipId);
|
||||
}
|
||||
|
||||
@@ -102,9 +102,20 @@ public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMap
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
|
||||
List<FreqConverterStatus> result = this.lambdaQuery()
|
||||
.between(FreqConverterStatus::getTimestamp, startTime, endTime)
|
||||
.orderByDesc(FreqConverterStatus::getTimestamp)
|
||||
.orderByAsc(FreqConverterStatus::getTimestamp)
|
||||
.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime) {
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
|
||||
FreqConverterStatus one = this.lambdaQuery().le(FreqConverterStatus::getTimestamp, startTime)
|
||||
.orderByDesc(FreqConverterStatus::getTimestamp)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
DynamicTableNameHandler.remove();
|
||||
return one;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverte
|
||||
tableSql = "CREATE TABLE `pq_freq_converter_test_res_" + maxSuffix + "` (" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `dip_id` char(32) NOT NULL COMMENT '装置暂降数据id'," +
|
||||
" `status_id` char(32) NOT NULL COMMENT '变频器状态数据id'," +
|
||||
" `start_time` datetime(3) DEFAULT NULL COMMENT '该暂降时期对应变频器的起始时间戳'," +
|
||||
" `end_time` datetime(3) DEFAULT NULL COMMENT '该暂降时期对应变频器的结束时间戳'," +
|
||||
" `tolerant` tinyInt(1) NOT NULL COMMENT '0为不耐受,1为耐受'," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器耐受实验结果';";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper;
|
||||
@@ -8,6 +8,7 @@ import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,9 +27,25 @@ public class PqFreqConverterTestResServiceImpl extends ServiceImpl<PqFreqConvert
|
||||
@Override
|
||||
public boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix);
|
||||
boolean result = this.saveBatch(testResList);
|
||||
|
||||
List<PqFreqConverterTestRes> existedTestResList = new ArrayList<>();
|
||||
List<PqFreqConverterTestRes> newTestResList = new ArrayList<>();
|
||||
for (PqFreqConverterTestRes testRes : testResList) {
|
||||
if (ObjectUtil.isNotNull(testRes.getId())) {
|
||||
existedTestResList.add(testRes);
|
||||
} else {
|
||||
newTestResList.add(testRes);
|
||||
}
|
||||
}
|
||||
if (existedTestResList.size() > 0) {
|
||||
this.updateBatchById(existedTestResList);
|
||||
}
|
||||
if (newTestResList.size() > 0) {
|
||||
this.saveBatch(newTestResList);
|
||||
}
|
||||
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,4 +55,12 @@ public class PqFreqConverterTestResServiceImpl extends ServiceImpl<PqFreqConvert
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqFreqConverterTestRes getByDipId(Integer suffix, String dipId) {
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix);
|
||||
PqFreqConverterTestRes one = this.lambdaQuery().eq(PqFreqConverterTestRes::getDipId, dipId).one();
|
||||
DynamicTableNameHandler.remove();
|
||||
return one;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,6 @@ activate:
|
||||
public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFMmIVanMxsW5S/qP8Wcxf/J3/i4631BP3UtWkRzO7jAw9HIAgK4Y7X53hXj6zMbfme1vMjQc0mq7m/KrH4WlTYpFexLO6Gnk8oH40F04tp+ABZIq93zNOydPEaVoZeTPH/LlkwrrxVGAMNNIKuebcqapp25JiWtlSFMv4kH/nDAj+2m8+P4zYVM1Ed6gO01eKDEYE3SBA1Ket2BfHTgviR/F8WKwlXh11enywsJnrHTM5dJQdlUxCjHy214TpheYOz/cv9elQnDfFAbmZW8mH5/hgMSTkm3h4uR7ITin6Erg+yc/t1kGaTWrzloyBRMSiFN/Pwr5yQjj+1wQqqUkwIDAQAB"
|
||||
|
||||
freq-converter:
|
||||
schedule-period: 1000 #定时器运行间隔
|
||||
schedule-period: 200 #定时器运行间隔
|
||||
no-tolerant: 4 #不耐受状态
|
||||
dt: 200 #延迟时间ms
|
||||
Reference in New Issue
Block a user