动态创建表结构、入库
This commit is contained in:
@@ -10,6 +10,7 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -176,4 +177,26 @@ public class PreDetectionController extends BaseController {
|
||||
preDetectionService.startCoefficient();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/startFreqConverter")
|
||||
@ApiOperation("开启变频器测试")
|
||||
public HttpResult<String> startFreqConverter(@RequestParam("loginName") String loginName, @RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId) {
|
||||
String methodDescribe = getMethodDescribe("startFreqConverter");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
preDetectionService.startFreqConverter(loginName, converterId, monitorId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/stopFreqConverter")
|
||||
@ApiOperation("关闭变频器测试")
|
||||
public HttpResult<String> stopFreqConverter(@RequestParam("loginName") String loginName) {
|
||||
String methodDescribe = getMethodDescribe("stopFreqConverter");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
preDetectionService.stopFreqConverter(loginName + CnSocketUtil.FREQ_CONVERTER_TAG, loginName + CnSocketUtil.DEV_TAG);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
@@ -22,6 +23,7 @@ import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -39,6 +41,8 @@ public class SocketFreqConverterDevService {
|
||||
private final SocketConnectionConfig socketConnectionConfig;
|
||||
private final IPqDevService pqDevService;
|
||||
private final IPqDipDataService pqDipDataService;
|
||||
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||
private String monitorId;
|
||||
|
||||
/**
|
||||
* 连接设备Socket
|
||||
@@ -61,6 +65,8 @@ public class SocketFreqConverterDevService {
|
||||
private void init(String converterId, String monitorId) {
|
||||
FormalTestManager.freqConverterDevStep = null;
|
||||
FormalTestManager.stopFlag = false;
|
||||
pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||
this.monitorId = monitorId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,14 +191,14 @@ public class SocketFreqConverterDevService {
|
||||
return JSON.toJSONString(payload);
|
||||
}
|
||||
|
||||
private void sendGetDipDataMsg(String monitorId) {
|
||||
private void sendGetDipDataMsg(String devTag) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
// 设置监测点ID列表
|
||||
phaseSequenceParam.setMoniterIdList(ListUtil.of(monitorId));
|
||||
phaseSequenceParam.setMoniterIdList(ListUtil.of(this.monitorId));
|
||||
|
||||
// 设置数据类型列表
|
||||
phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR"));
|
||||
@@ -202,7 +208,7 @@ public class SocketFreqConverterDevService {
|
||||
phaseSequenceParam.setIgnoreCount(0);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_03.getValue());
|
||||
SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg));
|
||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
private void sendQuitMsg(String devTag, SourceOperateCodeEnum operateCodeEnum) {
|
||||
@@ -240,7 +246,9 @@ public class SocketFreqConverterDevService {
|
||||
pqDipData.setStartTime(LocalDateTime.parse(devData.getTime()));
|
||||
pqDipData.setResidualVoltage(residualVoltage);
|
||||
pqDipData.setDurationMs(durationMs);
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix);
|
||||
pqDipDataService.save(pqDipData);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
|
||||
private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.detection.pojo.dto.FreqConverterRespDTO;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
@@ -99,7 +100,9 @@ public class SocketFreqConverterService {
|
||||
|
||||
private void init(String converterId, String monitorId) {
|
||||
FormalTestManager.freqConverterStep = null;
|
||||
FormalTestManager.pairsIpMap.put(converterId, monitorId);
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
freqConverterService.clearAllData(suffix);
|
||||
FormalTestManager.freqConverterTableSuffix = suffix;
|
||||
clearScheduleTask();
|
||||
}
|
||||
|
||||
@@ -159,7 +162,6 @@ public class SocketFreqConverterService {
|
||||
} else {
|
||||
FormalTestManager.stopFlag = false;
|
||||
}
|
||||
FormalTestManager.pairsIpMap.clear();
|
||||
if (removeSocket) {
|
||||
SocketManager.removeUser(converterChannelTag);
|
||||
} else {
|
||||
@@ -170,7 +172,7 @@ public class SocketFreqConverterService {
|
||||
private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS;
|
||||
freqConverterService.clearAllData();
|
||||
|
||||
if (Objects.isNull(FormalTestManager.scheduler)) {
|
||||
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||
@@ -195,7 +197,7 @@ public class SocketFreqConverterService {
|
||||
} else {
|
||||
FormalTestManager.stopFlag = false;
|
||||
}
|
||||
freqConverterService.saveFreqConverterStatus(freqConverterStatus);
|
||||
freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix,freqConverterStatus);
|
||||
}
|
||||
|
||||
private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||
|
||||
@@ -19,7 +19,8 @@ public enum DetectionResponseEnum {
|
||||
|
||||
|
||||
SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" ),
|
||||
EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" );
|
||||
EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ),
|
||||
SOCKET_CONNECT_TIMEOUT("A020042","socket连接超时!");
|
||||
|
||||
private final String code;
|
||||
private final String message;
|
||||
|
||||
@@ -4,9 +4,6 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
@@ -55,7 +52,6 @@ public interface PreDetectionService {
|
||||
void closeTestSimulate(SimulateDetectionParam param);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param
|
||||
*/
|
||||
void startContrastTest(ContrastDetectionParam param);
|
||||
@@ -68,4 +64,8 @@ public interface PreDetectionService {
|
||||
boolean getCanCoefficient();
|
||||
|
||||
void startCoefficient();
|
||||
|
||||
void startFreqConverter(String name, String converterId, String monitorId);
|
||||
|
||||
void stopFreqConverter(String converterId, String monitorId);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||
import com.njcn.gather.detection.handler.*;
|
||||
import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
@@ -76,6 +74,8 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
private final SocketDevResponseService socketDevResponseService;
|
||||
private final SocketSourceResponseService socketSourceResponseService;
|
||||
private final SocketContrastResponseService socketContrastResponseService;
|
||||
private final SocketFreqConverterService socketFreqConverterService;
|
||||
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
||||
private final SocketManager socketManager;
|
||||
private final ISysTestConfigService sysTestConfigService;
|
||||
@@ -393,6 +393,37 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFreqConverter(String loginName, String converterId, String monitorId) {
|
||||
String freqConverterTag = loginName + CnSocketUtil.FREQ_CONVERTER_TAG;
|
||||
String devTag = loginName + CnSocketUtil.DEV_TAG;
|
||||
socketFreqConverterService.connectSocket(freqConverterTag);
|
||||
//socketFreqConverterDevService.connectSocket(devTag);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
long timeout = 3000; // 3秒超时时间
|
||||
while (true) {
|
||||
// if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) {
|
||||
if (SocketManager.isChannelActive(freqConverterTag)) {
|
||||
socketFreqConverterService.connectionFreqConverter(freqConverterTag, converterId, monitorId);
|
||||
//socketFreqConverterDevService.connectionDev(devTag, converterId, monitorId);
|
||||
break;
|
||||
}
|
||||
|
||||
// 检查是否超时
|
||||
if (System.currentTimeMillis() - startTime > timeout) {
|
||||
throw new BusinessException(DetectionResponseEnum.SOCKET_CONNECT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopFreqConverter(String converterTag, String devTag) {
|
||||
socketFreqConverterService.stopTest(converterTag, devTag);
|
||||
socketFreqConverterDevService.stopTest(converterTag, converterTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对式-与通信模块进行连接
|
||||
*
|
||||
@@ -451,4 +482,4 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
*/
|
||||
public class CnSocketUtil {
|
||||
|
||||
public final static String FREQ_CONVERTER_TAG="_FreqConverter";
|
||||
|
||||
public final static String DEV_TAG = "_Dev";
|
||||
|
||||
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
||||
|
||||
@@ -33,6 +33,10 @@ public class FormalTestManager {
|
||||
|
||||
public static SourceOperateCodeEnum freqConverterStep;
|
||||
public static SourceOperateCodeEnum freqConverterDevStep;
|
||||
/**
|
||||
* 变频器存放数据的表后缀
|
||||
*/
|
||||
public static Integer freqConverterTableSuffix;
|
||||
|
||||
/**
|
||||
* key:设备ip,value:当前设备下面的监测点ID(ip_通道号)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.njcn.gather.dip.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
public interface PqDipDataMapper extends BaseMapper<PqDipData> {
|
||||
public interface PqDipDataMapper extends MPJBaseMapper<PqDipData> {
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package com.njcn.gather.dip.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -15,11 +12,8 @@ import java.time.LocalDateTime;
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_dip_data")
|
||||
public class PqDipData extends BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableName(value = "ad_harmonic_xx")
|
||||
public class PqDipData {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
@@ -37,7 +31,6 @@ public class PqDipData extends BaseEntity implements Serializable {
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
*
|
||||
* 持续时间,单位:ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
|
||||
@@ -3,9 +3,21 @@ package com.njcn.gather.dip.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
public interface IPqDipDataService extends IService<PqDipData> {
|
||||
|
||||
/**
|
||||
* 查询指定变频器所对应的电压暂降数据
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @return
|
||||
*/
|
||||
List<PqDipData> listDipData(Integer suffix);
|
||||
|
||||
void clearAllData(Integer suffix);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,34 @@
|
||||
package com.njcn.gather.dip.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.dip.mapper.PqDipDataMapper;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
@Service
|
||||
public class PqDipDataServiceImpl extends ServiceImpl<PqDipDataMapper, PqDipData> implements IPqDipDataService {
|
||||
@Override
|
||||
public List<PqDipData> listDipData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||
LambdaQueryChainWrapper<PqDipData> wrapper = this.lambdaQuery().orderByAsc(PqDipData::getStartTime);
|
||||
List<PqDipData> result = wrapper.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||
this.remove(null);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
@@ -20,10 +20,9 @@ import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -84,10 +83,10 @@ public class FreqConverterController extends BaseController {
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除变频器")
|
||||
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
|
||||
public HttpResult<Boolean> delete(@RequestBody @Validated List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
|
||||
boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(param);
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
@@ -95,4 +94,13 @@ public class FreqConverterController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/result")
|
||||
@ApiOperation("查询耐受实验结果")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<List<TolerantPointVO>> result(@RequestParam("converterId") String converterId) {
|
||||
String methodDescribe = getMethodDescribe("result");
|
||||
LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId);
|
||||
List<TolerantPointVO> tolerantPoints = freqConverterService.getTolerantPoints(converterId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PqFreqConverterParam {
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends PqDevParam {
|
||||
public static class UpdateParam extends PqFreqConverterParam {
|
||||
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package com.njcn.gather.freqConverter.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -13,11 +10,8 @@ import java.time.LocalDateTime;
|
||||
* @data 2026-04-07
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_freq_converter_status")
|
||||
public class FreqConverterStatus extends BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableName(value = "ad_harmonic_xx")
|
||||
public class FreqConverterStatus {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.njcn.gather.freqConverter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
|
||||
@@ -17,10 +16,11 @@ public interface IFreqConverterService extends IService<FreqConverterStatus> {
|
||||
/**
|
||||
* 保存变频器状态数据
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @param status 变频器状态数据
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
boolean saveFreqConverterStatus(FreqConverterStatus status);
|
||||
boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status);
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,23 +29,21 @@ public interface IFreqConverterService extends IService<FreqConverterStatus> {
|
||||
* @param converterId 变频器ID
|
||||
* @return 状态数据列表
|
||||
*/
|
||||
List<FreqConverterStatus> listStatusHistory(String converterId);
|
||||
List<FreqConverterStatus> listStatusData(String converterId);
|
||||
|
||||
/**
|
||||
* 清空所有数据
|
||||
*
|
||||
* @param converterId 变频器ID
|
||||
* @return
|
||||
*/
|
||||
boolean clearAllData();
|
||||
void clearAllData(Integer converterId);
|
||||
|
||||
/**
|
||||
* 根据设备暂降数据判断变频器是否耐受
|
||||
*
|
||||
* @param freqConverterDataList 变频器数据集合
|
||||
* @param dipDataList 设备暂降数据集合
|
||||
* @param converterId 变频器Id
|
||||
* @return 是否耐受
|
||||
*/
|
||||
List<TolerantPointVO> getTolerantPoints(List<FreqConverterStatus> freqConverterDataList, List<PqDipData> dipDataList);
|
||||
|
||||
|
||||
List<TolerantPointVO> getTolerantPoints(String converterId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
@@ -13,9 +15,12 @@ import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
public interface IPqFreqConverterConfigService extends IService<PqFreqConverterConfig> {
|
||||
Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam);
|
||||
|
||||
Integer getSuffix(String converterId);
|
||||
|
||||
boolean addPqFreqConverterConfig(PqFreqConverterParam param);
|
||||
|
||||
boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param);
|
||||
|
||||
boolean deletePqFreqConverterConfig(PqDevParam.DeleteParam param);
|
||||
boolean deletePqFreqConverterConfig(List<String> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -26,26 +31,45 @@ import java.util.List;
|
||||
* @since 2026
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
|
||||
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||
private final IPqDipDataService dipDataService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveFreqConverterStatus(FreqConverterStatus status) {
|
||||
return this.save(status);
|
||||
public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) {
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
|
||||
boolean result = this.save(status);
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FreqConverterStatus> listStatusHistory(String converterId) {
|
||||
return this.lambdaQuery().list();
|
||||
public List<FreqConverterStatus> listStatusData(String converterId) {
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
|
||||
LambdaQueryChainWrapper<FreqConverterStatus> wrapper = this.lambdaQuery().orderByAsc(FreqConverterStatus::getTimestamp);
|
||||
List<FreqConverterStatus> result = wrapper.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearAllData() {
|
||||
return this.remove(null);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void clearAllData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix);
|
||||
this.remove(null);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TolerantPointVO> getTolerantPoints(List<FreqConverterStatus> freqConverterDataList, List<PqDipData> dipDataList) {
|
||||
public List<TolerantPointVO> getTolerantPoints(String converterId) {
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
List<FreqConverterStatus> freqConverterDataList = this.listStatusData(converterId);
|
||||
List<PqDipData> dipDataList = dipDataService.listDipData(suffix);
|
||||
dipDataList.sort(Comparator.comparing(PqDipData::getDurationMs));
|
||||
|
||||
List<TolerantPointVO> res = new ArrayList<>();
|
||||
|
||||
@@ -1,43 +1,107 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.gather.freqConverter.mapper.PqFreqConverterConfigMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.gather.storage.mapper.TableGenMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverterConfigMapper, PqFreqConverterConfig> implements IPqFreqConverterConfigService {
|
||||
private final TableGenMapper tableGenMapper;
|
||||
|
||||
@Override
|
||||
public Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like("name", queryParam.getName());
|
||||
return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), queryWrapper);
|
||||
QueryWrapper wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName());
|
||||
wrapper.eq("state", 1);
|
||||
return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getSuffix(String converterId) {
|
||||
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().eq(PqFreqConverterConfig::getId, converterId).one();
|
||||
return freqConverterConfig.getSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean addPqFreqConverterConfig(PqFreqConverterParam param) {
|
||||
// 建表
|
||||
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().orderByDesc(PqFreqConverterConfig::getSuffix)
|
||||
.last("limit 1").one();
|
||||
Integer maxSuffix = 1;
|
||||
if (ObjectUtil.isNotNull(freqConverterConfig)) {
|
||||
maxSuffix = freqConverterConfig.getSuffix() + 1;
|
||||
}
|
||||
|
||||
String tableSql = "CREATE TABLE `pq_freq_converter_status_" + maxSuffix + "` (" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `slave_address` int(11) DEFAULT NULL COMMENT '从机地址'," +
|
||||
" `status_word1` int(11) DEFAULT NULL COMMENT '状态字1'," +
|
||||
" `status_word1_hex` varchar(20) DEFAULT NULL COMMENT '状态字1十六进制'," +
|
||||
" `timestamp` datetime(3) NOT NULL COMMENT '状态记录时刻(时间戳)'," +
|
||||
" PRIMARY KEY (`id`) USING BTREE" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器状态表';";
|
||||
tableGenMapper.genTable(tableSql);
|
||||
|
||||
tableSql = "CREATE TABLE `pq_dip_data_" + maxSuffix + "` (" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `start_time` datetime(3) NOT NULL COMMENT '起始时间戳'," +
|
||||
" `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," +
|
||||
" `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电压暂降数据表';";
|
||||
tableGenMapper.genTable(tableSql);
|
||||
|
||||
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||
pqFreqConverterConfig.setSuffix(maxSuffix);
|
||||
pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode());
|
||||
return this.save(pqFreqConverterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param) {
|
||||
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||
return this.updateById(pqFreqConverterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePqFreqConverterConfig(PqDevParam.DeleteParam param) {
|
||||
return this.lambdaUpdate().set(PqFreqConverterConfig::getState, 0).update();
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deletePqFreqConverterConfig(List<String> ids) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("drop table if exists ");
|
||||
|
||||
List<PqFreqConverterConfig> pqFreqConverterConfigs = this.listByIds(ids);
|
||||
for (PqFreqConverterConfig pqFreqConverterConfig : pqFreqConverterConfigs) {
|
||||
Integer suffix = pqFreqConverterConfig.getSuffix();
|
||||
sql.append("pq_freq_converter_status_" + suffix + ",").append("pq_dip_data_" + suffix + ",");
|
||||
}
|
||||
|
||||
sql.deleteCharAt(sql.length() - 1);
|
||||
// 删除表
|
||||
tableGenMapper.genTable(sql.toString());
|
||||
return this.lambdaUpdate()
|
||||
.in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids)
|
||||
.set(PqFreqConverterConfig::getState, 0).update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user