|
@@ -11,6 +11,8 @@ import com.zksy.base.service.MonitorPointService;
|
|
|
import com.zksy.cockpit.foundation.CockpitCreatedAt;
|
|
import com.zksy.cockpit.foundation.CockpitCreatedAt;
|
|
|
import com.zksy.cockpit.foundation.CockpitDistrict;
|
|
import com.zksy.cockpit.foundation.CockpitDistrict;
|
|
|
import com.zksy.cockpit.foundation.CockpitTypeIndustry;
|
|
import com.zksy.cockpit.foundation.CockpitTypeIndustry;
|
|
|
|
|
+import com.zksy.cockpit.point.BusinessCockpitDeviceFactResolver;
|
|
|
|
|
+import com.zksy.cockpit.point.CockpitMonitoringPointDeviceSnapshot;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
@@ -55,6 +57,8 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
|
|
|
private final EquipmentBaseService equipmentBaseService;
|
|
private final EquipmentBaseService equipmentBaseService;
|
|
|
private final EquipmentStatusService equipmentStatusService;
|
|
private final EquipmentStatusService equipmentStatusService;
|
|
|
private final EquipmentTypeService equipmentTypeService;
|
|
private final EquipmentTypeService equipmentTypeService;
|
|
|
|
|
+ /** 票 133:设备状态标签(报警/预警/工单)的唯一事实源,避免各适配器各写一份四表查询。 */
|
|
|
|
|
+ private final BusinessCockpitDeviceFactResolver deviceFacts;
|
|
|
private final Clock clock;
|
|
private final Clock clock;
|
|
|
|
|
|
|
|
public BusinessCockpitMonitoringOverviewAdapter(
|
|
public BusinessCockpitMonitoringOverviewAdapter(
|
|
@@ -62,11 +66,13 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
|
|
|
EquipmentBaseService equipmentBaseService,
|
|
EquipmentBaseService equipmentBaseService,
|
|
|
EquipmentStatusService equipmentStatusService,
|
|
EquipmentStatusService equipmentStatusService,
|
|
|
EquipmentTypeService equipmentTypeService,
|
|
EquipmentTypeService equipmentTypeService,
|
|
|
|
|
+ BusinessCockpitDeviceFactResolver deviceFacts,
|
|
|
Clock clock) {
|
|
Clock clock) {
|
|
|
this.monitorPointService = monitorPointService;
|
|
this.monitorPointService = monitorPointService;
|
|
|
this.equipmentBaseService = equipmentBaseService;
|
|
this.equipmentBaseService = equipmentBaseService;
|
|
|
this.equipmentStatusService = equipmentStatusService;
|
|
this.equipmentStatusService = equipmentStatusService;
|
|
|
this.equipmentTypeService = equipmentTypeService;
|
|
this.equipmentTypeService = equipmentTypeService;
|
|
|
|
|
+ this.deviceFacts = deviceFacts;
|
|
|
this.clock = clock;
|
|
this.clock = clock;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -138,42 +144,8 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices = new ArrayList<>();
|
|
|
|
|
- for (EquipmentBase device : ledger) {
|
|
|
|
|
- if (device == null || isBlank(device.getEquipmentCode())) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- String deviceCode = device.getEquipmentCode().trim();
|
|
|
|
|
- EquipmentType type = device.getEquipmentTypeId() == null
|
|
|
|
|
- ? null
|
|
|
|
|
- : types.get(device.getEquipmentTypeId());
|
|
|
|
|
-
|
|
|
|
|
- EquipmentStatus status = statusBatchReady
|
|
|
|
|
- ? statusById.get(device.getEquipmentId())
|
|
|
|
|
- : null;
|
|
|
|
|
- if (!statusBatchReady) {
|
|
|
|
|
- try {
|
|
|
|
|
- status = equipmentStatusService.getByDeviceCode(deviceCode);
|
|
|
|
|
- } catch (Exception ignored) {
|
|
|
|
|
- // 状态缺失按 UNKNOWN 上报,不阻断概览
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- devices.add(new CockpitMonitoringOverviewSnapshot.SourceDevice(
|
|
|
|
|
- deviceCode,
|
|
|
|
|
- // 执行票 62:设备台账要显示名称(缺名如实为 null,不拿编码冒充)。
|
|
|
|
|
- isBlank(device.getEquipmentName()) ? null : device.getEquipmentName().trim(),
|
|
|
|
|
- type == null || type.getId() == null ? null : String.valueOf(type.getId()),
|
|
|
|
|
- monitoringState(status),
|
|
|
|
|
- status == null || status.getStatusUpdateTime() == null
|
|
|
|
|
- ? null
|
|
|
|
|
- : TIME_FORMATTER.format(status.getStatusUpdateTime()
|
|
|
|
|
- .atZone(BUSINESS_ZONE).toOffsetDateTime()),
|
|
|
|
|
- pointCodeByDevice.get(deviceCode),
|
|
|
|
|
- // 数据时间=记录创建时间(equipment_base.create_time),与 sampledAt 分离
|
|
|
|
|
- CockpitCreatedAt.format(device.getCreateTime()),
|
|
|
|
|
- // 设备自身片区(equipment_base.district)即权威来源;脏值由 codeOf 归一为未分区
|
|
|
|
|
- CockpitDistrict.codeOf(device.getDistrict())));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices =
|
|
|
|
|
+ deviceRows(ledger, types, statusById, statusBatchReady, pointCodeByDevice);
|
|
|
|
|
|
|
|
List<CockpitMonitoringOverviewSnapshot.SourceType> sourceTypes = types.values().stream()
|
|
List<CockpitMonitoringOverviewSnapshot.SourceType> sourceTypes = types.values().stream()
|
|
|
.filter(type -> type.getId() != null)
|
|
.filter(type -> type.getId() != null)
|
|
@@ -199,6 +171,81 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
|
|
|
return Integer.valueOf(1).equals(status.getOnlineStatus()) ? "ONLINE" : "OFFLINE";
|
|
return Integer.valueOf(1).equals(status.getOnlineStatus()) ? "ONLINE" : "OFFLINE";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备台账 → 设备行。票 133:额外带 ALARM / WARNING / WORK_ORDER 三个**可叠加标签**。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>标签事实只从 {@link BusinessCockpitDeviceFactResolver} 取(在线/报警=equipment_status、
|
|
|
|
|
+ * 预警=未解除预警、工单=未结束工单);本适配器不另写四表查询,也不用报警流水二次推断
|
|
|
|
|
+ * (CONTEXT.md「设备预警/报警统计」「点位特效显示规则」两节都明令禁止)。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<CockpitMonitoringOverviewSnapshot.SourceDevice> deviceRows(
|
|
|
|
|
+ List<EquipmentBase> ledger,
|
|
|
|
|
+ Map<Integer, EquipmentType> types,
|
|
|
|
|
+ Map<String, EquipmentStatus> statusById,
|
|
|
|
|
+ boolean statusBatchReady,
|
|
|
|
|
+ Map<String, String> pointCodeByDevice) {
|
|
|
|
|
+ List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices = new ArrayList<>();
|
|
|
|
|
+ deviceFacts.prepareBatch(ledger);
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (EquipmentBase device : ledger) {
|
|
|
|
|
+ if (device == null || isBlank(device.getEquipmentCode())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String deviceCode = device.getEquipmentCode().trim();
|
|
|
|
|
+ EquipmentType type = device.getEquipmentTypeId() == null
|
|
|
|
|
+ ? null
|
|
|
|
|
+ : types.get(device.getEquipmentTypeId());
|
|
|
|
|
+
|
|
|
|
|
+ EquipmentStatus status = statusBatchReady
|
|
|
|
|
+ ? statusById.get(device.getEquipmentId())
|
|
|
|
|
+ : null;
|
|
|
|
|
+ if (!statusBatchReady) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ status = equipmentStatusService.getByDeviceCode(deviceCode);
|
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
|
+ // 状态缺失按 UNKNOWN 上报,不阻断概览
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ devices.add(new CockpitMonitoringOverviewSnapshot.SourceDevice(
|
|
|
|
|
+ deviceCode,
|
|
|
|
|
+ // 执行票 62:设备台账要显示名称(缺名如实为 null,不拿编码冒充)。
|
|
|
|
|
+ isBlank(device.getEquipmentName()) ? null : device.getEquipmentName().trim(),
|
|
|
|
|
+ type == null || type.getId() == null ? null : String.valueOf(type.getId()),
|
|
|
|
|
+ monitoringState(status),
|
|
|
|
|
+ status == null || status.getStatusUpdateTime() == null
|
|
|
|
|
+ ? null
|
|
|
|
|
+ : TIME_FORMATTER.format(status.getStatusUpdateTime()
|
|
|
|
|
+ .atZone(BUSINESS_ZONE).toOffsetDateTime()),
|
|
|
|
|
+ pointCodeByDevice.get(deviceCode),
|
|
|
|
|
+ // 数据时间=记录创建时间(equipment_base.create_time),与 sampledAt 分离
|
|
|
|
|
+ CockpitCreatedAt.format(device.getCreateTime()),
|
|
|
|
|
+ // 设备自身片区(equipment_base.district)即权威来源;脏值由 codeOf 归一为未分区
|
|
|
|
|
+ CockpitDistrict.codeOf(device.getDistrict()),
|
|
|
|
|
+ tagsOf(device, type)));
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ deviceFacts.clearBatch();
|
|
|
|
|
+ }
|
|
|
|
|
+ return devices;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 单台设备的状态标签(可叠加):报警/预警/工单任一成立即入列,都不成立时为空列表。 */
|
|
|
|
|
+ private List<String> tagsOf(EquipmentBase device, EquipmentType type) {
|
|
|
|
|
+ CockpitMonitoringPointDeviceSnapshot fact =
|
|
|
|
|
+ deviceFacts.resolve(device, type == null ? null : type.getTypeName());
|
|
|
|
|
+ List<String> tags = new ArrayList<>();
|
|
|
|
|
+ if (fact != null && fact.isAlarm()) {
|
|
|
|
|
+ tags.add("ALARM");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fact != null && fact.isWarning()) {
|
|
|
|
|
+ tags.add("WARNING");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fact != null && fact.isWorkOrderInProgress()) {
|
|
|
|
|
+ tags.add("WORK_ORDER");
|
|
|
|
|
+ }
|
|
|
|
|
+ return tags;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Map<Integer, EquipmentType> equipmentTypes() {
|
|
private Map<Integer, EquipmentType> equipmentTypes() {
|
|
|
Map<Integer, EquipmentType> result = new HashMap<>();
|
|
Map<Integer, EquipmentType> result = new HashMap<>();
|
|
|
for (EquipmentType type : safeList(equipmentTypeService.list())) {
|
|
for (EquipmentType type : safeList(equipmentTypeService.list())) {
|