From b78295e8da96c3e5e76befeef9582ce5273dbb74 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期二, 29 九月 2026 13:10:23 +0800
Subject: [PATCH] 按代码规范检查整改实体注释、Service Javadoc 与分层边界

---
 ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java
index 84188d9..6760c0c 100644
--- a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java
+++ b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java
@@ -3,11 +3,13 @@
 import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import org.junit.jupiter.api.Test;
+import com.ruoyi.common.exception.ServiceException;
 import com.battery.business.domain.TTest;
 import com.battery.business.domain.TTestWarningException;
 import com.battery.business.domain.TTestWarningThreshold;
@@ -47,24 +49,45 @@
 
         service.evaluate(test, "COLLECTOR", "adapter:9:S-01", "temperature", new BigDecimal("31"), "℃", new Date());
         service.evaluate(test, "COLLECTOR", "adapter:9:S-01", "temperature", new BigDecimal("20"), "℃", new Date());
+        service.evaluate(test, "COLLECTOR", "adapter:9:S-01", "temperature", new BigDecimal("0"), "℃", new Date());
+        service.evaluate(test, "COLLECTOR", "adapter:9:S-01", "temperature", new BigDecimal("30"), "℃", new Date());
+        service.evaluate(test, "COLLECTOR", "adapter:9:S-01", "temperature", null, "℃", new Date());
 
         verify(mapper, times(1)).upsertWarningException(eq(1L), eq(11L), eq("COLLECTOR"), eq("adapter:9:S-01"),
                 eq("temperature"), eq(new BigDecimal("31")), eq("℃"), anyString(), eq("WARNING"), any(Date.class));
     }
 
     @Test
-    void closesOpenExceptionAndAppendsAuditInServiceOperation() {
+    void nonReceivingTestsDoNotCreateThresholdTodos() {
+        var mapper = mock(TTestMapper.class);
+        var service = new TestWarningExceptionService(mapper);
+        var test = testWithThreshold("TEMPERATURE", new BigDecimal("8"), new BigDecimal("33"));
+        for (String reception : List.of("PAUSED", "ENDED", "NOT_STARTED")) {
+            test.setReceptionStatus(reception);
+            service.evaluate(test, "COLLECTOR", "9:S-01", "temperature", new BigDecimal("38"), "℃", new Date());
+        }
+        verifyNoInteractions(mapper);
+    }
+
+    @Test
+    void closesOpenExceptionOnlyForTestPrincipalWithHandlingNote() {
         TTestMapper mapper = mock(TTestMapper.class);
         TestWarningExceptionService service = new TestWarningExceptionService(mapper);
         TTestWarningException exception = new TTestWarningException();
         exception.setExceptionId(7L);
         exception.setTestId(1L);
+        TTest test = new TTest();
+        test.setTestId(1L);
+        test.setPrincipalId(22L);
         when(mapper.selectWarningExceptionById(7L)).thenReturn(exception);
+        when(mapper.selectTestById(1L)).thenReturn(test);
         when(mapper.closeWarningException(eq(7L), eq(22L), eq("负责人"), any(Date.class), eq("已核实"))).thenReturn(1);
 
-        int rows = service.close(7L, 22L, "负责人", "已核实");
+        assertEquals(exception, service.closeByPrincipal(7L, 22L, "负责人", "已核实"));
 
-        assertEquals(1, rows);
+        // 归属校验与处理结果必填都由服务层负责,Controller 不再判断业务规则。
+        assertThrows(ServiceException.class, () -> service.closeByPrincipal(7L, 23L, "其他人", "已核实"));
+        assertThrows(ServiceException.class, () -> service.closeByPrincipal(7L, 22L, "负责人", " "));
     }
 
     private static TTest testWithThreshold(String metric, BigDecimal min, BigDecimal max) {
@@ -78,6 +101,8 @@
         TTest test = new TTest();
         test.setTestId(1L);
         test.setThresholds(List.of(threshold));
+        test.setTestStatus("RUNNING");
+        test.setReceptionStatus("RECEIVING");
         return test;
     }
 }

--
Gitblit v1.7.1