调整表结构、编写查看检测结果接口、误差计算逻辑调整

This commit is contained in:
caozehui
2025-08-22 16:27:48 +08:00
parent 7b9954f1fe
commit d020890639
22 changed files with 712 additions and 158 deletions

View File

@@ -18,6 +18,7 @@
Id char(32) COLLATE utf8mb4_bin NOT NULL COMMENT '主键Id',
Std_Dev_Monitor_Id CHAR(34) NOT NULL COMMENT '标准设备监测点Id',
Num tinyint(1) unsigned DEFAULT 0 COMMENT '第几次检测',
Flag tinyint(1) unsigned NOT NULL COMMENT '0表示被检设备数据1表示标准设备数据',
A_Value_0 float NULL COMMENT 'A相基波有效值',
B_Value_0 float NULL COMMENT 'B相基波有效值',
C_Value_0 float NULL COMMENT 'B相基波有效值',
@@ -54,9 +55,10 @@
Id char(32) COLLATE utf8mb4_bin NOT NULL COMMENT '主键Id',
Std_Dev_Monitor_Id CHAR(34) NOT NULL COMMENT '标准设备监测点Id',
Num tinyint(1) unsigned DEFAULT 0 COMMENT '第几次检测',
A_Value_0 json NULL COMMENT 'A相基波有效值',
B_Value_0 json NULL COMMENT 'B相基波有效值',
C_Value_0 json NULL COMMENT 'B相基波有效值',
Flag tinyint(1) unsigned DEFAULT NULL COMMENT '0表示被检设备数据1表示标准设备数据',
A_Value_0 json NULL COMMENT 'A相基波有效值',
B_Value_0 json NULL COMMENT 'B相基波有效值',
C_Value_0 json NULL COMMENT 'B相基波有效值',
PRIMARY KEY (Id)
</when>
<otherwise>

View File

@@ -21,4 +21,9 @@ public class ContrastBaseResult extends BaseResult {
* 标准设备监测点id
*/
private String stdDevMonitorId;
/**
* 0表示被检设备数据1表示标准设备数据
*/
private Integer flag;
}

View File

@@ -3,9 +3,33 @@ package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
import java.util.List;
/**
* @author caozehui
* @data 2025-07-28
*/
public interface ContrastHarmonicService extends IService<ContrastHarmonicResult> {
/**
* 获取所有原始数据
*
* @param code
* @param num 第几次检测
* @param flag 0:被检设备1:标准设备
* @param devId 设备ID
* @param adTypeList
* @return
*/
List<ContrastHarmonicResult> listAllRawData(String code, Integer num, Integer flag, String devId, List<String> adTypeList);
/**
* 获取所有谐波结果数据
*
* @param code
* @param num 第几次检测
* @param devId 设备ID
* @return
*/
List<ContrastHarmonicResult> listAllResultData(String code, Integer num, String devId, List<String> adTypeList);
}

View File

@@ -3,10 +3,34 @@ package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
import java.util.List;
/**
* @author caozehui
* @data 2025-07-28
*/
public interface ContrastNonHarmonicService extends IService<ContrastNonHarmonicResult> {
/**
* 获取所有原始数据
*
* @param code
* @param num 第几次检测
* @param flag 0:被检设备1:标准设备
* @param devId 设备ID
* @param adTypeList
* @return
*/
List<ContrastNonHarmonicResult> listAllRawData(String code, Integer num, Integer flag, String devId, List<String> adTypeList);
/**
* 获取所有非谐波结果数据
*
* @param code
* @param num 第几次检测
* @param devId 设备ID
* @param adTypeList
* @return
*/
List<ContrastNonHarmonicResult> listAllResultData(String code, Integer num, String devId, List<String> adTypeList);
}

View File

@@ -3,6 +3,7 @@ package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;

View File

@@ -1,12 +1,17 @@
package com.njcn.gather.storage.service.impl;
import cn.hutool.core.collection.CollUtil;
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.storage.mapper.ContrastHarmonicMappper;
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
import com.njcn.gather.storage.service.ContrastHarmonicService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author caozehui
* @data 2025-07-28
@@ -14,4 +19,29 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ContrastHarmonicServiceImpl extends ServiceImpl<ContrastHarmonicMappper, ContrastHarmonicResult> implements ContrastHarmonicService {
@Override
public List<ContrastHarmonicResult> listAllRawData(String code, Integer num, Integer flag, String devId, List<String> adTypeList) {
String prefix = "ad_harmonic_" + code;
DynamicTableNameHandler.setTableName(prefix);
List<ContrastHarmonicResult> result = this.lambdaQuery().likeRight(ContrastHarmonicResult::getDevMonitorId, devId)
.eq(ObjectUtil.isNotNull(num), ContrastHarmonicResult::getNum, num)
.eq(ContrastHarmonicResult::getFlag, flag)
.in(CollUtil.isNotEmpty(adTypeList), ContrastHarmonicResult::getAdType, adTypeList)
.orderByAsc(ContrastHarmonicResult::getTimeId).list();
DynamicTableNameHandler.remove();
return result;
}
@Override
public List<ContrastHarmonicResult> listAllResultData(String code, Integer num, String devId, List<String> adTypeList) {
String prefix = "ad_harmonic_result_" + code;
DynamicTableNameHandler.setTableName(prefix);
List<ContrastHarmonicResult> result = this.lambdaQuery().likeRight(ContrastHarmonicResult::getDevMonitorId, devId)
.eq(ObjectUtil.isNotNull(num), ContrastHarmonicResult::getNum, num)
.in(CollUtil.isNotEmpty(adTypeList), ContrastHarmonicResult::getAdType, adTypeList).list();
DynamicTableNameHandler.remove();
return result;
}
}

View File

@@ -1,12 +1,17 @@
package com.njcn.gather.storage.service.impl;
import cn.hutool.core.collection.CollUtil;
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.storage.mapper.ContrastNonHarmonicMappper;
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
import com.njcn.gather.storage.service.ContrastNonHarmonicService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author caozehui
* @data 2025-07-28
@@ -14,4 +19,29 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ContrastNonHarmonicServiceImpl extends ServiceImpl<ContrastNonHarmonicMappper, ContrastNonHarmonicResult> implements ContrastNonHarmonicService {
@Override
public List<ContrastNonHarmonicResult> listAllRawData(String code, Integer num, Integer flag, String devId, List<String> adTypeList) {
String prefix = "ad_non_harmonic_" + code;
DynamicTableNameHandler.setTableName(prefix);
List<ContrastNonHarmonicResult> result = this.lambdaQuery().likeRight(ContrastNonHarmonicResult::getDevMonitorId, devId)
.eq(ObjectUtil.isNotNull(num), ContrastNonHarmonicResult::getNum, num)
.eq(ContrastNonHarmonicResult::getFlag, flag)
.in(CollUtil.isNotEmpty(adTypeList), ContrastNonHarmonicResult::getAdType, adTypeList)
.orderByAsc(ContrastNonHarmonicResult::getTimeId).list();
DynamicTableNameHandler.remove();
return result;
}
@Override
public List<ContrastNonHarmonicResult> listAllResultData(String code, Integer num, String devId, List<String> adTypeList) {
String prefix = "ad_non_harmonic_result_" + code;
DynamicTableNameHandler.setTableName(prefix);
List<ContrastNonHarmonicResult> result = this.lambdaQuery().likeRight(ContrastNonHarmonicResult::getDevMonitorId, devId)
.eq(ObjectUtil.isNotNull(num), ContrastNonHarmonicResult::getNum, num)
.in(CollUtil.isNotEmpty(adTypeList), ContrastNonHarmonicResult::getAdType, adTypeList).list();
DynamicTableNameHandler.remove();
return result;
}
}

View File

@@ -15,6 +15,7 @@ import com.njcn.gather.storage.mapper.SimAndDigHarmonicMappper;
import com.njcn.gather.storage.mapper.SimAndDigNonHarmonicMapper;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
@@ -25,6 +26,7 @@ import com.njcn.gather.system.dictionary.mapper.DictTreeMapper;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.util.StorageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -106,15 +108,15 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
LocalDateTime localDateTime = (LocalDateTime) timeId.get(harmonicResult);
dataVO.setTime(localDateTime.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)));
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
dataVO.setDataA(StrUtil.isNotBlank(fieldA.get(harmonicResult) + "") ? new BigDecimal(fieldA.get(harmonicResult) + "").toPlainString() : null);
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
dataVO.setDataB(StrUtil.isNotBlank(fieldB.get(harmonicResult) + "") ? new BigDecimal(fieldB.get(harmonicResult) + "").toPlainString() : null);
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
dataVO.setDataC(StrUtil.isNotBlank(fieldC.get(harmonicResult) + "") ? new BigDecimal(fieldC.get(harmonicResult) + "").toPlainString() : null);
} catch (NoSuchFieldException e) {
@@ -167,17 +169,17 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
dataVO.setHarmNum(i);
dataVO.setUnit(unit);
try {
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
RawResultDataVO.DetectionData a = JSON.parseObject(fieldA.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataA(a);
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
RawResultDataVO.DetectionData b = JSON.parseObject(fieldB.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataB(b);
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + StorageUtil.isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
RawResultDataVO.DetectionData c = JSON.parseObject(fieldC.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataC(c);
@@ -275,7 +277,7 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
return results;
}
private Integer setResultFlag(List<RawResultDataVO.DetectionData> numbers) {
public static Integer setResultFlag(List<RawResultDataVO.DetectionData> numbers) {
List<Integer> isData = numbers.stream().filter(Objects::nonNull)
.filter(x -> ObjectUtil.isNotNull(x.getData()))
.map(RawResultDataVO.DetectionData::getIsData)
@@ -284,7 +286,7 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
return getInteger(isData);
}
private static Integer getInteger(List<Integer> isData) {
public static Integer getInteger(List<Integer> isData) {
if (CollUtil.isNotEmpty(isData)) {
List<Integer> isQualified = isData.stream().filter(x -> 1 == x || 2 == x).collect(Collectors.toList());
if (CollUtil.isNotEmpty(isQualified)) {
@@ -306,11 +308,4 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
return 4;
}
public Double isHarmOrInHarm(Double value) {
if (value == value.longValue()) {
return value;
} else {
return value + 0.5;
}
}
}

View File

@@ -20,6 +20,7 @@ import com.njcn.gather.storage.pojo.vo.RawResultDataVO;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.util.StorageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -75,7 +76,7 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
List<RawDataVO> rawDataVOS = new ArrayList<>();
for (SimAndDigNonHarmonicResult result : value) {
RawDataVO dataVO = new RawDataVO();
dataVO.setUnit(dictTree.getCode().equals("MAG")?"%":unit(dictTree.getCode()));
dataVO.setUnit(dictTree.getCode().equals("MAG")?"%": StorageUtil.unit(dictTree.getCode()));
dataVO.setTime(result.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)));
dataVO.setDataA(StrUtil.isNotBlank(result.getAValue()) ? new BigDecimal(result.getAValue()).toPlainString() : null);
dataVO.setDataB(StrUtil.isNotBlank(result.getBValue()) ? new BigDecimal(result.getBValue()).toPlainString() : null);
@@ -112,7 +113,7 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
DictTree treeName = dictTreeByName.get(key);
RawResultDataVO dataVO = new RawResultDataVO();
dataVO.setIsData(result.getResultFlag());
dataVO.setUnit(unit(treeName.getCode()));
dataVO.setUnit(StorageUtil.unit(treeName.getCode()));
RawResultDataVO.DetectionData a = JSON.parseObject(result.getAValue(), RawResultDataVO.DetectionData.class);
RawResultDataVO.DetectionData b = JSON.parseObject(result.getBValue(), RawResultDataVO.DetectionData.class);
RawResultDataVO.DetectionData c = JSON.parseObject(result.getCValue(), RawResultDataVO.DetectionData.class);
@@ -196,96 +197,5 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
return results;
}
private String unit(String code) {
String unit = "";
switch (code) {
/**
* 频率
*/
case "FREQ":
unit = "Hz";
break;
/**
* 电压
*/
case "VRMS":
unit = "V";
break;
/**
* 电流
*/
case "IRMS":
unit = "A";
break;
/**
* 谐波电压
*/
case "V2-50":
/**
* 谐波电流
*/
case "I2-50":
/**
* 间谐波电压
*/
case "SV_1-49":
/**
* 间谐波电流
*/
case "SI_1-49":
/**
* 三相电压不平衡度
*/
case "V_UNBAN":
/**
* 三相电流不平衡度
*/
case "I_UNBAN":
unit = "%";
break;
/**
* 谐波有功功率
*/
case "P2-50":
unit = "W";
break;
/**
* 功率
*/
case "P":
unit = "P";
break;
/**
* 闪变
*/
case "PST":
break;
/**
* 暂态-电压幅值
*/
case "MAG":
unit = "%";
break;
/**
* 暂态-持续时间
*/
case "DUR":
unit = "s";
break;
/**
* 相角
*/
case "VA":
case "IA":
unit = "°";
break;
/**
* 电压偏差
*/
case "DELTA_V":
unit = "%";
break;
}
return unit;
}
}

View File

@@ -45,6 +45,7 @@ public class TableGenServiceImpl implements TableGenService {
"Id char(32) COLLATE utf8mb4_bin NOT NULL COMMENT '主键Id',\n" +
"Std_Dev_Monitor_Id CHAR(34) NOT NULL COMMENT '标准设备监测点Id',\n" +
"Num tinyint(1) unsigned DEFAULT 0 COMMENT '第几次检测',\n" +
"Flag tinyint(1) unsigned NOT NULL COMMENT '0表示被检设备数据1表示标准设备数据',\n" +
"A_Value_0 float NULL COMMENT 'A相基波有效值',\n" +
"C_Value_0 float NULL COMMENT 'B相基波有效值',\n" +
"B_Value_0 float NULL COMMENT 'B相基波有效值',\n" +
@@ -70,6 +71,7 @@ public class TableGenServiceImpl implements TableGenService {
"Id char(32) COLLATE utf8mb4_bin NOT NULL COMMENT '主键Id',\n" +
"Std_Dev_Monitor_Id CHAR(34) NOT NULL COMMENT '标准设备监测点Id',\n" +
"Num tinyint(1) unsigned DEFAULT 0 COMMENT '第几次检测',\n" +
"Flag tinyint(1) unsigned DEFAULT NULL COMMENT '0表示被检设备数据1表示标准设备数据',\n" +
"A_Value_0 json NULL COMMENT 'A相基波有效值',\n" +
"B_Value_0 json NULL COMMENT 'B相基波有效值',\n" +
"C_Value_0 json NULL COMMENT 'B相基波有效值',\n" +

View File

@@ -0,0 +1,113 @@
package com.njcn.gather.util;
/**
* @author caozehui
* @data 2025-08-21
*/
public class StorageUtil {
public static Double isHarmOrInHarm(Double value) {
if (value == value.longValue()) {
return value;
} else {
return value + 0.5;
}
}
public static String unit(String code) {
String unit = "";
switch (code) {
/**
* 频率
*/
case "FREQ":
unit = "Hz";
break;
/**
* 电压
*/
case "V":
case "VRMS":
unit = "V";
break;
/**
* 电流
*/
case "I":
case "IRMS":
unit = "A";
break;
/**
* 谐波电压
*/
case "V2-50":
/**
* 谐波电流
*/
case "I2-50":
/**
* 间谐波电压
*/
case "SV_1-49":
/**
* 间谐波电流
*/
case "SI_1-49":
/**
* 三相电压不平衡度
*/
case "V_UNBAN":
case "IMBV":
/**
* 三相电流不平衡度
*/
case "I_UNBAN":
case "IMBA":
unit = "%";
break;
/**
* 谐波有功功率
*/
case "P2-50":
unit = "W";
break;
/**
* 功率
*/
case "P":
unit = "W";
break;
/**
* 闪变
*/
case "PST":
break;
/**
* 暂态-电压幅值
*/
case "MAG":
unit = "%";
break;
/**
* 暂态-持续时间
*/
case "DUR":
unit = "s";
break;
/**
* 相角
*/
case "VA":
case "IA":
unit = "°";
break;
/**
* 电压偏差
*/
case "DELTA_V":
unit = "%";
break;
}
return unit;
}
}