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 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.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.gather.detection.pojo.po.DevData; import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.pojo.vo.DetectionData; import com.njcn.gather.detection.pojo.vo.DetectionData;
@@ -214,7 +215,7 @@ public class DetectionServiceImpl {
result.setDataType("avg"); result.setDataType("avg");
if (map.containsKey(TYPE_T)) { if (map.containsKey(TYPE_T)) {
DetectionData t = rangeComparisonList(map.get(TYPE_T), pqErrSysDtls, fData, 1.0, dataRule); 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()); result.setResultFlag(t.getIsData());
} else { } else {
//取出源所对应的相别信息 //取出源所对应的相别信息
@@ -222,19 +223,19 @@ public class DetectionServiceImpl {
.filter(x -> (type + "a").equals(x.getChannelType())) .filter(x -> (type + "a").equals(x.getChannelType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getFAmp(), dataRule); 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() List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
.filter(x -> (type + "b").equals(x.getChannelType())) .filter(x -> (type + "b").equals(x.getChannelType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getFAmp(), dataRule); 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() List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
.filter(x -> (type + "c").equals(x.getChannelType())) .filter(x -> (type + "c").equals(x.getChannelType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getFAmp(), dataRule); 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()); List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), c.getIsData()).stream().distinct().collect(Collectors.toList());
return getAdNonHarmonicResult(result, numbers); return getAdNonHarmonicResult(result, numbers);
@@ -334,19 +335,19 @@ public class DetectionServiceImpl {
.filter(x -> TYPE_A.equals(x.getPhase())) .filter(x -> TYPE_A.equals(x.getPhase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule); 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() List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_B.equals(x.getPhase())) .filter(x -> TYPE_B.equals(x.getPhase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule); 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() List<PqScriptCheckData> channelTypeCList = checkData.stream()
.filter(x -> TYPE_C.equals(x.getPhase())) .filter(x -> TYPE_C.equals(x.getPhase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule); 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()); List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), c.getIsData());
return getAdNonHarmonicResult(result, numbers); return getAdNonHarmonicResult(result, numbers);
@@ -355,7 +356,7 @@ public class DetectionServiceImpl {
.filter(x -> TYPE_T.equals(x.getPhase())) .filter(x -> TYPE_T.equals(x.getPhase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
DetectionData t = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule); 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()); List<Integer> numbers = Arrays.asList(t.getIsData());
return getAdNonHarmonicResult(result, numbers); return getAdNonHarmonicResult(result, numbers);
} }
@@ -441,7 +442,7 @@ public class DetectionServiceImpl {
retainATime = channelTypeAList.get(0).getFAmp(); retainATime = channelTypeAList.get(0).getFAmp();
} }
DetectionData a = rangeComparisonList(mag.get(TYPE_A), magErrList, fData, retainATime, dataRule); 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() List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
.filter(x -> ("Ub").equals(x.getChannelType())) .filter(x -> ("Ub").equals(x.getChannelType()))
@@ -453,7 +454,7 @@ public class DetectionServiceImpl {
retainBTime = channelTypeBList.get(0).getFAmp(); retainBTime = channelTypeBList.get(0).getFAmp();
} }
DetectionData b = rangeComparisonList(mag.get(TYPE_B), magErrList, fData, retainBTime, dataRule); 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() List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
.filter(x -> ("Uc").equals(x.getChannelType())) .filter(x -> ("Uc").equals(x.getChannelType()))
@@ -465,7 +466,7 @@ public class DetectionServiceImpl {
retainCTime = channelTypeCList.get(0).getFAmp(); retainCTime = channelTypeCList.get(0).getFAmp();
} }
DetectionData c = rangeComparisonList(mag.get(TYPE_C), magErrList, fData, retainCTime, dataRule); 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()); 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())) { if (ObjectUtil.isNull(value.getIsData())) {
idField.set(harmonicResult, value.getData()); idField.set(harmonicResult, value.getData());
} else { } else {
idField.set(harmonicResult, value.getData() + "_" + value.getIsData()+"_"+value.getResultData()); idField.set(harmonicResult,JSON.toJSONString(value));
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -680,6 +681,7 @@ public class DetectionServiceImpl {
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()), BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList()); BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList());
if (CollUtil.isNotEmpty(qualifiedList)) { if (CollUtil.isNotEmpty(qualifiedList)) {
data.setRadius(-errSysDtl.getMaxErrorValue()+"-"+errSysDtl.getMaxErrorValue());
data.setData(qualifiedList.get(0)); data.setData(qualifiedList.get(0));
switch (dataRule) { switch (dataRule) {
case AT_WILL_VALUE: case AT_WILL_VALUE:
@@ -786,9 +788,11 @@ public class DetectionServiceImpl {
BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())), BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())),
BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue()))) BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())))
).collect(Collectors.toList()); ).collect(Collectors.toList());
detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue()); detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue() * channelData);
if (CollUtil.isNotEmpty(qualifiedList)) { if (CollUtil.isNotEmpty(qualifiedList)) {
detectionData.setData(qualifiedList.get(0)); 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) { switch (dataRule) {
case AT_WILL_VALUE: case AT_WILL_VALUE:
case CP95_VALUE: case CP95_VALUE:

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,13 @@
package com.njcn.gather.storage.service; package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService; 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.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult; import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author caozehui * @author caozehui
@@ -22,5 +25,13 @@ public interface AdHarmonicService extends IService<AdHarmonicResult> {
* @param code 计划code * @param code 计划code
* @return 谐波结果 * @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; package com.njcn.gather.storage.service;
import com.baomidou.mybatisplus.extension.service.IService; 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.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult; import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import java.util.List; import java.util.List;
import java.util.Map;
public interface AdNonHarmonicService extends IService<AdNonHarmonicResult> { 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); 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.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.storage.mapper.AdHarmonicMappper; 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.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult; import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdHarmonicService; import com.njcn.gather.storage.service.AdHarmonicService;
import org.springframework.stereotype.Service; 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.List;
import java.util.Map;
/** /**
* @author caozehui * @author caozehui
@@ -36,4 +46,71 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
DynamicTableNameHandler.remove(); DynamicTableNameHandler.remove();
return BeanUtil.copyToList(list, AdBaseResult.class); 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.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.storage.mapper.AdNonHarmonicMapper; 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.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult; 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.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 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 @Service
@RequiredArgsConstructor
public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, AdNonHarmonicResult> implements AdNonHarmonicService { public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, AdNonHarmonicResult> implements AdNonHarmonicService {
private final IDictTreeService dictTreeService;
@Override @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_non_harmonic_result_"; String prefix = "ad_non_harmonic_result_";
@@ -37,4 +49,37 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, A
DynamicTableNameHandler.remove(); DynamicTableNameHandler.remove();
return BeanUtil.copyToList(list, AdBaseResult.class); 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;
}
} }