1.正式检测代码详情检测表格代码提交

This commit is contained in:
wr
2025-01-05 13:57:38 +08:00
parent 949aa83539
commit ea8a2bd8e7
10 changed files with 210 additions and 44 deletions

View File

@@ -32,5 +32,9 @@ public class DetectionData {
*/
private Double resultData;
/**
* 误差范围
*/
private String radius;
}

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.pojo.vo.DetectionData;
@@ -60,9 +61,9 @@ public class DetectionServiceImpl {
public Map<String, Integer> text(List<DevData> dev, String errorSysId, Map<String, String> devIdMapComm, SourceIssue issue, DictDataEnum dataRule) {
Map<String, List<DevData>> devDataMap = dev.stream().collect(Collectors.groupingBy(DevData::getId));
Map<String, Integer> stringBooleanMap = new LinkedHashMap<>();
String code="1";
String code = "1";
devDataMap.forEach(((key, value) -> {
stringBooleanMap.put(key, DetectionIndexProcessing(value,code, errorSysId, devIdMapComm, dataRule, issue));
stringBooleanMap.put(key, DetectionIndexProcessing(value, code, errorSysId, devIdMapComm, dataRule, issue));
}));
return stringBooleanMap;
}
@@ -77,7 +78,7 @@ public class DetectionServiceImpl {
* @param sourceIssue 源下发的参数
* @return
*/
public Integer DetectionIndexProcessing(List<DevData> dev,String code, String errorSysId, Map<String, String> devIdMapComm, DictDataEnum dataRule, SourceIssue sourceIssue) {
public Integer DetectionIndexProcessing(List<DevData> dev, String code, String errorSysId, Map<String, String> devIdMapComm, DictDataEnum dataRule, SourceIssue sourceIssue) {
PqErrSysParam.DetectionParam param = new PqErrSysParam.DetectionParam();
param.setIndex(sourceIssue.getIndex());
param.setScriptId(sourceIssue.getScriptId());
@@ -89,70 +90,70 @@ public class DetectionServiceImpl {
*/
case "FREQ":
AdNonHarmonicResult freq = isQualified(dev, devIdMapComm, pqErrSysDtls, F, sourceIssue, dataRule, "FREQ");
detectionDataDealService.acceptAdNonResult(Arrays.asList(freq),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(freq), code);
return freq.getResultFlag();
/**
* 电压
*/
case "V":
AdNonHarmonicResult vrms = isQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "VRMS");
detectionDataDealService.acceptAdNonResult(Arrays.asList(vrms),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(vrms), code);
return vrms.getResultFlag();
/**
* 电流
*/
case "I":
AdNonHarmonicResult irms = isQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, "IRMS");
detectionDataDealService.acceptAdNonResult(Arrays.asList(irms),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(irms), code);
return irms.getResultFlag();
/**
* 谐波电压
*/
case "HV":
AdHarmonicResult harmV = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmV),code);
detectionDataDealService.acceptAdResult(Arrays.asList(harmV), code);
return harmV.getResultFlag();
/**
* 谐波电流
*/
case "HI":
AdHarmonicResult harmI = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmI),code);
detectionDataDealService.acceptAdResult(Arrays.asList(harmI), code);
return harmI.getResultFlag();
/**
* 间谐波电压
*/
case "HSV":
AdHarmonicResult harmInV = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, 1);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInV),code);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInV), code);
return harmInV.getResultFlag();
/**
* 间谐波电流
*/
case "HSI":
AdHarmonicResult harmInI = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, 1);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInI),code);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInI), code);
return harmInI.getResultFlag();
/**
* 三相电压不平衡度
*/
case "IMBV":
AdNonHarmonicResult vUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "V_UNBAN");
detectionDataDealService.acceptAdNonResult(Arrays.asList(vUnban),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(vUnban), code);
return vUnban.getResultFlag();
/**
* 三相电流不平衡度
*/
case "IMBA":
AdNonHarmonicResult iUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, "I_UNBAN");
detectionDataDealService.acceptAdNonResult(Arrays.asList(iUnban),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(iUnban), code);
return iUnban.getResultFlag();
/**
* 谐波有功功率
*/
case "HP":
AdHarmonicResult harmP = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, P, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmP),code);
detectionDataDealService.acceptAdResult(Arrays.asList(harmP), code);
return harmP.getResultFlag();
/**
* 功率
@@ -164,13 +165,13 @@ public class DetectionServiceImpl {
*/
case "F":
AdNonHarmonicResult pst = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, null, sourceIssue, dataRule, "PST");
detectionDataDealService.acceptAdNonResult(Arrays.asList(pst),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(pst), code);
return pst.getResultFlag();
/**
* 暂态
*/
case "VOLTAGE":
return isVoltageQualified(dev, devIdMapComm, pqErrSysDtls, sourceIssue, dataRule,code);
return isVoltageQualified(dev, devIdMapComm, pqErrSysDtls, sourceIssue, dataRule, code);
}
return null;
}
@@ -214,7 +215,7 @@ public class DetectionServiceImpl {
result.setDataType("avg");
if (map.containsKey(TYPE_T)) {
DetectionData t = rangeComparisonList(map.get(TYPE_T), pqErrSysDtls, fData, 1.0, dataRule);
result.setTValue(t.getData() + "_" + t.getIsData()+"_"+t.getResultData());
result.setTValue(JSON.toJSONString(t));
result.setResultFlag(t.getIsData());
} else {
//取出源所对应的相别信息
@@ -222,19 +223,19 @@ public class DetectionServiceImpl {
.filter(x -> (type + "a").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getFAmp(), dataRule);
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
result.setAValue(JSON.toJSONString(a));
List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
.filter(x -> (type + "b").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getFAmp(), dataRule);
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
result.setBValue(JSON.toJSONString(b));
List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
.filter(x -> (type + "c").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getFAmp(), dataRule);
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+c.getResultData());
result.setCValue(JSON.toJSONString(c));
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), c.getIsData()).stream().distinct().collect(Collectors.toList());
return getAdNonHarmonicResult(result, numbers);
@@ -328,34 +329,34 @@ public class DetectionServiceImpl {
result.setSort(sourceIssue.getIndex());
result.setAdType(pqErrSysDtls.get(0).getScriptType());
result.setDataType("avg");
if(StrUtil.isBlank(type)){
if (StrUtil.isBlank(type)) {
//取出源所对应的相别信息
List<PqScriptCheckData> channelTypeAList = checkData.stream()
.filter(x -> TYPE_A.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule);
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
result.setAValue(JSON.toJSONString(a));
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_B.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
result.setBValue(JSON.toJSONString(b));
List<PqScriptCheckData> channelTypeCList = checkData.stream()
.filter(x -> TYPE_C.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule);
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+c.getResultData());
result.setCValue(JSON.toJSONString(c));
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), c.getIsData());
return getAdNonHarmonicResult(result, numbers);
}else{
} else {
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_T.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData t = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setBValue(t.getData() + "_" + t.getIsData()+"_"+t.getResultData());
result.setBValue(JSON.toJSONString(t));
List<Integer> numbers = Arrays.asList(t.getIsData());
return getAdNonHarmonicResult(result, numbers);
}
@@ -391,7 +392,7 @@ public class DetectionServiceImpl {
magResult.setAdType(magErrList.get(0).getScriptType());
AdNonHarmonicResult durResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, dur, durErrList, sourceIssue.getFFreq(), DUR);
durResult.setAdType(durErrList.get(0).getScriptType());
detectionDataDealService.acceptAdNonResult(Arrays.asList(magResult,durResult),code);
detectionDataDealService.acceptAdNonResult(Arrays.asList(magResult, durResult), code);
List<Integer> numbers = Arrays.asList(magResult.getResultFlag(), durResult.getResultFlag()).stream().distinct().collect(Collectors.toList());
if (numbers.contains(4)) {
return 4;
@@ -441,7 +442,7 @@ public class DetectionServiceImpl {
retainATime = channelTypeAList.get(0).getFAmp();
}
DetectionData a = rangeComparisonList(mag.get(TYPE_A), magErrList, fData, retainATime, dataRule);
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
result.setAValue(JSON.toJSONString(a));
List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
.filter(x -> ("Ub").equals(x.getChannelType()))
@@ -453,7 +454,7 @@ public class DetectionServiceImpl {
retainBTime = channelTypeBList.get(0).getFAmp();
}
DetectionData b = rangeComparisonList(mag.get(TYPE_B), magErrList, fData, retainBTime, dataRule);
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
result.setBValue(JSON.toJSONString(b));
List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
.filter(x -> ("Uc").equals(x.getChannelType()))
@@ -465,7 +466,7 @@ public class DetectionServiceImpl {
retainCTime = channelTypeCList.get(0).getFAmp();
}
DetectionData c = rangeComparisonList(mag.get(TYPE_C), magErrList, fData, retainCTime, dataRule);
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+c.getResultData());
result.setCValue(JSON.toJSONString(c));
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), c.getIsData()).stream().distinct().collect(Collectors.toList());
@@ -578,7 +579,7 @@ public class DetectionServiceImpl {
if (ObjectUtil.isNull(value.getIsData())) {
idField.set(harmonicResult, value.getData());
} else {
idField.set(harmonicResult, value.getData() + "_" + value.getIsData()+"_"+value.getResultData());
idField.set(harmonicResult,JSON.toJSONString(value));
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
@@ -645,7 +646,7 @@ public class DetectionServiceImpl {
}
});
devMap.forEach((harm, harmDataList) -> {
PqErrSysDtls errSysDtl = errSysDtlMap.get(num==1?harm+0.5:harm);
PqErrSysDtls errSysDtl = errSysDtlMap.get(num == 1 ? harm + 0.5 : harm);
DetectionData data = new DetectionData();
data.setIsData(4);
data.setNum(harm);
@@ -680,6 +681,7 @@ public class DetectionServiceImpl {
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList());
if (CollUtil.isNotEmpty(qualifiedList)) {
data.setRadius(-errSysDtl.getMaxErrorValue()+"-"+errSysDtl.getMaxErrorValue());
data.setData(qualifiedList.get(0));
switch (dataRule) {
case AT_WILL_VALUE:
@@ -721,7 +723,7 @@ public class DetectionServiceImpl {
for (DevData devData : dev) {
Optional<DevData.SqlDataDTO> first = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst();
DevData.SqlDataDTO fund = null;
if (first.isPresent()){
if (first.isPresent()) {
fund = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst().get();
}
DevData.SqlDataHarmDTO harm = devData.getSqlDataHarm().stream().filter(x -> 49 == x.getNum()).collect(Collectors.toList()).stream().findFirst().get();
@@ -786,9 +788,11 @@ public class DetectionServiceImpl {
BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())),
BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())))
).collect(Collectors.toList());
detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue());
detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue() * channelData);
if (CollUtil.isNotEmpty(qualifiedList)) {
detectionData.setData(qualifiedList.get(0));
detectionData.setRadius(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue()))
+ "-" + BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())));
switch (dataRule) {
case AT_WILL_VALUE:
case CP95_VALUE:

View File

@@ -760,9 +760,9 @@ public class ResultServiceImpl implements IResultService {
if (CollUtil.isNotEmpty(cur)) {
String unit;
if (isValueType) {
unit = ResultUnitEnum.V_RELATIVE_UNIT.getUnit();
unit = ResultUnitEnum.I_RELATIVE_UNIT.getUnit();
} else {
unit = ResultUnitEnum.V_ABSOLUTELY_UNIT.getUnit();
unit = ResultUnitEnum.I_ABSOLUTELY_UNIT.getUnit();
}
for (PqScriptDtls dtls : cur) {
buffer.append("I" + dtls.getPhase().toLowerCase() + "=" + dtls.getValue() + unit + ",相角=" + dtls.getAngle() + "° ");

View File

@@ -38,6 +38,11 @@
<artifactId>spingboot2.3.12</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>com.njcn.gather</groupId>
<artifactId>system</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

View File

@@ -2,6 +2,8 @@ package com.njcn.gather.storage.pojo.param;
import lombok.Data;
import java.util.List;
/**
* @author wr
* @description
@@ -34,4 +36,9 @@ public class StorageParam {
* 自动生成,用于生成数据表后缀
*/
private Integer code;
/**
* 谐波次数
*/
private List<Double> harmNum;
}

View File

@@ -37,4 +37,9 @@ public class RawDataVO {
* C相数据
*/
private BigDecimal dataC;
/**
* C相数据
*/
private BigDecimal dataT;
}

View File

@@ -1,10 +1,13 @@
package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import java.util.List;
import java.util.Map;
/**
* @author caozehui
@@ -22,5 +25,13 @@ public interface AdHarmonicService extends IService<AdHarmonicResult> {
* @param code 计划code
* @return 谐波结果
*/
List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum,Integer code);
List<AdBaseResult> get(String scriptId, List<Integer> index, String deviceId, String chnNum, Integer code);
/**
* 查询原始数据
*
* @param param
* @return
*/
Map<String, List<RawDataVO>> listResultData(StorageParam param);
}

View File

@@ -1,10 +1,13 @@
package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import java.util.List;
import java.util.Map;
public interface AdNonHarmonicService extends IService<AdNonHarmonicResult> {
@@ -20,5 +23,10 @@ public interface AdNonHarmonicService extends IService<AdNonHarmonicResult> {
*/
List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum,Integer code);
/**
* 非谐波原始数据展示
* @param param
* @return
*/
Map<String,List<RawDataVO>> listNonResultData(StorageParam param) ;
}

View File

@@ -2,17 +2,27 @@ package com.njcn.gather.storage.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.storage.mapper.AdHarmonicMappper;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdHarmonicService;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author caozehui
@@ -21,9 +31,9 @@ import java.util.List;
@Service
public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarmonicResult> implements AdHarmonicService {
@Override
public List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum,Integer code ) {
public List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum, Integer code) {
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix +code);
DynamicTableNameHandler.setTableName(prefix + code);
MPJLambdaWrapper<AdHarmonicResult> wrapper = new MPJLambdaWrapper<>();
String monitorId = deviceId + "_" + chnNum;
if ("-1".equals(chnNum)) {
@@ -36,4 +46,71 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
DynamicTableNameHandler.remove();
return BeanUtil.copyToList(list, AdBaseResult.class);
}
@Override
public Map<String, List<RawDataVO>> listResultData(StorageParam param) {
String prefix = "ad_harmonic_";
DynamicTableNameHandler.setTableName(prefix + param.getCode());
MPJLambdaWrapper<AdHarmonicResult> wrapper = new MPJLambdaWrapper<>();
wrapper.like(AdHarmonicResult::getMonitorId, param.getDevId() + "_" + param.getDevNum())
.eq(ObjectUtil.isNotNull(param.getScriptId()), AdHarmonicResult::getScriptId, param.getScriptId())
.in(ObjectUtil.isNotEmpty(param.getIndex()), AdHarmonicResult::getSort, param.getIndex())
.orderByAsc(AdHarmonicResult::getTimeId)
;
List<AdHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdHarmonicResult.class, wrapper);
List<Double> harmNum = param.getHarmNum();
Map<String, List<RawDataVO>> info=new HashMap<>(3);
RawDataVO dataVO;
List<RawDataVO> rawDataVOS;
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
dataVO = new RawDataVO();
dataVO.setHarmNum(i);
try {
Field timeId = harmonicResult.getClass().getDeclaredField("timeId");
timeId.setAccessible(true);
LocalDateTime localDateTime = (LocalDateTime) timeId.get(harmonicResult);
dataVO.setTime(localDateTime.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
BigDecimal decimalA = new BigDecimal(fieldA.get(harmonicResult)+"");
dataVO.setDataA(decimalA);
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
BigDecimal decimalB = new BigDecimal(fieldB.get(harmonicResult)+"");
dataVO.setDataB(decimalB);
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
BigDecimal decimalC = new BigDecimal(fieldC.get(harmonicResult)+"");
dataVO.setDataC(decimalC);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
if(info.containsKey(String.valueOf(i))){
info.get(String.valueOf(i)).add(dataVO);
}else{
rawDataVOS=new ArrayList<>();
rawDataVOS.add(dataVO);
info.put(String.valueOf(i),rawDataVOS) ;
}
}
}
DynamicTableNameHandler.remove();
return info;
}
public Double isHarmOrInHarm(Double value) {
if (value == value.longValue()) {
return value;
} else {
return value + 0.5;
}
}
}

View File

@@ -2,24 +2,36 @@ package com.njcn.gather.storage.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.storage.mapper.AdNonHarmonicMapper;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
*
*/
@Service
@RequiredArgsConstructor
public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, AdNonHarmonicResult> implements AdNonHarmonicService {
private final IDictTreeService dictTreeService;
@Override
public List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum, Integer code) {
String prefix = "ad_non_harmonic_result_";
@@ -37,4 +49,37 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, A
DynamicTableNameHandler.remove();
return BeanUtil.copyToList(list, AdBaseResult.class);
}
@Override
public Map<String, List<RawDataVO>> listNonResultData(StorageParam param) {
String prefix = "ad_non_harmonic_";
DynamicTableNameHandler.setTableName(prefix + param.getCode());
MPJLambdaWrapper<AdNonHarmonicResult> wrapper = new MPJLambdaWrapper<>();
wrapper.like(AdNonHarmonicResult::getMonitorId, param.getDevId() + "_" + param.getDevNum())
.eq(ObjectUtil.isNotNull(param.getScriptId()), AdNonHarmonicResult::getScriptId, param.getScriptId())
.in(ObjectUtil.isNotEmpty(param.getIndex()), AdNonHarmonicResult::getSort, param.getIndex());
List<AdNonHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdNonHarmonicResult.class, wrapper);
Map<String, List<RawDataVO>> info = new HashMap<>(2);
Map<String, List<AdNonHarmonicResult>> adTypeMap = adHarmonicResults.stream().collect(Collectors.groupingBy(AdNonHarmonicResult::getAdType));
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(adTypeMap.keySet()));
Map<String, String> dictTreeByName = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, DictTree::getName));
adTypeMap.forEach((key, value) -> {
if (dictTreeByName.containsKey(key)) {
String treeName = dictTreeByName.get(key);
List<RawDataVO> rawDataVOS = new ArrayList<>();
for (AdNonHarmonicResult result : value) {
RawDataVO dataVO = new RawDataVO();
dataVO.setTime(result.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
dataVO.setDataA(ObjectUtil.isNotNull(result.getAValue())?new BigDecimal(result.getAValue()):null);
dataVO.setDataB(ObjectUtil.isNotNull(result.getBValue())?new BigDecimal(result.getBValue()):null);
dataVO.setDataC(ObjectUtil.isNotNull(result.getCValue())?new BigDecimal(result.getCValue()):null);
dataVO.setDataT(ObjectUtil.isNotNull(result.getTValue())?new BigDecimal(result.getTValue()):null);
rawDataVOS.add(dataVO);
}
info.put(key,rawDataVOS);
}
});
DynamicTableNameHandler.remove();
return info;
}
}