二级代码修复
This commit is contained in:
@@ -15,9 +15,12 @@ public class SegValue implements Serializable {
|
|||||||
private BigDecimal avg;
|
private BigDecimal avg;
|
||||||
private BigDecimal std;
|
private BigDecimal std;
|
||||||
private int cnt;
|
private int cnt;
|
||||||
private BigDecimal sum;
|
private BigDecimal sum = BigDecimal.ZERO;
|
||||||
|
|
||||||
public void add(BigDecimal value) {
|
public void add(BigDecimal value) {
|
||||||
|
if (value == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.sum = this.sum.add(value);
|
this.sum = this.sum.add(value);
|
||||||
this.cnt++;
|
this.cnt++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ public class PdoExCoilServiceImpl implements PdoExCoilService {
|
|||||||
separateFlag = true;
|
separateFlag = true;
|
||||||
exitMatId = exitMatId + "-" + subNum;
|
exitMatId = exitMatId + "-" + subNum;
|
||||||
}
|
}
|
||||||
log.info("这个plan里面都有啥:id{}planid{},",plan.getId(),plan.getPlanid());
|
|
||||||
ExitCoilInfoDTO exitCoil = ExitCoilInfoDTO.builder()
|
ExitCoilInfoDTO exitCoil = ExitCoilInfoDTO.builder()
|
||||||
.planId(plan.getPlanid())
|
.planId(plan.getPlanid())
|
||||||
.entryMatId(entryMatId)
|
.entryMatId(entryMatId)
|
||||||
|
|||||||
@@ -35,10 +35,9 @@ public class SegmentService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 将动态的 Map 数据转换为 JSON 字符串
|
// 1. 将动态的 Map 数据转换为 JSON 字符串(存平均值)
|
||||||
Map<String, BigDecimal> totalValuesAvg = new HashMap<>();
|
Map<String, BigDecimal> totalValuesAvg = new HashMap<>();
|
||||||
segment.getTotalValues().forEach((key, segValue) -> {
|
segment.getTotalValues().forEach((key, segValue) -> {
|
||||||
// 这里将 key 拼接上 "_avg" 以示区分,如果需要也可以不加
|
|
||||||
totalValuesAvg.put(key + "_avg", segValue.getAverage());
|
totalValuesAvg.put(key + "_avg", segValue.getAverage());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ import org.springframework.scheduling.annotation.Async;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import static com.fizz.business.constants.enums.DeviceEnum.FUR4;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -165,6 +168,14 @@ public class SegmentTrackerService {
|
|||||||
segment.setHeadPos(segment.getHeadPos().add(weldDev));
|
segment.setHeadPos(segment.getHeadPos().add(weldDev));
|
||||||
segment.setTailPos(segment.getTailPos().add(weldDev));
|
segment.setTailPos(segment.getTailPos().add(weldDev));
|
||||||
|
|
||||||
|
// 根据 SourceType 读取对应测量对象数据,写入段的 totalValues(Map 形式)
|
||||||
|
EnumMap<DeviceEnum.SourceType, Object> sourceMessageMap = new EnumMap<>(DeviceEnum.SourceType.class);
|
||||||
|
sourceMessageMap.put(DeviceEnum.SourceType.ENTRY, entry);
|
||||||
|
sourceMessageMap.put(DeviceEnum.SourceType.FURNACE, furnace);
|
||||||
|
sourceMessageMap.put(DeviceEnum.SourceType.COAT, coat);
|
||||||
|
sourceMessageMap.put(DeviceEnum.SourceType.EXIT, exit);
|
||||||
|
sourceMessageMap.values().forEach(message -> accumulateMessageFields(segment, message));
|
||||||
|
|
||||||
// 遍历所有设备,累积段在设备区域内的数据
|
// 遍历所有设备,累积段在设备区域内的数据
|
||||||
for (DeviceEnum device : DeviceEnum.values()) {
|
for (DeviceEnum device : DeviceEnum.values()) {
|
||||||
double currentDevicePos = stripPositionService.calculate(device, celLength, cxlLength);
|
double currentDevicePos = stripPositionService.calculate(device, celLength, cxlLength);
|
||||||
@@ -332,6 +343,27 @@ public class SegmentTrackerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将测量对象中的数值字段累积到段的 totalValues 中
|
||||||
|
*/
|
||||||
|
private void accumulateMessageFields(SegmentDTO segment, Object message) {
|
||||||
|
if (segment == null || message == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Field field : message.getClass().getDeclaredFields()) {
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object val = field.get(message);
|
||||||
|
if (val instanceof BigDecimal) {
|
||||||
|
setSegValue(segment.getTotalValues(), field.getName(), (BigDecimal) val);
|
||||||
|
} else if (val instanceof Number) {
|
||||||
|
setSegValue(segment.getTotalValues(), field.getName(), BigDecimal.valueOf(((Number) val).doubleValue()));
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 本地缓存,每个 coilId 对应已到达设备
|
// 本地缓存,每个 coilId 对应已到达设备
|
||||||
public void trackCoilHeadPosition(String coilId, BigDecimal headPos,
|
public void trackCoilHeadPosition(String coilId, BigDecimal headPos,
|
||||||
AppMeasureEntryMessage entry, AppMeasureExitMessage exit) {
|
AppMeasureEntryMessage entry, AppMeasureExitMessage exit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user