1.解决检测完成,可能有脏数据引发的不符合问题

2.优化检测树单位,解决自动生成表缺少部分字段
This commit is contained in:
wr
2025-01-14 16:23:33 +08:00
parent dd4cf1eede
commit 9fc1baad28
10 changed files with 72 additions and 46 deletions

View File

@@ -19,6 +19,7 @@ import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
@@ -46,8 +47,6 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -85,7 +84,7 @@ public class SocketDevResponseService {
private final IAdPlanService adPlanService;
private final ExecutorService executorPool = Executors.newFixedThreadPool(10);
// private final ExecutorService executorPool = Executors.newFixedThreadPool(10);
/**
@@ -986,7 +985,12 @@ public class SocketDevResponseService {
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xuMsg));
} else {
//TODO 是否最终检测完成需要推送给用户
iPqDevService.updateResult(param.getDevIds(), param.getCode());
PqScriptCheckDataParam checkDataParam=new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(),valueType, param.getCode());
CnSocketUtil.quitSend(param);
}
successComm.clear();

View File

@@ -177,10 +177,11 @@ public interface IPqDevService extends IService<PqDev> {
/**
* 正式监测完成,修改中断状态
* @param ids
* @param valueType
* @param code
* @return
*/
boolean updateResult(List<String> ids,String code);
boolean updateResult(List<String> ids,List<String> valueType ,String code);
void updatePqDevReportState(String devId, int i);

View File

@@ -489,9 +489,9 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
@Override
public boolean updateResult(List<String> ids, String code) {
public boolean updateResult(List<String> ids,List<String> valueType, String code) {
if (CollUtil.isNotEmpty(ids)) {
Map<String, Integer> result = detectionDataDealService.devResult(ids, code);
Map<String, Integer> result = detectionDataDealService.devResult(ids,valueType, code);
List<PqDev> list = this.list(new LambdaQueryWrapper<PqDev>().in(PqDev::getId, ids));
for (PqDev pqDev : list) {
if (result.containsKey(pqDev.getId())) {

View File

@@ -1,15 +1,14 @@
package com.njcn.gather.device.script.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.gather.device.script.mapper.PqScriptCheckDataMapper;
import com.njcn.gather.device.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.device.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.device.script.pojo.vo.PqScriptCheckDataVO;
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
import com.njcn.gather.system.dictionary.mapper.DictTreeMapper;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
@@ -18,7 +17,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -45,7 +43,7 @@ public class PqScriptCheckDataServiceImpl extends ServiceImpl<PqScriptCheckDataM
queryWrapper.selectAll(PqScriptCheckData.class)
.leftJoin(DictTree.class, DictTree::getId, PqScriptCheckData::getValueType)
.eq(PqScriptCheckData::getScriptId, param.getScriptId())
.eq(PqScriptCheckData::getIndex, param.getIndex())
.eq(ObjectUtil.isNotNull(param.getIndex()),PqScriptCheckData::getIndex, param.getIndex())
.eq(PqScriptCheckData::getEnable, DataStateEnum.ENABLE.getCode());
if (param.getIsValueTypeName()) {
queryWrapper.selectAs(DictTree::getCode, PqScriptCheckData::getValueType);

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.device.script.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.device.script.pojo.enums.ResultUnitEnum;
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
@@ -16,6 +17,9 @@ import java.util.stream.Collectors;
*/
public class ScriptDtlsDesc {
public static StringBuffer getStringBuffer(List<PqScriptDtls> scriptDtlIndex, Boolean isValueType) {
if(ObjectUtil.isNull(isValueType)){
isValueType=false;
}
StringBuffer buffer = new StringBuffer();
buffer.append("输入:");
appendValue(scriptDtlIndex, buffer, "Freq", "频率", ResultUnitEnum.FREQ_UNIT.getUnit(), null);

View File

@@ -10,6 +10,7 @@
Sort int(4) NOT NULL COMMENT '总检测脚本中的测试项序号',
AD_Type CHAR(32) NOT NULL COMMENT '检测指标,字典表',
Data_Type CHAR(32) NOT NULL COMMENT '数据指标只有数据源为分钟统计时候才会使用最大、最小、平均、CP95默认平均值字典表',
Result_Flag int(1) COMMENT '1不合格 2合格 4无法处理',
A_Value varchar(30) DEFAULT NULL COMMENT 'A相值',
B_Value varchar(30) DEFAULT NULL COMMENT 'B相值',
C_Value varchar(30) DEFAULT NULL COMMENT 'C相值',
@@ -37,7 +38,7 @@
B_Value json NULL COMMENT 'B相值',
C_Value json NULL COMMENT 'C相值',
T_Value json NULL COMMENT 'T相值(没有相别的则存这里)',
PRIMARY KEY (Monitor_Id, Script_Id, Sort, AD_Type)
PRIMARY KEY (Monitor_Id, Script_Id, Sort, AD_Type,Data_Type)
) COMMENT='监测数据表';
</update>

View File

@@ -23,8 +23,9 @@ public interface DetectionDataDealService extends IReplenishMybatisService<AdHar
/**
* 根据终端id查询终端所有监测项目是否合格
* @param ids
* @param valueType
* @param code
* @return
*/
Map<String,Integer> devResult(List<String> ids,String code);
Map<String,Integer> devResult(List<String> ids,List<String> valueType,String code);
}

View File

@@ -20,7 +20,9 @@ import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.pojo.vo.RawResultDataVO;
import com.njcn.gather.storage.service.AdHarmonicService;
import io.swagger.models.auth.In;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -40,6 +42,7 @@ import java.util.stream.Collectors;
public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarmonicResult> implements AdHarmonicService {
private final AdNonHarmonicMapper adNonHarmonicMapper;
private final IDictDataService dictDataService;
@Override
public List<AdBaseResult> get(String scriptId, List<Integer> sort, String deviceId, String chnNum, Integer code) {
@@ -129,42 +132,51 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
.orderByAsc(AdHarmonicResult::getTimeId);
List<AdHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdHarmonicResult.class, wrapper);
List<Double> harmNum = param.getHarmNum();
Map<String, RawResultDataVO> info=new LinkedHashMap<>(3);
RawResultDataVO dataVO;
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
dataVO = new RawResultDataVO();
dataVO.setHarmNum(i);
dataVO.setIsData(harmonicResult.getResultFlag());
dataVO.setUnit("%");
try {
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
RawResultDataVO.DetectionData a = JSON.parseObject(fieldA.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
dataVO.setDataA(a);
if(CollUtil.isNotEmpty(adHarmonicResults)){
List<Double> harmNum = param.getHarmNum();
RawResultDataVO dataVO;
DictData dictData = dictDataService.getDictDataById(adHarmonicResults.get(0).getAdType());
String unit;
if(DictDataEnum.I2_50.getCode().equals(dictData.getCode())||DictDataEnum.SI_1_49.getCode().equals(dictData.getCode())){
unit="A";
}else{
unit="%";
}
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
dataVO = new RawResultDataVO();
dataVO.setHarmNum(i);
dataVO.setIsData(harmonicResult.getResultFlag());
dataVO.setUnit(unit);
try {
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + 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());
fieldB.setAccessible(true);
RawResultDataVO.DetectionData b = JSON.parseObject(fieldB.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
dataVO.setDataB(b);
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + 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());
fieldC.setAccessible(true);
RawResultDataVO.DetectionData c = JSON.parseObject(fieldC.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
dataVO.setDataC(c);
if(ObjectUtil.isNotNull(a)){
dataVO.setRadius(a.getRadius());
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
RawResultDataVO.DetectionData c = JSON.parseObject(fieldC.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
dataVO.setDataC(c);
if(ObjectUtil.isNotNull(a)){
dataVO.setRadius(a.getRadius());
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
info.put(String.valueOf(i),dataVO) ;
}
info.put(String.valueOf(i),dataVO) ;
}
}
DynamicTableNameHandler.remove();
return info;
}

View File

@@ -94,12 +94,13 @@ public class DetectionDataServiceImpl extends ReplenishMybatisServiceImpl<Detect
}
@Override
public Map<String, Integer> devResult(List<String> ids,String code) {
public Map<String, Integer> devResult(List<String> ids,List<String> valueType,String code) {
List<AdNonHarmonicResult> noHarm=new ArrayList<>();
for (String id : ids) {
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
noHarm.addAll(adNonHarmonicService.list( new LambdaQueryWrapper<AdNonHarmonicResult>()
.like(AdNonHarmonicResult::getMonitorId,id)
.in(CollUtil.isNotEmpty(valueType),AdNonHarmonicResult::getAdType,valueType)
)) ;
}
DynamicTableNameHandler.remove();
@@ -108,6 +109,7 @@ public class DetectionDataServiceImpl extends ReplenishMybatisServiceImpl<Detect
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
harm.addAll(this.list( new LambdaQueryWrapper<AdHarmonicResult>()
.like(AdHarmonicResult::getMonitorId,id)
.in(CollUtil.isNotEmpty(valueType),AdHarmonicResult::getAdType,valueType)
)) ;
}
DynamicTableNameHandler.remove();

View File

@@ -28,8 +28,11 @@ public enum DictDataEnum {
AVG_VALUE("平均值", "Avg_value"),
Own_value("所有值", "Own_value"),
/**
* 字典树code
*/
I2_50("谐波电流幅值", "I2-50"),
SI_1_49("间谐波电流幅值", "SI_1-49"),
;