代码调整

This commit is contained in:
2025-01-03 13:21:45 +08:00
parent 5c8a4fbfb8
commit 82acf16593
10 changed files with 217 additions and 52 deletions

View File

@@ -96,11 +96,11 @@ public class PreDetectionController extends BaseController {
List<DevData> devDataList = new ArrayList<>();
DevData aa = JSON.parseObject(a, DevData.class);
DevData bb = JSON.parseObject(a, DevData.class);
DevData cc = JSON.parseObject(a, DevData.class);
DevData dd = JSON.parseObject(a, DevData.class);
DevData ee = JSON.parseObject(a, DevData.class);
DevData ff = JSON.parseObject(a, DevData.class);
DevData bb = JSON.parseObject(b, DevData.class);
DevData cc = JSON.parseObject(c, DevData.class);
DevData dd = JSON.parseObject(d, DevData.class);
DevData ee = JSON.parseObject(e, DevData.class);
DevData ff = JSON.parseObject(f, DevData.class);
devDataList.add(aa);
devDataList.add(bb);
devDataList.add(cc);

View File

@@ -27,9 +27,11 @@ import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -37,8 +39,11 @@ 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.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@@ -49,6 +54,8 @@ public class SocketDevResponseService {
private final String handlerStr = "_Dev";
private final String handlerSourceStr = "_Source";
//private final List<String> dicDataList = Stream.of(DicDataEnum.FREQ.getCode(),DicDataEnum.V.getCode())
private final WebSocketHandler webSocketHandler;
private final IPqDevService iPqDevService;
private final IPqScriptDtlsService scriptDtlsService;
@@ -58,6 +65,10 @@ public class SocketDevResponseService {
private final DetectionDataDealService detectionDataDealService;
private final ExecutorService executorPool = Executors.newFixedThreadPool(5);
/**
@@ -235,7 +246,7 @@ public class SocketDevResponseService {
//successXieyi = new ArrayList<>();
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
Map<String, List<PreDetection>> map = new HashMap(1);
Map<String, List<PreDetection>> map = new HashMap<>(1);
map.put("deviceList", devList);
String jsonString = JSON.toJSONString(map);
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
@@ -451,6 +462,10 @@ public class SocketDevResponseService {
if (successComm.size() == monitorIdListComm.size()) {
System.out.println(sourceIssue.getType() +"_"+ sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
//原始数据入库
baseDataInsert(devDataList,sourceIssue,param);
System.out.println(JSON.toJSONString(sourceIssue));
//开启线程进行入库原始数据操作
@@ -459,15 +474,11 @@ public class SocketDevResponseService {
long tem = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
SocketManager.addTargetMap(sourceIssue.getType(), tem);
System.out.println("该大项还有"+tem+"个小项没有进行检测!!!!!!!!");
if (tem == 0) {
System.out.println(sourceIssue.getType() + sourceIssue.getIndex() + "当前测试大项已经全部结束》》》》》》》》");
baseDataInsert(devDataList,sourceIssue,param);
//当val为0则认为大项中的小项已经全部跑完开始组装信息推送给前端
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1] + "_End");
@@ -491,15 +502,16 @@ public class SocketDevResponseService {
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO));
}
System.out.println("当前小项结束进行删除============"+sourceIssue.getType()+"_"+sourceIssue.getIndex());
//开始进行下一个大项检测
//当小项结束后需要删除集合中的小项
SocketManager.delSource(sourceIssue.getIndex());
//开始进行下一项检测
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
if (CollUtil.isNotEmpty(sourceIssueList)) {
SocketMsg<String> xuMsg = new SocketMsg<>();
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
//正式检测
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
xuMsg.setData(JSON.toJSONString(sourceIssues));
@@ -507,13 +519,10 @@ public class SocketDevResponseService {
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
}
//当小项结束后需要删除集合中的小项
SocketManager.delSource(sourceIssue.getIndex());
System.out.println("当前小项结束进行删除============"+sourceIssue.getType()+"_"+sourceIssue.getIndex());
successComm.clear();
devDataList.clear();
}
}
break;
case UNPROCESSED_BUSINESS:
@@ -746,32 +755,104 @@ public class SocketDevResponseService {
* @date 2024/12/29
*/
private void baseDataInsert(List<DevData> devDataList,SourceIssue sourceIssue,PreDetectionParam param){
Runnable runnable = new Runnable() {
@Override
public void run() {
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; // ISO 8601格式
Runnable runnable = () -> {
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; // ISO 8601格式
List<AdNonHarmonicResult> adHarmonicResultList = new ArrayList<>();
for(DevData data : devDataList){
AdNonHarmonicResult adNonHarmonicResult = new AdNonHarmonicResult();
List<AdNonHarmonicResult> adNonHarmonicResultList = new ArrayList<>();
List<AdHarmonicResult> adHarmonicResultList = new ArrayList<>();
for(DevData data : devDataList){
LocalDateTime localDateTime = timeFormat(data.getTime(),formatter);
if(Objects.nonNull(localDateTime)){
LocalDateTime localDateTime = timeFormat(data.getTime(),formatter);
if(Objects.nonNull(localDateTime)){
if(Stream.of("FREQ","V","IMBA","P","I","IMBV").collect(Collectors.toList()).contains(sourceIssue.getType())){
AdNonHarmonicResult adNonHarmonicResult = new AdNonHarmonicResult();
adNonHarmonicResult.setTimeId(localDateTime);
adNonHarmonicResult.setMonitorId(data.getId());
adNonHarmonicResult.setScriptId(param.getScriptId());
adNonHarmonicResult.setSort(sourceIssue.getIndex());
adNonHarmonicResult.setAdType(sourceIssue.getSourceId());
adNonHarmonicResult.setAValue(data.getSqlData().get(0).getList().getA().toString());
adNonHarmonicResult.setBValue(data.getSqlData().get(0).getList().getB().toString());
adNonHarmonicResult.setCValue(data.getSqlData().get(0).getList().getC().toString());
adHarmonicResultList.add(adNonHarmonicResult);
adNonHarmonicResult.setAdType(sourceIssue.getId());
adNonHarmonicResult.setDataType("avg");
DevData.SqlDataDTO.ListDTO tem = data.getSqlData().get(0).getList();
Double a = tem.getA();
Double b = tem.getB();
Double c = tem.getC();
Double d = tem.getT();
if(Objects.nonNull(a)){
adNonHarmonicResult.setAValue(String.format("%.7f", a));
}
if(Objects.nonNull(b)){
adNonHarmonicResult.setBValue(String.format("%.7f", b));
}
if(Objects.nonNull(c)){
adNonHarmonicResult.setCValue(String.format("%.7f", c));
}
if(Objects.nonNull(d)){
adNonHarmonicResult.setTValue(String.format("%.7f", d));
}
adNonHarmonicResultList.add(adNonHarmonicResult);
}else {
//DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().get(0).getList();
AdHarmonicResult adHarmonicResult = new AdHarmonicResult();
adHarmonicResult.setTimeId(localDateTime);
adHarmonicResult.setMonitorId(data.getId());
adHarmonicResult.setScriptId(param.getScriptId());
adHarmonicResult.setSort(sourceIssue.getIndex());
adHarmonicResult.setAdType(sourceIssue.getId());
adHarmonicResult.setDataType("avg");
/* Double aV = vvv.getA();
Double bV = vvv.getB();
Double cV = vvv.getC();
if(Objects.nonNull(aV)){
adHarmonicResult.setAValue1(aV.toString());
}
if(Objects.nonNull(bV)){
adHarmonicResult.setBValue1(bV.toString());
}
if(Objects.nonNull(cV)){
adHarmonicResult.setCValue1(cV.toString());
}*/
DevData.SqlDataHarmDTO.ListDTO tem = data.getSqlDataHarm().get(0).getList();
List<String> a = tem.getA();
List<String> b = tem.getB();
List<String> c = tem.getC();
Class<AdHarmonicResult> example = (Class<AdHarmonicResult>) adHarmonicResult.getClass();
for(int i = 2;i<=50;i++){
// 通过反射设置name字段的值
try {
// 假设这些字段已经以正确的方式定义在AdHarmonicResult类中
Field aField = example.getDeclaredField("aValue" + i);
Field bField = example.getDeclaredField("bValue" + i);
Field cField = example.getDeclaredField("cValue" + i);
aField.setAccessible(true);
aField.set(adHarmonicResult,a.get(i - 2));
bField.setAccessible(true);
bField.set(adHarmonicResult,b.get(i - 2));
cField.setAccessible(true);
cField.set(adHarmonicResult,c.get(i - 2));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
adHarmonicResultList.add(adHarmonicResult);
}
}
detectionDataDealService.acceptAdNon(adHarmonicResultList,"1");
}
if(CollUtil.isNotEmpty(adNonHarmonicResultList)){
detectionDataDealService.acceptAdNon(adNonHarmonicResultList,"1");
}
if(CollUtil.isNotEmpty(adHarmonicResultList)){
detectionDataDealService.acceptAd(adHarmonicResultList,"1");
}
};
runnable.run();
executorPool.submit(runnable);
}

View File

@@ -18,6 +18,7 @@ import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -186,16 +187,24 @@ public class SocketSourceResponseService {
String s = param.getUserPageId() + DEV;
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
String comm = sourceIssue.getDevValueTypeList().get(0);
List<String> comm = sourceIssue.getDevValueTypeList();
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&"+sourceIssue.getType());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
if(sourceIssue.getType().equals(DicDataEnum.HP.getCode())||sourceIssue.getType().equals(DicDataEnum.F.getCode())){
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
}else if(DicDataEnum.VOLTAGE.getCode().equals(sourceIssue.getType())){
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_03.getValue());
}else {
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
}
List<String> moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream()).map(PreDetection.MonitorListDTO::getLineId).collect(Collectors.toList());
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
System.out.println("向装置下发的参数"+comm);
phaseSequenceParam.setMoniterIdList(moniterIdList);
phaseSequenceParam.setDataType(Arrays.asList(comm));
phaseSequenceParam.setDataType(comm);
phaseSequenceParam.setReadCount(2);
phaseSequenceParam.setIgnoreCount(10);
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));

View File

@@ -635,7 +635,7 @@ public class DetectionServiceImpl {
}
});
devMap.forEach((harm, harmDataList) -> {
PqErrSysDtls errSysDtl = errSysDtlMap.get(harm);
PqErrSysDtls errSysDtl = errSysDtlMap.get(num==1?harm+0.5:harm);
DetectionData data = new DetectionData();
data.setIsData(4);
data.setNum(harm);
@@ -708,7 +708,11 @@ public class DetectionServiceImpl {
.sorted().distinct().collect(Collectors.toList());
}
for (DevData devData : dev) {
DevData.SqlDataDTO fund = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst().get();
Optional<DevData.SqlDataDTO> first = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst();
DevData.SqlDataDTO fund = null;
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();
if (ObjectUtil.isNotNull(fund)) {
harmPut(TYPE_A, map, harmNum, harm, String.valueOf(fund.getList().getA()), num);
@@ -875,7 +879,7 @@ public class DetectionServiceImpl {
}
public Double multiply(Double devData, Double channelData, Integer type) {
if (ObjectUtil.isNotNull(type)) {
if (ObjectUtil.isNotNull(devData)) {
if (0 == type) {
return BigDecimal.valueOf(devData).multiply(BigDecimal.valueOf(channelData))
.setScale(4, RoundingMode.HALF_UP).doubleValue();

View File

@@ -79,7 +79,7 @@ public class SocketManager {
public static void addSourceList(List<SourceIssue> sList) {
sourceIssueList = sList;
System.out.println(sList);
// System.out.println(sList);
}
public static List<SourceIssue> getSourceList() {