|
@@ -0,0 +1,849 @@
|
|
|
|
|
+package com.zksy.cockpit.event;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.zksy.base.alarm.domain.AlarmData;
|
|
|
|
|
+import com.zksy.base.alarm.service.AlarmDataService;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
|
|
+import com.zksy.base.domain.MonitorPoint;
|
|
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
|
|
+import com.zksy.base.service.EquipmentTypeService;
|
|
|
|
|
+import com.zksy.base.service.MonitorPointService;
|
|
|
|
|
+import com.zksy.base.warning.domain.AlarmWarningRel;
|
|
|
|
|
+import com.zksy.base.warning.domain.EarlyWarning;
|
|
|
|
|
+import com.zksy.base.warning.domain.WarningType;
|
|
|
|
|
+import com.zksy.base.warning.mapper.AlarmWarningRelMapper;
|
|
|
|
|
+import com.zksy.base.warning.mapper.WarningTypeMapper;
|
|
|
|
|
+import com.zksy.base.warning.service.EarlyWarningService;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitTypeIndustry;
|
|
|
|
|
+import com.zksy.ops.domain.WorkOrder;
|
|
|
|
|
+import com.zksy.ops.service.WorkOrderService;
|
|
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.time.Clock;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.OffsetDateTime;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 预警处置与设备事件的真实只读适配器。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>五个事件端点共享同一组业务事实:预警、报警、设备类型、监测点和工单。
|
|
|
|
|
+ * 这里统一按设备编码解析类型,并通过 {@code alarm_data.work_order_id} 与
|
|
|
|
|
+ * {@code alarm_warning_rel} 回填事件工单关联,避免各端点各自猜测关联键。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>现有表没有可信的坐标校核字段,事件坐标即使来自记录也始终标记为未校核,
|
|
|
|
|
+ * 由契约层统一判定为不可渲染。成因、区域和预警实时值在当前模型中没有可靠来源,
|
|
|
|
|
+ * 保持 {@code null}。</p>
|
|
|
|
|
+ */
|
|
|
|
|
+@Component
|
|
|
|
|
+@Primary
|
|
|
|
|
+public class BusinessCockpitEventAdapter {
|
|
|
|
|
+
|
|
|
|
|
+ private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
+ private static final DateTimeFormatter TIMESTAMP = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
|
|
+ private static final List<String> CURRENT_WARNING_STATUSES = java.util.Arrays.asList(
|
|
|
|
|
+ "PENDING", "PROCESSING", "HANDLING", "RELEASED");
|
|
|
|
|
+
|
|
|
|
|
+ private final EquipmentBaseService equipmentBaseService;
|
|
|
|
|
+ private final EquipmentTypeService equipmentTypeService;
|
|
|
|
|
+ private final MonitorPointService monitorPointService;
|
|
|
|
|
+ private final EarlyWarningService earlyWarningService;
|
|
|
|
|
+ private final AlarmDataService alarmDataService;
|
|
|
|
|
+ private final WarningTypeMapper warningTypeMapper;
|
|
|
|
|
+ private final AlarmWarningRelMapper alarmWarningRelMapper;
|
|
|
|
|
+ private final WorkOrderService workOrderService;
|
|
|
|
|
+ private final Clock clock;
|
|
|
|
|
+
|
|
|
|
|
+ public BusinessCockpitEventAdapter(
|
|
|
|
|
+ EquipmentBaseService equipmentBaseService,
|
|
|
|
|
+ EquipmentTypeService equipmentTypeService,
|
|
|
|
|
+ MonitorPointService monitorPointService,
|
|
|
|
|
+ EarlyWarningService earlyWarningService,
|
|
|
|
|
+ AlarmDataService alarmDataService,
|
|
|
|
|
+ WarningTypeMapper warningTypeMapper,
|
|
|
|
|
+ AlarmWarningRelMapper alarmWarningRelMapper,
|
|
|
|
|
+ WorkOrderService workOrderService,
|
|
|
|
|
+ Clock clock) {
|
|
|
|
|
+ this.equipmentBaseService = equipmentBaseService;
|
|
|
|
|
+ this.equipmentTypeService = equipmentTypeService;
|
|
|
|
|
+ this.monitorPointService = monitorPointService;
|
|
|
|
|
+ this.earlyWarningService = earlyWarningService;
|
|
|
|
|
+ this.alarmDataService = alarmDataService;
|
|
|
|
|
+ this.warningTypeMapper = warningTypeMapper;
|
|
|
|
|
+ this.alarmWarningRelMapper = alarmWarningRelMapper;
|
|
|
|
|
+ this.workOrderService = workOrderService;
|
|
|
|
|
+ this.clock = clock;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitCurrentEventsSnapshot loadCurrentEvents() {
|
|
|
|
|
+ Facts facts = loadFacts(true);
|
|
|
|
|
+ return new CockpitCurrentEventsSnapshot(
|
|
|
|
|
+ businessTime(),
|
|
|
|
|
+ currentTypes(facts.typesById),
|
|
|
|
|
+ currentWarnings(facts),
|
|
|
|
|
+ currentAlarms(facts),
|
|
|
|
|
+ currentWorkOrders(facts));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitHistoryAnalysisSnapshot loadHistoryAnalysis() {
|
|
|
|
|
+ Facts facts = loadFacts(false);
|
|
|
|
|
+ return new CockpitHistoryAnalysisSnapshot(
|
|
|
|
|
+ businessTime(),
|
|
|
|
|
+ historyTypes(facts.typesById),
|
|
|
|
|
+ historyWarnings(facts),
|
|
|
|
|
+ historyAlarms(facts),
|
|
|
|
|
+ historyWorkOrders(facts));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitHandlingEfficiencySnapshot loadHandlingEfficiency() {
|
|
|
|
|
+ Facts facts = loadFacts(false);
|
|
|
|
|
+ return new CockpitHandlingEfficiencySnapshot(
|
|
|
|
|
+ businessTime(),
|
|
|
|
|
+ efficiencyTypes(facts.typesById),
|
|
|
|
|
+ efficiencyWarnings(facts),
|
|
|
|
|
+ efficiencyAlarms(facts),
|
|
|
|
|
+ efficiencyWorkOrders(facts));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitMultidimensionalAnalysisSnapshot loadMultidimensionalAnalysis() {
|
|
|
|
|
+ Facts facts = loadFacts(false);
|
|
|
|
|
+ return new CockpitMultidimensionalAnalysisSnapshot(
|
|
|
|
|
+ businessTime(),
|
|
|
|
|
+ multidimensionalTypes(facts.typesById),
|
|
|
|
|
+ multidimensionalWarnings(facts),
|
|
|
|
|
+ multidimensionalAlarms(facts));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitEventSnapshot loadCurrent(String deviceCode) {
|
|
|
|
|
+ Facts facts = loadFacts(true);
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(deviceCode));
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<WarningFact> warnings = facts.warnings.stream()
|
|
|
|
|
+ .filter(item -> same(deviceCode, item.warning.getDeviceCode()) && isCurrentWarning(item.warning))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ List<AlarmFact> alarms = facts.alarms.stream()
|
|
|
|
|
+ .filter(item -> same(deviceCode, item.alarm.getDeviceCode()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return eventSnapshot(facts, device, warnings, alarms, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitEventSnapshot loadHistory(
|
|
|
|
|
+ String deviceCode,
|
|
|
|
|
+ OffsetDateTime startTime,
|
|
|
|
|
+ OffsetDateTime endTime,
|
|
|
|
|
+ int page,
|
|
|
|
|
+ int pageSize) {
|
|
|
|
|
+ Facts facts = loadFacts(false);
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(deviceCode));
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<WarningFact> warnings = facts.warnings.stream()
|
|
|
|
|
+ .filter(item -> same(deviceCode, item.warning.getDeviceCode()))
|
|
|
|
|
+ .filter(item -> inWindow(item.eventTime(), startTime, endTime))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ List<AlarmFact> alarms = facts.alarms.stream()
|
|
|
|
|
+ .filter(item -> same(deviceCode, item.alarm.getDeviceCode()))
|
|
|
|
|
+ .filter(item -> inWindow(item.eventTime(), startTime, endTime))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<EventRef> ordered = new ArrayList<>();
|
|
|
|
|
+ warnings.forEach(item -> ordered.add(EventRef.warning(item)));
|
|
|
|
|
+ alarms.forEach(item -> ordered.add(EventRef.alarm(item)));
|
|
|
|
|
+ ordered.sort(EVENT_ORDERING);
|
|
|
|
|
+ int from = Math.min((page - 1) * pageSize, ordered.size());
|
|
|
|
|
+ int to = Math.min(from + pageSize, ordered.size());
|
|
|
|
|
+
|
|
|
|
|
+ List<WarningFact> pageWarnings = new ArrayList<>();
|
|
|
|
|
+ List<AlarmFact> pageAlarms = new ArrayList<>();
|
|
|
|
|
+ for (EventRef item : ordered.subList(from, to)) {
|
|
|
|
|
+ if (item.warning != null) {
|
|
|
|
|
+ pageWarnings.add(item.warning);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pageAlarms.add(item.alarm);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return eventSnapshot(facts, device, pageWarnings, pageAlarms, ordered.size());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEventSnapshot eventSnapshot(
|
|
|
|
|
+ Facts facts,
|
|
|
|
|
+ EquipmentBase device,
|
|
|
|
|
+ List<WarningFact> warnings,
|
|
|
|
|
+ List<AlarmFact> alarms,
|
|
|
|
|
+ Integer total) {
|
|
|
|
|
+ List<CockpitEventWarning> warningItems = warnings.stream()
|
|
|
|
|
+ .map(item -> toEventWarning(item, facts))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ List<CockpitEventAlarm> alarmItems = alarms.stream()
|
|
|
|
|
+ .map(item -> toEventAlarm(item, facts))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return new CockpitEventSnapshot(
|
|
|
|
|
+ device.getEquipmentCode().trim(),
|
|
|
|
|
+ typeCode(device, facts.typesById),
|
|
|
|
|
+ typeName(device, facts.typesById),
|
|
|
|
|
+ warningItems,
|
|
|
|
|
+ alarmItems,
|
|
|
|
|
+ eventRelations(facts, warnings, alarms),
|
|
|
|
|
+ total);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEventWarning toEventWarning(WarningFact item, Facts facts) {
|
|
|
|
|
+ EarlyWarning warning = item.warning;
|
|
|
|
|
+ PointFact point = facts.pointsByDevice.get(normalize(warning.getDeviceCode()));
|
|
|
|
|
+ return new CockpitEventWarning(
|
|
|
|
|
+ trimToNull(warning.getWarningNo()),
|
|
|
|
|
+ trimToNull(warning.getWarningName()),
|
|
|
|
|
+ trimToNull(warning.getWarningType()),
|
|
|
|
|
+ level(warning.getWarningLevel()),
|
|
|
|
|
+ CockpitEventLevelColor.resolve(level(warning.getWarningLevel())),
|
|
|
|
|
+ trimToNull(warning.getStatus()),
|
|
|
|
|
+ offsetTime(warning.getPublishTime()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ trimToNull(warning.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(warning.getDeviceName(), deviceName(warning.getDeviceCode(), facts)),
|
|
|
|
|
+ firstNonBlank(warning.getLocation(), point == null ? null : point.location));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEventAlarm toEventAlarm(AlarmFact item, Facts facts) {
|
|
|
|
|
+ AlarmData alarm = item.alarm;
|
|
|
|
|
+ PointFact point = facts.pointsByDevice.get(normalize(alarm.getDeviceCode()));
|
|
|
|
|
+ WarningType metadata = warningType(alarm, facts);
|
|
|
|
|
+ return new CockpitEventAlarm(
|
|
|
|
|
+ trimToNull(alarm.getId()),
|
|
|
|
|
+ trimToNull(alarm.getWarningCode()),
|
|
|
|
|
+ firstNonBlank(metadata == null ? null : metadata.getWarningName(), alarm.getWarningCode()),
|
|
|
|
|
+ trimToNull(alarm.getWarningType()),
|
|
|
|
|
+ alarm.getAlarmLevel(),
|
|
|
|
|
+ CockpitEventLevelColor.resolve(alarm.getAlarmLevel()),
|
|
|
|
|
+ alarmStatus(alarm.getAlarmStatus()),
|
|
|
|
|
+ offsetTime(alarm.getCreateTime()),
|
|
|
|
|
+ alarm.getActualValue(),
|
|
|
|
|
+ alarm.getMinValue(),
|
|
|
|
|
+ alarm.getMaxValue(),
|
|
|
|
|
+ metadata == null ? null : metadata.getWarningUnit(),
|
|
|
|
|
+ trimToNull(alarm.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(alarm.getDeviceName(), deviceName(alarm.getDeviceCode(), facts)),
|
|
|
|
|
+ point == null ? null : point.location);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitAlarmWarningRelation> eventRelations(
|
|
|
|
|
+ Facts facts,
|
|
|
|
|
+ List<WarningFact> warnings,
|
|
|
|
|
+ List<AlarmFact> alarms) {
|
|
|
|
|
+ Map<String, String> warningIds = new HashMap<>();
|
|
|
|
|
+ for (WarningFact item : warnings) {
|
|
|
|
|
+ if (item.warning.getWarningId() != null && item.warning.getWarningNo() != null) {
|
|
|
|
|
+ warningIds.put(item.warning.getWarningId(), item.warning.getWarningNo().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, String> alarmIds = new HashMap<>();
|
|
|
|
|
+ for (AlarmFact item : alarms) {
|
|
|
|
|
+ if (item.alarm.getId() != null) {
|
|
|
|
|
+ alarmIds.put(item.alarm.getId(), item.alarm.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<CockpitAlarmWarningRelation> result = new ArrayList<>();
|
|
|
|
|
+ for (AlarmWarningRel relation : facts.relations) {
|
|
|
|
|
+ String warningNo = warningIds.get(relation.getWarningId());
|
|
|
|
|
+ String alarmId = alarmIds.get(relation.getAlarmId());
|
|
|
|
|
+ if (warningNo == null || alarmId == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ result.add(new CockpitAlarmWarningRelation(
|
|
|
|
|
+ trimToNull(relation.getRelId()),
|
|
|
|
|
+ warningNo,
|
|
|
|
|
+ alarmId,
|
|
|
|
|
+ offsetTime(relation.getCreateTime())));
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitCurrentEventsSnapshot.SourceWarning> currentWarnings(Facts facts) {
|
|
|
|
|
+ return facts.warnings.stream()
|
|
|
|
|
+ .filter(item -> isCurrentWarning(item.warning))
|
|
|
|
|
+ .map(item -> currentWarning(item, facts))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitCurrentEventsSnapshot.SourceAlarm> currentAlarms(Facts facts) {
|
|
|
|
|
+ return facts.alarms.stream()
|
|
|
|
|
+ .map(item -> currentAlarm(item, facts))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitCurrentEventsSnapshot.SourceWarning currentWarning(WarningFact item, Facts facts) {
|
|
|
|
|
+ EarlyWarning warning = item.warning;
|
|
|
|
|
+ PointFact point = facts.pointsByDevice.get(normalize(warning.getDeviceCode()));
|
|
|
|
|
+ return new CockpitCurrentEventsSnapshot.SourceWarning(
|
|
|
|
|
+ trimToNull(warning.getWarningNo()),
|
|
|
|
|
+ trimToNull(warning.getWarningName()),
|
|
|
|
|
+ trimToNull(warning.getWarningType()),
|
|
|
|
|
+ level(warning.getWarningLevel()),
|
|
|
|
|
+ trimToNull(warning.getStatus()),
|
|
|
|
|
+ offsetTime(warning.getPublishTime()),
|
|
|
|
|
+ offsetTime(warning.getUpdateTime()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ trimToNull(warning.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(warning.getDeviceName(), deviceName(warning.getDeviceCode(), facts)),
|
|
|
|
|
+ point == null ? null : point.code,
|
|
|
|
|
+ point == null ? null : point.name,
|
|
|
|
|
+ firstNonBlank(warning.getLocation(), point == null ? null : point.location),
|
|
|
|
|
+ typeCode(warning.getDeviceCode(), facts),
|
|
|
|
|
+ warning.getLongitude(),
|
|
|
|
|
+ warning.getLatitude(),
|
|
|
|
|
+ false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitCurrentEventsSnapshot.SourceAlarm currentAlarm(AlarmFact item, Facts facts) {
|
|
|
|
|
+ AlarmData alarm = item.alarm;
|
|
|
|
|
+ PointFact point = facts.pointsByDevice.get(normalize(alarm.getDeviceCode()));
|
|
|
|
|
+ WarningType metadata = warningType(alarm, facts);
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(alarm.getDeviceCode()));
|
|
|
|
|
+ return new CockpitCurrentEventsSnapshot.SourceAlarm(
|
|
|
|
|
+ trimToNull(alarm.getId()),
|
|
|
|
|
+ firstNonBlank(metadata == null ? null : metadata.getWarningName(), alarm.getWarningCode()),
|
|
|
|
|
+ trimToNull(alarm.getWarningType()),
|
|
|
|
|
+ alarm.getAlarmLevel(),
|
|
|
|
|
+ alarmStatus(alarm.getAlarmStatus()),
|
|
|
|
|
+ offsetTime(alarm.getCreateTime()),
|
|
|
|
|
+ offsetTime(alarm.getUpdateTime()),
|
|
|
|
|
+ alarm.getActualValue(),
|
|
|
|
|
+ metadata == null ? null : metadata.getWarningUnit(),
|
|
|
|
|
+ trimToNull(alarm.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(alarm.getDeviceName(), device == null ? null : device.getEquipmentName()),
|
|
|
|
|
+ point == null ? null : point.code,
|
|
|
|
|
+ point == null ? null : point.name,
|
|
|
|
|
+ point == null ? (device == null ? null : device.getEquipmentLocation()) : point.location,
|
|
|
|
|
+ typeCode(alarm.getDeviceCode(), facts),
|
|
|
|
|
+ coordinate(alarm.getLongitude(), device == null ? null : device.getLongitude()),
|
|
|
|
|
+ coordinate(alarm.getLatitude(), device == null ? null : device.getLatitude()),
|
|
|
|
|
+ false,
|
|
|
|
|
+ alarm.getMinValue(),
|
|
|
|
|
+ alarm.getMaxValue());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitCurrentEventsSnapshot.SourceWorkOrderLink> currentWorkOrders(Facts facts) {
|
|
|
|
|
+ List<CockpitCurrentEventsSnapshot.SourceWorkOrderLink> result = new ArrayList<>();
|
|
|
|
|
+ for (WorkOrderFact item : facts.workOrders) {
|
|
|
|
|
+ if (!isOpenWorkOrder(item.order.getOrderStatus())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ addCurrentWorkOrderLinks(result, item);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addCurrentWorkOrderLinks(
|
|
|
|
|
+ List<CockpitCurrentEventsSnapshot.SourceWorkOrderLink> result,
|
|
|
|
|
+ WorkOrderFact item) {
|
|
|
|
|
+ if (item.eventNos.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (String eventNo : item.eventNos) {
|
|
|
|
|
+ WorkOrder order = item.order;
|
|
|
|
|
+ result.add(new CockpitCurrentEventsSnapshot.SourceWorkOrderLink(
|
|
|
|
|
+ eventNo,
|
|
|
|
|
+ order.getOrderNo(),
|
|
|
|
|
+ order.getOrderLevel(),
|
|
|
|
|
+ order.getOrderDesc(),
|
|
|
|
|
+ order.getOrderStatus(),
|
|
|
|
|
+ format(order.getCreateTime()),
|
|
|
|
|
+ format(order.getUpdateTime()),
|
|
|
|
|
+ format(order.getPlanFinishTime()),
|
|
|
|
|
+ format(order.getRealFinishTime())));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHistoryAnalysisSnapshot.SourceWarning> historyWarnings(Facts facts) {
|
|
|
|
|
+ return facts.warnings.stream()
|
|
|
|
|
+ .map(item -> new CockpitHistoryAnalysisSnapshot.SourceWarning(
|
|
|
|
|
+ trimToNull(item.warning.getWarningNo()),
|
|
|
|
|
+ level(item.warning.getWarningLevel()),
|
|
|
|
|
+ offsetTime(item.warning.getPublishTime()),
|
|
|
|
|
+ typeCode(item.warning.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.warning.getDeviceCode())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHistoryAnalysisSnapshot.SourceAlarm> historyAlarms(Facts facts) {
|
|
|
|
|
+ return facts.alarms.stream()
|
|
|
|
|
+ .map(item -> new CockpitHistoryAnalysisSnapshot.SourceAlarm(
|
|
|
|
|
+ trimToNull(item.alarm.getId()),
|
|
|
|
|
+ item.alarm.getAlarmLevel(),
|
|
|
|
|
+ offsetTime(item.alarm.getCreateTime()),
|
|
|
|
|
+ typeCode(item.alarm.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.alarm.getDeviceCode())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHistoryAnalysisSnapshot.SourceWorkOrderLink> historyWorkOrders(Facts facts) {
|
|
|
|
|
+ List<CockpitHistoryAnalysisSnapshot.SourceWorkOrderLink> result = new ArrayList<>();
|
|
|
|
|
+ for (WorkOrderFact item : facts.workOrders) {
|
|
|
|
|
+ for (String eventNo : item.eventNos) {
|
|
|
|
|
+ result.add(new CockpitHistoryAnalysisSnapshot.SourceWorkOrderLink(
|
|
|
|
|
+ eventNo, item.order.getOrderStatus()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHandlingEfficiencySnapshot.SourceWarning> efficiencyWarnings(Facts facts) {
|
|
|
|
|
+ return facts.warnings.stream()
|
|
|
|
|
+ .map(item -> new CockpitHandlingEfficiencySnapshot.SourceWarning(
|
|
|
|
|
+ trimToNull(item.warning.getWarningNo()),
|
|
|
|
|
+ level(item.warning.getWarningLevel()),
|
|
|
|
|
+ offsetTime(item.warning.getPublishTime()),
|
|
|
|
|
+ typeCode(item.warning.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.warning.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(item.warning.getDeviceName(), deviceName(item.warning.getDeviceCode(), facts))))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHandlingEfficiencySnapshot.SourceAlarm> efficiencyAlarms(Facts facts) {
|
|
|
|
|
+ return facts.alarms.stream()
|
|
|
|
|
+ .map(item -> new CockpitHandlingEfficiencySnapshot.SourceAlarm(
|
|
|
|
|
+ trimToNull(item.alarm.getId()),
|
|
|
|
|
+ item.alarm.getAlarmLevel(),
|
|
|
|
|
+ offsetTime(item.alarm.getCreateTime()),
|
|
|
|
|
+ typeCode(item.alarm.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.alarm.getDeviceCode()),
|
|
|
|
|
+ firstNonBlank(item.alarm.getDeviceName(), deviceName(item.alarm.getDeviceCode(), facts))))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHandlingEfficiencySnapshot.SourceWorkOrderLink> efficiencyWorkOrders(Facts facts) {
|
|
|
|
|
+ List<CockpitHandlingEfficiencySnapshot.SourceWorkOrderLink> result = new ArrayList<>();
|
|
|
|
|
+ for (WorkOrderFact item : facts.workOrders) {
|
|
|
|
|
+ for (String eventNo : item.eventNos) {
|
|
|
|
|
+ result.add(new CockpitHandlingEfficiencySnapshot.SourceWorkOrderLink(
|
|
|
|
|
+ eventNo,
|
|
|
|
|
+ item.order.getOrderStatus(),
|
|
|
|
|
+ format(item.order.getCreateTime()),
|
|
|
|
|
+ format(item.order.getRealFinishTime())));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitMultidimensionalAnalysisSnapshot.SourceWarning> multidimensionalWarnings(Facts facts) {
|
|
|
|
|
+ return facts.warnings.stream()
|
|
|
|
|
+ .map(item -> new CockpitMultidimensionalAnalysisSnapshot.SourceWarning(
|
|
|
|
|
+ trimToNull(item.warning.getWarningNo()),
|
|
|
|
|
+ trimToNull(item.warning.getWarningType()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ level(item.warning.getWarningLevel()),
|
|
|
|
|
+ offsetTime(item.warning.getPublishTime()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ typeCode(item.warning.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.warning.getDeviceCode())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitMultidimensionalAnalysisSnapshot.SourceAlarm> multidimensionalAlarms(Facts facts) {
|
|
|
|
|
+ return facts.alarms.stream()
|
|
|
|
|
+ .map(item -> new CockpitMultidimensionalAnalysisSnapshot.SourceAlarm(
|
|
|
|
|
+ trimToNull(item.alarm.getId()),
|
|
|
|
|
+ trimToNull(item.alarm.getWarningType()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ item.alarm.getAlarmLevel(),
|
|
|
|
|
+ offsetTime(item.alarm.getCreateTime()),
|
|
|
|
|
+ null,
|
|
|
|
|
+ typeCode(item.alarm.getDeviceCode(), facts),
|
|
|
|
|
+ trimToNull(item.alarm.getDeviceCode())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitCurrentEventsSnapshot.SourceType> currentTypes(Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ return types.values().stream()
|
|
|
|
|
+ .map(type -> new CockpitCurrentEventsSnapshot.SourceType(
|
|
|
|
|
+ typeCode(type), type.getTypeName(),
|
|
|
|
|
+ CockpitTypeIndustry.industryOf(type, types), "SMART_DEVICE"))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHistoryAnalysisSnapshot.SourceType> historyTypes(Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ return types.values().stream()
|
|
|
|
|
+ .map(type -> new CockpitHistoryAnalysisSnapshot.SourceType(
|
|
|
|
|
+ typeCode(type), type.getTypeName(),
|
|
|
|
|
+ CockpitTypeIndustry.industryOf(type, types), "SMART_DEVICE"))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitHandlingEfficiencySnapshot.SourceType> efficiencyTypes(Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ return types.values().stream()
|
|
|
|
|
+ .map(type -> new CockpitHandlingEfficiencySnapshot.SourceType(
|
|
|
|
|
+ typeCode(type), type.getTypeName(),
|
|
|
|
|
+ CockpitTypeIndustry.industryOf(type, types), "SMART_DEVICE"))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CockpitMultidimensionalAnalysisSnapshot.SourceType> multidimensionalTypes(Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ return types.values().stream()
|
|
|
|
|
+ .map(type -> new CockpitMultidimensionalAnalysisSnapshot.SourceType(
|
|
|
|
|
+ typeCode(type), type.getTypeName(),
|
|
|
|
|
+ CockpitTypeIndustry.industryOf(type, types), "SMART_DEVICE"))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Facts loadFacts(boolean current) {
|
|
|
|
|
+ Map<Integer, EquipmentType> types = typeIndex();
|
|
|
|
|
+ Map<String, EquipmentBase> devices = deviceIndex();
|
|
|
|
|
+ Map<String, PointFact> points = pointIndex();
|
|
|
|
|
+ Map<String, WarningType> warningTypes = warningTypeIndex();
|
|
|
|
|
+ List<EarlyWarning> warnings = safeList(earlyWarningService.list());
|
|
|
|
|
+ List<AlarmData> alarms = safeList(alarmDataService.list());
|
|
|
|
|
+ List<AlarmWarningRel> relations = safeList(alarmWarningRelMapper.selectList(new QueryWrapper<AlarmWarningRel>()));
|
|
|
|
|
+ List<WorkOrder> orders = safeList(workOrderService.list());
|
|
|
|
|
+
|
|
|
|
|
+ List<WarningFact> warningFacts = warnings.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(item -> !current || isCurrentWarning(item))
|
|
|
|
|
+ .filter(item -> !isBlank(item.getWarningNo()))
|
|
|
|
|
+ .map(item -> new WarningFact(item))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ List<AlarmFact> alarmFacts = alarms.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(item -> !isBlank(item.getId()))
|
|
|
|
|
+ .map(item -> new AlarmFact(item))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, List<String>> eventNosByOrderId = new HashMap<>();
|
|
|
|
|
+ Map<String, String> warningNoById = warnings.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(item -> !isBlank(item.getWarningId()) && !isBlank(item.getWarningNo()))
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ EarlyWarning::getWarningId,
|
|
|
|
|
+ item -> item.getWarningNo().trim(),
|
|
|
|
|
+ (left, right) -> left));
|
|
|
|
|
+ Map<String, List<String>> warningNosByAlarmId = new HashMap<>();
|
|
|
|
|
+ for (AlarmWarningRel relation : relations) {
|
|
|
|
|
+ if (relation == null || isBlank(relation.getAlarmId())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String warningNo = warningNoById.get(relation.getWarningId());
|
|
|
|
|
+ if (warningNo != null) {
|
|
|
|
|
+ warningNosByAlarmId.computeIfAbsent(relation.getAlarmId(), key -> new ArrayList<>()).add(warningNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (AlarmData alarm : alarms) {
|
|
|
|
|
+ if (alarm == null || alarm.getWorkOrderId() == null || isBlank(alarm.getId())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> eventNos = eventNosByOrderId.computeIfAbsent(alarm.getWorkOrderId(), key -> new ArrayList<>());
|
|
|
|
|
+ eventNos.add(alarm.getId().trim());
|
|
|
|
|
+ eventNos.addAll(warningNosByAlarmId.getOrDefault(alarm.getId(), Collections.emptyList()));
|
|
|
|
|
+ }
|
|
|
|
|
+ List<WorkOrderFact> workOrderFacts = orders.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .map(order -> new WorkOrderFact(order, eventNosByOrderId.getOrDefault(
|
|
|
|
|
+ order.getOrderId(), Collections.emptyList())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return new Facts(types, devices, points, warningTypes, relations, warningFacts, alarmFacts, workOrderFacts);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<Integer, EquipmentType> typeIndex() {
|
|
|
|
|
+ Map<Integer, EquipmentType> result = new LinkedHashMap<>();
|
|
|
|
|
+ for (EquipmentType type : safeList(equipmentTypeService.list())) {
|
|
|
|
|
+ if (type != null && type.getId() != null) {
|
|
|
|
|
+ result.put(type.getId(), type);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, EquipmentBase> deviceIndex() {
|
|
|
|
|
+ Map<String, EquipmentBase> result = new LinkedHashMap<>();
|
|
|
|
|
+ for (EquipmentBase device : safeList(equipmentBaseService.list())) {
|
|
|
|
|
+ if (device != null && !isBlank(device.getEquipmentCode())) {
|
|
|
|
|
+ result.put(device.getEquipmentCode().trim(), device);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, PointFact> pointIndex() {
|
|
|
|
|
+ Map<String, PointFact> result = new LinkedHashMap<>();
|
|
|
|
|
+ for (MonitorPoint point : safeList(monitorPointService.list())) {
|
|
|
|
|
+ if (point == null || isBlank(point.getPointId())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<EquipmentBase> devices = safeList(equipmentBaseService.getEquipmentByPoint(point.getPointId()));
|
|
|
|
|
+ for (EquipmentBase device : devices) {
|
|
|
|
|
+ if (device != null && !isBlank(device.getEquipmentCode())) {
|
|
|
|
|
+ result.putIfAbsent(device.getEquipmentCode().trim(), new PointFact(
|
|
|
|
|
+ trimToNull(point.getPointCode()),
|
|
|
|
|
+ trimToNull(point.getPointName()),
|
|
|
|
|
+ trimToNull(point.getLocation())));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, WarningType> warningTypeIndex() {
|
|
|
|
|
+ Map<String, WarningType> result = new LinkedHashMap<>();
|
|
|
|
|
+ for (WarningType type : safeList(warningTypeMapper.selectList(new QueryWrapper<WarningType>()))) {
|
|
|
|
|
+ if (type != null && type.getEquipmentTypeId() != null && !isBlank(type.getWarningCode())) {
|
|
|
|
|
+ result.put(type.getEquipmentTypeId() + "\u0000" + type.getWarningCode().trim(), type);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private WarningType warningType(AlarmData alarm, Facts facts) {
|
|
|
|
|
+ if (alarm == null || isBlank(alarm.getWarningCode())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(alarm.getDeviceCode()));
|
|
|
|
|
+ if (device == null || device.getEquipmentTypeId() == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return facts.warningTypes.get(device.getEquipmentTypeId() + "\u0000" + alarm.getWarningCode().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String deviceName(String deviceCode, Facts facts) {
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(deviceCode));
|
|
|
|
|
+ return device == null ? null : device.getEquipmentName();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String typeCode(String deviceCode, Facts facts) {
|
|
|
|
|
+ EquipmentBase device = facts.devicesByCode.get(normalize(deviceCode));
|
|
|
|
|
+ return device == null ? null : typeCode(device, facts.typesById);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String typeName(EquipmentBase device, Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ EquipmentType type = device == null || device.getEquipmentTypeId() == null
|
|
|
|
|
+ ? null : types.get(device.getEquipmentTypeId());
|
|
|
|
|
+ return type == null ? null : type.getTypeName();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String typeCode(EquipmentBase device, Map<Integer, EquipmentType> types) {
|
|
|
|
|
+ return device == null || device.getEquipmentTypeId() == null
|
|
|
|
|
+ || !types.containsKey(device.getEquipmentTypeId())
|
|
|
|
|
+ ? null : String.valueOf(device.getEquipmentTypeId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String typeCode(EquipmentType type) {
|
|
|
|
|
+ return type == null || type.getId() == null ? null : String.valueOf(type.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Integer level(String value) {
|
|
|
|
|
+ if (isBlank(value)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ int resolved = Integer.parseInt(value.trim());
|
|
|
|
|
+ return resolved >= 1 && resolved <= 4 ? resolved : null;
|
|
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String alarmStatus(Integer status) {
|
|
|
|
|
+ if (Integer.valueOf(0).equals(status)) {
|
|
|
|
|
+ return "UNHANDLED";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Integer.valueOf(1).equals(status)) {
|
|
|
|
|
+ return "HANDLED";
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isCurrentWarning(EarlyWarning warning) {
|
|
|
|
|
+ return warning != null && isCurrentStatus(warning.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isCurrentStatus(String status) {
|
|
|
|
|
+ return status != null && CURRENT_WARNING_STATUSES.contains(status.trim().toUpperCase());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isOpenWorkOrder(Integer status) {
|
|
|
|
|
+ return status != null && ((status >= 0 && status <= 4) || status == 6);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean inWindow(String eventTime, OffsetDateTime start, OffsetDateTime end) {
|
|
|
|
|
+ if (isBlank(eventTime)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ OffsetDateTime parsed = OffsetDateTime.parse(eventTime);
|
|
|
|
|
+ return !parsed.isBefore(start) && !parsed.isAfter(end);
|
|
|
|
|
+ } catch (DateTimeParseException ignored) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static final Comparator<EventRef> EVENT_ORDERING = Comparator
|
|
|
|
|
+ .comparing(EventRef::eventTime, Comparator.nullsLast(Comparator.reverseOrder()))
|
|
|
|
|
+ .thenComparing(EventRef::eventNo, Comparator.nullsLast(String::compareTo));
|
|
|
|
|
+
|
|
|
|
|
+ private static String offsetTime(LocalDateTime value) {
|
|
|
|
|
+ return value == null ? null : TIMESTAMP.format(value.atZone(BUSINESS_ZONE).toOffsetDateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String format(Date value) {
|
|
|
|
|
+ return value == null ? null : TIMESTAMP.format(value.toInstant().atZone(BUSINESS_ZONE));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String businessTime() {
|
|
|
|
|
+ return TIMESTAMP.format(clock.instant().atZone(BUSINESS_ZONE));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static BigDecimal coordinate(String eventValue, BigDecimal fallback) {
|
|
|
|
|
+ if (isBlank(eventValue)) {
|
|
|
|
|
+ return fallback;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return new BigDecimal(eventValue.trim());
|
|
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
|
|
+ return fallback;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String normalize(String value) {
|
|
|
|
|
+ return isBlank(value) ? null : value.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean same(String left, String right) {
|
|
|
|
|
+ return Objects.equals(normalize(left), normalize(right));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String trimToNull(String value) {
|
|
|
|
|
+ return isBlank(value) ? null : value.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String firstNonBlank(String first, String second) {
|
|
|
|
|
+ return isBlank(first) ? trimToNull(second) : first.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isBlank(String value) {
|
|
|
|
|
+ return value == null || value.trim().isEmpty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static <T> List<T> safeList(List<T> value) {
|
|
|
|
|
+ return value == null ? Collections.emptyList() : value.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class PointFact {
|
|
|
|
|
+ private final String code;
|
|
|
|
|
+ private final String name;
|
|
|
|
|
+ private final String location;
|
|
|
|
|
+
|
|
|
|
|
+ private PointFact(String code, String name, String location) {
|
|
|
|
|
+ this.code = code;
|
|
|
|
|
+ this.name = name;
|
|
|
|
|
+ this.location = location;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class WarningFact {
|
|
|
|
|
+ private final EarlyWarning warning;
|
|
|
|
|
+
|
|
|
|
|
+ private WarningFact(EarlyWarning warning) {
|
|
|
|
|
+ this.warning = warning;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String eventTime() {
|
|
|
|
|
+ return offsetTime(warning.getPublishTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class AlarmFact {
|
|
|
|
|
+ private final AlarmData alarm;
|
|
|
|
|
+
|
|
|
|
|
+ private AlarmFact(AlarmData alarm) {
|
|
|
|
|
+ this.alarm = alarm;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String eventTime() {
|
|
|
|
|
+ return offsetTime(alarm.getCreateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class EventRef {
|
|
|
|
|
+ private final WarningFact warning;
|
|
|
|
|
+ private final AlarmFact alarm;
|
|
|
|
|
+
|
|
|
|
|
+ private EventRef(WarningFact warning, AlarmFact alarm) {
|
|
|
|
|
+ this.warning = warning;
|
|
|
|
|
+ this.alarm = alarm;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static EventRef warning(WarningFact item) {
|
|
|
|
|
+ return new EventRef(item, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static EventRef alarm(AlarmFact item) {
|
|
|
|
|
+ return new EventRef(null, item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String eventTime() {
|
|
|
|
|
+ return warning == null ? alarm.eventTime() : warning.eventTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String eventNo() {
|
|
|
|
|
+ return warning == null ? alarm.alarm.getId() : warning.warning.getWarningNo();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class WorkOrderFact {
|
|
|
|
|
+ private final WorkOrder order;
|
|
|
|
|
+ private final List<String> eventNos;
|
|
|
|
|
+
|
|
|
|
|
+ private WorkOrderFact(WorkOrder order, List<String> eventNos) {
|
|
|
|
|
+ this.order = order;
|
|
|
|
|
+ this.eventNos = new ArrayList<>(eventNos);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class Facts {
|
|
|
|
|
+ private final Map<Integer, EquipmentType> typesById;
|
|
|
|
|
+ private final Map<String, EquipmentBase> devicesByCode;
|
|
|
|
|
+ private final Map<String, PointFact> pointsByDevice;
|
|
|
|
|
+ private final Map<String, WarningType> warningTypes;
|
|
|
|
|
+ private final List<AlarmWarningRel> relations;
|
|
|
|
|
+ private final List<WarningFact> warnings;
|
|
|
|
|
+ private final List<AlarmFact> alarms;
|
|
|
|
|
+ private final List<WorkOrderFact> workOrders;
|
|
|
|
|
+
|
|
|
|
|
+ private Facts(
|
|
|
|
|
+ Map<Integer, EquipmentType> typesById,
|
|
|
|
|
+ Map<String, EquipmentBase> devicesByCode,
|
|
|
|
|
+ Map<String, PointFact> pointsByDevice,
|
|
|
|
|
+ Map<String, WarningType> warningTypes,
|
|
|
|
|
+ List<AlarmWarningRel> relations,
|
|
|
|
|
+ List<WarningFact> warnings,
|
|
|
|
|
+ List<AlarmFact> alarms,
|
|
|
|
|
+ List<WorkOrderFact> workOrders) {
|
|
|
|
|
+ this.typesById = typesById;
|
|
|
|
|
+ this.devicesByCode = devicesByCode;
|
|
|
|
|
+ this.pointsByDevice = pointsByDevice;
|
|
|
|
|
+ this.warningTypes = warningTypes;
|
|
|
|
|
+ this.relations = relations;
|
|
|
|
|
+ this.warnings = warnings;
|
|
|
|
|
+ this.alarms = alarms;
|
|
|
|
|
+ this.workOrders = workOrders;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|