|
@@ -1,114 +0,0 @@
|
|
|
-package com.zksy.web.controller.cockpit;
|
|
|
|
|
-
|
|
|
|
|
-import com.zksy.base.alarm.domain.AlarmLog;
|
|
|
|
|
-import com.zksy.base.alarm.dto.AlarmVO;
|
|
|
|
|
-import com.zksy.base.alarm.mapper.AlarmLogMapper;
|
|
|
|
|
-import com.zksy.base.alarm.mapper.AlarmOperationsMapper;
|
|
|
|
|
-import com.zksy.base.warning.mapper.AlarmWarningRelMapper;
|
|
|
|
|
-import com.zksy.base.warning.mapper.EarlyWarningMapper;
|
|
|
|
|
-import com.zksy.base.warning.mapper.WarningAttachmentMapper;
|
|
|
|
|
-import com.zksy.base.warning.mapper.WarningDisposalMapper;
|
|
|
|
|
-import com.zksy.base.warning.mapper.WarningSupervisionMapper;
|
|
|
|
|
-import com.zksy.cockpit.event.CockpitEventDetailService;
|
|
|
|
|
-import com.zksy.ops.dto.WorkOrderDetailVO;
|
|
|
|
|
-import com.zksy.ops.domain.vo.WorkOrderVO;
|
|
|
|
|
-import com.zksy.ops.service.WorkOrderService;
|
|
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
|
|
-import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
|
-import org.mockito.InjectMocks;
|
|
|
|
|
-import org.mockito.Mock;
|
|
|
|
|
-import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
-
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
|
|
-
|
|
|
|
|
-@ExtendWith(MockitoExtension.class)
|
|
|
|
|
-class CockpitEventDetailServiceAlarmTest {
|
|
|
|
|
-
|
|
|
|
|
- @Mock private EarlyWarningMapper warnings;
|
|
|
|
|
- @Mock private AlarmOperationsMapper alarms;
|
|
|
|
|
- @Mock private WarningDisposalMapper disposals;
|
|
|
|
|
- @Mock private WarningAttachmentMapper attachments;
|
|
|
|
|
- @Mock private WarningSupervisionMapper supervisions;
|
|
|
|
|
- @Mock private AlarmWarningRelMapper linkedAlarms;
|
|
|
|
|
- @Mock private AlarmLogMapper alarmLogs;
|
|
|
|
|
- @Mock private WorkOrderService workOrders;
|
|
|
|
|
- @InjectMocks private CockpitEventDetailService service;
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void alarmDetailCarriesHistoryAndAttachmentList() {
|
|
|
|
|
- AlarmVO detail = new AlarmVO();
|
|
|
|
|
- detail.setId("A1");
|
|
|
|
|
- detail.setAlarmNo("BJ1");
|
|
|
|
|
- detail.setEquipmentImage("/upload/device.png");
|
|
|
|
|
- detail.setWorkOrderId(9L);
|
|
|
|
|
- when(alarms.selectCockpitDetailByNo("BJ1")).thenReturn(detail);
|
|
|
|
|
-
|
|
|
|
|
- AlarmLog log = new AlarmLog();
|
|
|
|
|
- log.setOperType(1);
|
|
|
|
|
- log.setOperDesc("确认报警");
|
|
|
|
|
- log.setOperUserName("值班员");
|
|
|
|
|
- log.setOperTime(LocalDateTime.of(2026, 12, 1, 9, 30));
|
|
|
|
|
- log.setAttachUrl("/upload/alarm-a.png,/upload/alarm-b.png");
|
|
|
|
|
- when(alarmLogs.selectHistory("A1")).thenReturn(Collections.singletonList(log));
|
|
|
|
|
-
|
|
|
|
|
- WorkOrderVO order = new WorkOrderVO();
|
|
|
|
|
- order.setMaintenanceBeforeImg("/upload/before.png");
|
|
|
|
|
- order.setMaintenanceAfterImg("/upload/after.png");
|
|
|
|
|
- WorkOrderDetailVO orderDetail = new WorkOrderDetailVO();
|
|
|
|
|
- orderDetail.setOrder(order);
|
|
|
|
|
- when(workOrders.getDetail(9L)).thenReturn(orderDetail);
|
|
|
|
|
-
|
|
|
|
|
- AlarmVO result = service.alarmDetail("BJ1");
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(1, result.getDisposalHistory().size());
|
|
|
|
|
- Map<String, Object> record = result.getDisposalHistory().get(0);
|
|
|
|
|
- assertEquals("确认报警", record.get("operationDesc"));
|
|
|
|
|
- assertEquals("值班员", record.get("operatorName"));
|
|
|
|
|
- assertEquals("2026-12-01 09:30:00", record.get("operatedAt"));
|
|
|
|
|
-
|
|
|
|
|
- List<String> urls = result.getAttachmentList().stream()
|
|
|
|
|
- .map(item -> String.valueOf(item.get("url")))
|
|
|
|
|
- .toList();
|
|
|
|
|
- assertTrue(urls.contains("/upload/device.png"));
|
|
|
|
|
- assertTrue(urls.contains("/upload/alarm-a.png"));
|
|
|
|
|
- assertTrue(urls.contains("/upload/before.png"));
|
|
|
|
|
- assertTrue(urls.contains("/upload/after.png"));
|
|
|
|
|
- assertEquals(urls.size(), result.getAttachmentList().size(), "附件按 URL 去重");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void alarmDetailReturnsEmptyArraysWhenNoHistoryAndNoAttachments() {
|
|
|
|
|
- AlarmVO detail = new AlarmVO();
|
|
|
|
|
- detail.setId("A2");
|
|
|
|
|
- detail.setAlarmNo("BJ2");
|
|
|
|
|
- when(alarms.selectCockpitDetailByNo("BJ2")).thenReturn(detail);
|
|
|
|
|
- when(alarmLogs.selectHistory("A2")).thenReturn(Collections.emptyList());
|
|
|
|
|
-
|
|
|
|
|
- AlarmVO result = service.alarmDetail("BJ2");
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(Collections.emptyList(), result.getDisposalHistory());
|
|
|
|
|
- assertEquals(Collections.emptyList(), result.getAttachmentList());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void alarmDetailKeepsBasicDetailWhenHistoryReadFails() {
|
|
|
|
|
- AlarmVO detail = new AlarmVO();
|
|
|
|
|
- detail.setId("A3");
|
|
|
|
|
- detail.setAlarmNo("BJ3");
|
|
|
|
|
- when(alarms.selectCockpitDetailByNo("BJ3")).thenReturn(detail);
|
|
|
|
|
- when(alarmLogs.selectHistory("A3")).thenThrow(new RuntimeException("log table unavailable"));
|
|
|
|
|
-
|
|
|
|
|
- AlarmVO result = service.alarmDetail("BJ3");
|
|
|
|
|
-
|
|
|
|
|
- assertEquals("BJ3", result.getAlarmNo());
|
|
|
|
|
- assertEquals(Collections.emptyList(), result.getDisposalHistory());
|
|
|
|
|
- assertEquals(Collections.emptyList(), result.getAttachmentList());
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|