This commit is contained in:
caozehui
2026-04-15 18:52:14 +08:00
parent c5e77ee9b1
commit d8bcca1ede
18 changed files with 271 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
@@ -20,10 +21,15 @@ import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterDevClientHandler; import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterDevClientHandler;
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig; import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.dip.pojo.po.PqDipData; import com.njcn.gather.dip.pojo.po.PqDipData;
import com.njcn.gather.dip.service.IPqDipDataService; import com.njcn.gather.dip.service.IPqDipDataService;
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
import com.njcn.gather.freqConverter.service.IFreqConverterService;
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService; import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -42,7 +48,9 @@ public class SocketFreqConverterDevService {
private final SocketConnectionConfig socketConnectionConfig; private final SocketConnectionConfig socketConnectionConfig;
private final IPqDevService pqDevService; private final IPqDevService pqDevService;
private final IPqDipDataService pqDipDataService; private final IPqDipDataService pqDipDataService;
private final IFreqConverterService freqConverterService;
private final IPqFreqConverterTestResService pqFreqConverterTestResService; private final IPqFreqConverterTestResService pqFreqConverterTestResService;
private final FreqConverterConfig freqConverterConfig;
private String monitorId; private String monitorId;
private String userId; private String userId;
@@ -68,6 +76,7 @@ public class SocketFreqConverterDevService {
FormalTestManager.freqConverterDevStep = null; FormalTestManager.freqConverterDevStep = null;
FormalTestManager.stopFlag = false; FormalTestManager.stopFlag = false;
FormalTestManager.isRemoveSocket = false; FormalTestManager.isRemoveSocket = false;
FormalTestManager.pendingDipTaskMap.clear();
pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix); pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix);
pqFreqConverterTestResService.clearAllData(FormalTestManager.freqConverterTableSuffix); pqFreqConverterTestResService.clearAllData(FormalTestManager.freqConverterTableSuffix);
this.userId = userId; this.userId = userId;
@@ -122,7 +131,7 @@ public class SocketFreqConverterDevService {
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL; FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
break; break;
default: default:
log.info("设备响应异常devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); log.warn("设备响应异常devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
break; break;
} }
} }
@@ -147,7 +156,7 @@ public class SocketFreqConverterDevService {
case DATA_RESOLVE: case DATA_RESOLVE:
case NO_INIT_DEV: case NO_INIT_DEV:
default: default:
log.info("设备响应异常devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); log.warn("设备响应异常devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
break; break;
} }
} }
@@ -156,6 +165,8 @@ public class SocketFreqConverterDevService {
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
switch (responseCodeEnum) { switch (responseCodeEnum) {
case UNPROCESSED_BUSINESS:
break;
case SUCCESS: case SUCCESS:
cleanup(devTag); cleanup(devTag);
break; break;
@@ -203,12 +214,15 @@ public class SocketFreqConverterDevService {
private void sendGetDipDataMsg(String devTag) { private void sendGetDipDataMsg(String devTag) {
SocketMsg<String> socketMsg = new SocketMsg<>(); SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&VOLTAGE");
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam(); DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
String[] split = this.monitorId.split(String.valueOf(StrUtil.C_UNDERLINE));
PqDev dev = pqDevService.getById(split[0]);
// 设置监测点ID列表 // 设置监测点ID列表
phaseSequenceParam.setMoniterIdList(ListUtil.of(this.monitorId)); phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp()+StrUtil.C_UNDERLINE+split[1]));
// 设置数据类型列表 // 设置数据类型列表
phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR")); phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR"));
@@ -253,12 +267,34 @@ public class SocketFreqConverterDevService {
} }
PqDipData pqDipData = new PqDipData(); PqDipData pqDipData = new PqDipData();
pqDipData.setId(IdUtil.fastSimpleUUID());
pqDipData.setStartTime(LocalDateTime.parse(devData.getTime())); pqDipData.setStartTime(LocalDateTime.parse(devData.getTime()));
pqDipData.setResidualVoltage(residualVoltage); pqDipData.setResidualVoltage(residualVoltage);
pqDipData.setDurationMs(durationMs); pqDipData.setDurationMs(durationMs);
DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix); DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix);
pqDipDataService.save(pqDipData); pqDipDataService.save(pqDipData);
DynamicTableNameHandler.remove(); DynamicTableNameHandler.remove();
this.initDipTestRes(pqDipData);
}
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) {
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);
int collectCount = (int) Math.ceil((freqConverterConfig.getDt()) / freqConverterConfig.getSchedulePeriod());
if (collectCount > 0) {
FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask(pqDipData.getId(), collectCount));
}
} }
private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) { private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) {

View File

@@ -13,17 +13,18 @@ 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;
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterClientHandler; import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterClientHandler;
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig; import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
import com.njcn.gather.freqConverter.service.IFreqConverterService; import com.njcn.gather.freqConverter.service.IFreqConverterService;
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -41,7 +42,9 @@ public class SocketFreqConverterService {
private final SocketConnectionConfig socketConnectionConfig; private final SocketConnectionConfig socketConnectionConfig;
private final IPqFreqConverterConfigService pqFreqConverterConfigService; private final IPqFreqConverterConfigService pqFreqConverterConfigService;
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
private String userId; private String userId;
private final FreqConverterConfig freqConverterConfig;
/** /**
* 连接变频器Socket * 连接变频器Socket
@@ -98,13 +101,16 @@ public class SocketFreqConverterService {
} }
} }
private void init(String userId, String converterId, String monitorId) { public void init(String userId, String converterId, String monitorId) {
this.userId = userId; this.userId = userId;
FormalTestManager.freqConverterStep = null; FormalTestManager.freqConverterStep = null;
FormalTestManager.currentFreqConverterId = converterId;
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
freqConverterService.clearAllData(suffix); freqConverterService.clearAllData(suffix);
FormalTestManager.freqConverterTableSuffix = suffix; FormalTestManager.freqConverterTableSuffix = suffix;
FormalTestManager.isRemoveSocket = false; FormalTestManager.isRemoveSocket = false;
FormalTestManager.pendingDipTaskMap.clear();
pqFreqConverterConfigService.updateTestStatus(converterId, 0);
clearScheduleTask(); clearScheduleTask();
} }
@@ -172,10 +178,10 @@ public class SocketFreqConverterService {
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1); FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> { FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
this.sendGetDeviceStatusMsg(converterChannelTag); this.sendGetDeviceStatusMsg(converterChannelTag);
}, 0l, 200l, TimeUnit.SECONDS); }, 0l, freqConverterConfig.getSchedulePeriod(), TimeUnit.MILLISECONDS);
} }
} else { } else {
log.error("变频器初始化串口失败converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage()); log.warn("变频器初始化串口失败converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage());
} }
} }
@@ -187,16 +193,20 @@ public class SocketFreqConverterService {
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class); FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
// 变频器故障中,移除这段时期内的设备数据 // 变频器故障中,移除这段时期内的设备数据
if (freqConverterStatus.getStatusWord1() == 4) { if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) {
FormalTestManager.stopFlag = true; FormalTestManager.stopFlag = true;
} else { } else {
FormalTestManager.stopFlag = false; FormalTestManager.stopFlag = false;
} }
freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus); freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus);
this.consumePendingDipTasks(freqConverterStatus);
} }
private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
if (respDTO.getCode() == 0 && respDTO.getSuccess()) { if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
if (FormalTestManager.currentFreqConverterId != null) {
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
}
cleanup(converterChannelTag); cleanup(converterChannelTag);
} else { } else {
this.sendClose(converterChannelTag); this.sendClose(converterChannelTag);
@@ -238,6 +248,37 @@ public class SocketFreqConverterService {
} }
} }
private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) {
if (FormalTestManager.pendingDipTaskMap.isEmpty()) {
return;
}
List<PqFreqConverterTestRes> resList = new ArrayList<>();
Integer suffix = FormalTestManager.freqConverterTableSuffix;
List<String> finishedDipIdList = 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);
task.decrementRemainingCount();
if (task.getRemainingCount() <= 0) {
finishedDipIdList.add(task.getDipId());
}
}
pqFreqConverterTestResService.saveTestRes(suffix, resList);
for (String dipId : finishedDipIdList) {
FormalTestManager.pendingDipTaskMap.remove(dipId);
}
}
} }

View File

@@ -397,6 +397,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
public void startFreqConverter(String userId, String converterId, String monitorId) { public void startFreqConverter(String userId, String converterId, String monitorId) {
String freqConverterTag = userId + CnSocketUtil.FREQ_CONVERTER_TAG; String freqConverterTag = userId + CnSocketUtil.FREQ_CONVERTER_TAG;
String devTag = userId + CnSocketUtil.DEV_TAG; String devTag = userId + CnSocketUtil.DEV_TAG;
// socketFreqConverterService.init(userId, converterId, monitorId);
socketFreqConverterService.connectSocket(freqConverterTag); socketFreqConverterService.connectSocket(freqConverterTag);
socketFreqConverterDevService.connectSocket(devTag); socketFreqConverterDevService.connectSocket(devTag);
@@ -404,7 +405,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
long timeout = 3000; // 3秒超时时间 long timeout = 3000; // 3秒超时时间
while (true) { while (true) {
if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) { if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) {
// if (SocketManager.isChannelActive(freqConverterTag)) { // if (SocketManager.isChannelActive(devTag)) {
socketFreqConverterService.connectionFreqConverter(userId, freqConverterTag, converterId, monitorId); socketFreqConverterService.connectionFreqConverter(userId, freqConverterTag, converterId, monitorId);
socketFreqConverterDevService.connectionDev(userId, devTag, converterId, monitorId); socketFreqConverterDevService.connectionDev(userId, devTag, converterId, monitorId);
break; break;

View File

@@ -38,6 +38,13 @@ public class FormalTestManager {
*/ */
public static Integer freqConverterTableSuffix; public static Integer freqConverterTableSuffix;
public static String currentFreqConverterId;
/**
* 待采集后续变频器状态的Dip任务
*/
public static Map<String, PendingDipTask> pendingDipTaskMap = new ConcurrentHashMap<>();
/** /**
* key:设备ip,value:当前设备下面的监测点ID(ip_通道号) * key:设备ip,value:当前设备下面的监测点ID(ip_通道号)
*/ */
@@ -215,4 +222,26 @@ public class FormalTestManager {
* 是否进行相序校验 * 是否进行相序校验
*/ */
public static boolean isXu; public static boolean isXu;
public static class PendingDipTask {
private final String dipId;
private int remainingCount;
public PendingDipTask(String dipId, int remainingCount) {
this.dipId = dipId;
this.remainingCount = remainingCount;
}
public String getDipId() {
return dipId;
}
public int getRemainingCount() {
return remainingCount;
}
public void decrementRemainingCount() {
this.remainingCount--;
}
}
} }

View File

@@ -32,12 +32,8 @@ public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHand
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
if (FormalTestManager.stopFlag) { log.info("收到设备消息devChannelTag={}, msg={},FormalTestManager.stopFlag={}", devChannelTag, msg, FormalTestManager.stopFlag);
log.debug("变频器异常或重连中丢弃设备数据devChannelTag={}, msg={}", devChannelTag, msg);
return;
}
log.info("收到设备消息devChannelTag={}, msg={}", devChannelTag, msg);
socketFreqConverterDevService.handleRead(devChannelTag, msg); socketFreqConverterDevService.handleRead(devChannelTag, msg);
} }

View File

@@ -189,4 +189,14 @@ public class PqDevController extends BaseController {
} }
return pqDevService.importDev(file, patternId, planId, response, cover); return pqDevService.importDev(file, patternId, planId, response, cover);
} }
@OperateInfo
@GetMapping("/listAll")
@ApiOperation("查询所有未删除设备数据")
public HttpResult<List<PqDevVO>> listAll() {
String methodDescribe = getMethodDescribe("listAll");
LogUtil.njcnDebug(log, "{},查询所有设备", methodDescribe);
List<PqDevVO> result = pqDevService.listAll();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
} }

View File

@@ -288,4 +288,6 @@ public interface IPqDevService extends IService<PqDev> {
* @return * @return
*/ */
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList); List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
List<PqDevVO> listAll();
} }

View File

@@ -1625,4 +1625,31 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
} }
return result; return result;
} }
@Override
public List<PqDevVO> listAll() {
return this.lambdaQuery()
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
.orderByDesc(PqDev::getCreateTime)
.list().stream().map(pqDev -> {
PqDevVO pqDevVO = new PqDevVO();
BeanUtil.copyProperties(pqDev, pqDevVO);
// 解密序列号和密钥
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
}
if (StrUtil.isNotBlank(pqDevVO.getDevKey())) {
pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey()));
}
// 填充设备类型信息
DevType devType = devTypeService.getById(pqDevVO.getDevType());
if (ObjectUtil.isNotNull(devType)) {
pqDevVO.setDevType(devType.getName());
pqDevVO.setDevChns(devType.getDevChns());
pqDevVO.setDevVolt(devType.getDevVolt());
pqDevVO.setDevCurr(devType.getDevCurr());
}
return pqDevVO;
}).collect(Collectors.toList());
}
} }

View File

@@ -0,0 +1,18 @@
package com.njcn.gather.freqConverter.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author caozehui
* @data 2026-04-15
*/
@Data
@Component
@ConfigurationProperties(prefix = "freq-converter")
public class FreqConverterConfig {
private Long schedulePeriod;
private Integer noTolerant;
private Integer dt;
}

View File

@@ -1,7 +1,6 @@
package com.njcn.gather.freqConverter.pojo.param; package com.njcn.gather.freqConverter.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex; import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.pojo.constant.DetectionValidMessage; import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.param.BaseParam; import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@@ -40,6 +39,7 @@ public class PqFreqConverterParam {
@ApiModelProperty(value = "串口读写超时,单位毫秒", required = true) @ApiModelProperty(value = "串口读写超时,单位毫秒", required = true)
private Integer timeoutMs; private Integer timeoutMs;
private Integer testStatus;
/** /**
* 分页查询实体 * 分页查询实体

View File

@@ -61,6 +61,11 @@ public class PqFreqConverterConfig extends BaseEntity {
*/ */
private Integer suffix; private Integer suffix;
/**
* 检测状态0未检测1检测完成
*/
private Integer testStatus;
/** /**
* 状态0-删除 1-正常 * 状态0-删除 1-正常
*/ */

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@@ -46,4 +47,6 @@ public interface IFreqConverterService extends IService<FreqConverterStatus> {
* @return 是否耐受 * @return 是否耐受
*/ */
List<TolerantPointVO> getTolerantPoints(String converterId); List<TolerantPointVO> getTolerantPoints(String converterId);
List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime);
} }

View File

@@ -2,7 +2,6 @@ package com.njcn.gather.freqConverter.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam; import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
@@ -23,4 +22,6 @@ public interface IPqFreqConverterConfigService extends IService<PqFreqConverterC
boolean deletePqFreqConverterConfig(List<String> ids); boolean deletePqFreqConverterConfig(List<String> ids);
boolean updateTestStatus(String converterId, Integer testStatus);
} }

View File

@@ -3,6 +3,8 @@ package com.njcn.gather.freqConverter.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
import java.util.List;
/** /**
* @author caozehui * @author caozehui
* @data 2026-04-14 * @data 2026-04-14
@@ -15,4 +17,21 @@ public interface IPqFreqConverterTestResService extends IService<PqFreqConverter
* @return * @return
*/ */
void clearAllData(Integer suffix); void clearAllData(Integer suffix);
/**
* 保存结果记录
*
* @param suffix 表后缀
* @param testResList 结果数据
* @return 是否成功
*/
boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList);
/**
* 查询结果记录
*
* @param suffix 表后缀
* @return 结果列表
*/
List<PqFreqConverterTestRes> listTestRes(Integer suffix);
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.freqConverter.service.impl; package com.njcn.gather.freqConverter.service.impl;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
@@ -7,9 +8,11 @@ import com.njcn.gather.dip.pojo.po.PqDipData;
import com.njcn.gather.dip.service.IPqDipDataService; import com.njcn.gather.dip.service.IPqDipDataService;
import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper; import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper;
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
import com.njcn.gather.freqConverter.service.IFreqConverterService; import com.njcn.gather.freqConverter.service.IFreqConverterService;
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -18,6 +21,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 变频器状态数据Service实现类 * 变频器状态数据Service实现类
@@ -35,10 +39,14 @@ import java.util.List;
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService { public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
private final IPqFreqConverterConfigService pqFreqConverterConfigService; private final IPqFreqConverterConfigService pqFreqConverterConfigService;
private final IPqDipDataService dipDataService; private final IPqDipDataService dipDataService;
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) { public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) {
if (status.getId() == null) {
status.setId(IdUtil.fastSimpleUUID());
}
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
boolean result = this.save(status); boolean result = this.save(status);
DynamicTableNameHandler.remove(); DynamicTableNameHandler.remove();
@@ -68,8 +76,8 @@ public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMap
@Override @Override
public List<TolerantPointVO> getTolerantPoints(String converterId) { public List<TolerantPointVO> getTolerantPoints(String converterId) {
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
List<FreqConverterStatus> freqConverterDataList = this.listStatusData(converterId);
List<PqDipData> dipDataList = dipDataService.listDipData(suffix); List<PqDipData> dipDataList = dipDataService.listDipData(suffix);
List<PqFreqConverterTestRes> testResList = pqFreqConverterTestResService.listTestRes(suffix);
dipDataList.sort(Comparator.comparing(PqDipData::getDurationMs)); dipDataList.sort(Comparator.comparing(PqDipData::getDurationMs));
List<TolerantPointVO> res = new ArrayList<>(); List<TolerantPointVO> res = new ArrayList<>();
@@ -77,18 +85,26 @@ public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMap
TolerantPointVO tolerantPointVO = new TolerantPointVO(); TolerantPointVO tolerantPointVO = new TolerantPointVO();
tolerantPointVO.setDurationMs(dipData.getDurationMs()); tolerantPointVO.setDurationMs(dipData.getDurationMs());
tolerantPointVO.setResidualVoltage(dipData.getResidualVoltage()); tolerantPointVO.setResidualVoltage(dipData.getResidualVoltage());
LocalDateTime dipEndTime = dipData.getStartTime().plusNanos(dipData.getDurationMs() * 1_000_000L); List<PqFreqConverterTestRes> matchedResList = testResList.stream()
FreqConverterStatus nextStatus = freqConverterDataList.stream() .filter(item -> dipData.getId().equals(item.getDipId()))
.filter(item -> item.getTimestamp() != null && !item.getTimestamp().isBefore(dipEndTime)) .collect(Collectors.toList());
.min(Comparator.comparing(FreqConverterStatus::getTimestamp))
.orElse(null); boolean tolerant = matchedResList.stream().allMatch(PqFreqConverterTestRes::getTolerant);
if (nextStatus == null || nextStatus.getStatusWord1() == null || nextStatus.getStatusWord1() != 4) { tolerantPointVO.setTolerant(tolerant);
tolerantPointVO.setTolerant(true);
} else {
tolerantPointVO.setTolerant(false);
}
res.add(tolerantPointVO); res.add(tolerantPointVO);
} }
return res; return res;
} }
@Override
public List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime) {
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
List<FreqConverterStatus> result = this.lambdaQuery()
.between(FreqConverterStatus::getTimestamp, startTime, endTime)
.orderByDesc(FreqConverterStatus::getTimestamp)
.list();
DynamicTableNameHandler.remove();
return result;
}
} }

View File

@@ -83,6 +83,7 @@ public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverte
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class); PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
pqFreqConverterConfig.setSuffix(maxSuffix); pqFreqConverterConfig.setSuffix(maxSuffix);
pqFreqConverterConfig.setTestStatus(0);
pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode()); pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode());
return this.save(pqFreqConverterConfig); return this.save(pqFreqConverterConfig);
} }
@@ -115,4 +116,13 @@ public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverte
.in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids) .in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids)
.set(PqFreqConverterConfig::getState, 0).update(); .set(PqFreqConverterConfig::getState, 0).update();
} }
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateTestStatus(String converterId, Integer testStatus) {
return this.lambdaUpdate()
.eq(PqFreqConverterConfig::getId, converterId)
.set(PqFreqConverterConfig::getTestStatus, testStatus)
.update();
}
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.freqConverter.service.impl; package com.njcn.gather.freqConverter.service.impl;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper; import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper;
@@ -7,6 +8,8 @@ import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService; import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author caozehui * @author caozehui
* @data 2026-04-14 * @data 2026-04-14
@@ -19,4 +22,20 @@ public class PqFreqConverterTestResServiceImpl extends ServiceImpl<PqFreqConvert
this.remove(null); this.remove(null);
DynamicTableNameHandler.remove(); DynamicTableNameHandler.remove();
} }
@Override
public boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix);
boolean result = this.saveBatch(testResList);
DynamicTableNameHandler.remove();
return result;
}
@Override
public List<PqFreqConverterTestRes> listTestRes(Integer suffix) {
DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix);
List<PqFreqConverterTestRes> result = this.list();
DynamicTableNameHandler.remove();
return result;
}
} }

View File

@@ -6,9 +6,9 @@ spring:
datasource: datasource:
druid: druid:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://192.168.1.24:13306/pqs91002?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # url: jdbc:mysql://192.168.1.24:13306/pqs91002?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
# username: root # username: root
# password: njcnpqs # password: njcnpqs
url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
username: root username: root
password: njcnpqs password: njcnpqs
@@ -126,3 +126,8 @@ power-quality:
activate: 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+Ya3vGktW37ht4WOx2OsJRhG1dbf6RLwFlH7DWwKBgQDFBxvi5I1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SldGA8ajVHx3BYRjj+zl62NTQthy8fw3tqxb3c5e8toOmZWKjZvDhg2TRLhsDDQWEYg3LZG87REqVIjgEPcpjNLidjygGX8n3JF2o0O5I/EMvl0s/+LVQONfduOBvhwDqr8QNisbLsyneiAq7umewMolo="
public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFMmIVanMxsW5S/qP8Wcxf/J3/i4631BP3UtWkRzO7jAw9HIAgK4Y7X53hXj6zMbfme1vMjQc0mq7m/KrH4WlTYpFexLO6Gnk8oH40F04tp+ABZIq93zNOydPEaVoZeTPH/LlkwrrxVGAMNNIKuebcqapp25JiWtlSFMv4kH/nDAj+2m8+P4zYVM1Ed6gO01eKDEYE3SBA1Ket2BfHTgviR/F8WKwlXh11enywsJnrHTM5dJQdlUxCjHy214TpheYOz/cv9elQnDfFAbmZW8mH5/hgMSTkm3h4uR7ITin6Erg+yc/t1kGaTWrzloyBRMSiFN/Pwr5yQjj+1wQqqUkwIDAQAB" public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFMmIVanMxsW5S/qP8Wcxf/J3/i4631BP3UtWkRzO7jAw9HIAgK4Y7X53hXj6zMbfme1vMjQc0mq7m/KrH4WlTYpFexLO6Gnk8oH40F04tp+ABZIq93zNOydPEaVoZeTPH/LlkwrrxVGAMNNIKuebcqapp25JiWtlSFMv4kH/nDAj+2m8+P4zYVM1Ed6gO01eKDEYE3SBA1Ket2BfHTgviR/F8WKwlXh11enywsJnrHTM5dJQdlUxCjHy214TpheYOz/cv9elQnDfFAbmZW8mH5/hgMSTkm3h4uR7ITin6Erg+yc/t1kGaTWrzloyBRMSiFN/Pwr5yQjj+1wQqqUkwIDAQAB"
freq-converter:
schedule-period: 1000 #定时器运行间隔
no-tolerant: 4 #不耐受状态
dt: 200 #延迟时间ms