feat(admin): 选人教师树(仿 Notice GetSchoolAll)——组树剔除学生组, YschClassOpenApi.getSchTeaList 按 GroupIds 挂组+空组剪枝 (GET /admin/user/teacherTree); 管理端新增 /def/diagram.png 示意图页进度图 <img> 直嵌
build / build-push (push) Successful in 46s

This commit is contained in:
chenxing
2026-09-17 14:53:05 +08:00
parent 5a7d93a48f
commit 434aa9d185
4 changed files with 274 additions and 1 deletions
@@ -460,7 +460,8 @@ class FlowDiagramServiceTest {
// 真管理守卫(纯逻辑无依赖)+ 其余依赖 mock
controller = new FlowAdminController(new FlowAdminGuard(), defAdminService,
mock(FlowMapAdminService.class), mock(FlowCallbackAdminService.class),
mock(FlwInstanceRepository.class), diagramService);
mock(FlwInstanceRepository.class), diagramService,
mock(com.yunhai.flowcenter.service.DiagramImageService.class));
}
private BoaUser user(int id, Integer type, Integer schId, Integer... roleIds) {
@@ -0,0 +1,128 @@
package com.yunhai.flowcenter.service;
import com.yunhai.flowcenter.repository.FlwAssigneeMapRepository;
import com.yunhai.platform.openapi.base.OpenApiGroupClient;
import com.yunhai.platform.openapi.base.OpenApiUserClient;
import com.yunhai.platform.openapi.clazz.OpenApiClassClient;
import com.yunhai.platform.openapi.clazz.YschClassOpenApi;
import com.yunhai.platform.openapi.clazz.model.SchTea;
import com.yunhai.platform.utils.model.BoaGroup;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* 选人组件教师树(仿 Notice GetSchoolAll 口径):组树骨架剔除学生组、教师按 GroupIds 挂组、
* 空组剪除、归属组全被剔除时兜底挂根。
*/
class FlowMapAdminServiceTeacherTreeTest {
private FlowMapAdminService service;
private final OpenApiGroupClient groupClient = mock(OpenApiGroupClient.class);
private final OpenApiClassClient classClient = mock(OpenApiClassClient.class, RETURNS_DEEP_STUBS);
private static final OpenApiClassClient ORIGINAL_CLIENT = staticClient();
private static OpenApiClassClient staticClient() {
try {
java.lang.reflect.Field f = YschClassOpenApi.class.getDeclaredField("client");
f.setAccessible(true);
return (OpenApiClassClient) f.get(null);
} catch (Exception e) {
return null;
}
}
@AfterAll
static void restore() {
if (ORIGINAL_CLIENT != null) {
YschClassOpenApi.setClient(ORIGINAL_CLIENT);
}
}
@BeforeEach
void setUp() {
service = new FlowMapAdminService(mock(FlwAssigneeMapRepository.class),
mock(OpenApiUserClient.class), groupClient);
YschClassOpenApi.setClient(classClient);
}
private BoaGroup group(int id, String name, Integer type, BoaGroup... children) {
BoaGroup g = new BoaGroup(id, name);
g.setType(type);
if (children.length > 0) {
g.setChildren(new ArrayList<>(Arrays.asList(children)));
}
return g;
}
private SchTea tea(int userId, String name, Integer... gids) {
SchTea t = new SchTea();
t.setUserTeaSerId(userId);
t.setTeaName(name);
t.setGroupIds(new ArrayList<>(Arrays.asList(gids)));
return t;
}
@Test
void teachersAttachByGroup_studentGroupPruned_emptyGroupHighlighted() {
BoaGroup school = group(3, "云海小学", 1,
group(10, "教师组", 7, group(11, "校长室", 7), group(12, "空科室", 7)),
group(20, "学生组", 8));
when(groupClient.getGroupById(3, true)).thenReturn(school);
when(classClient.getSchTeaList(3)).thenReturn(new ArrayList<>(Arrays.asList(
tea(101, "刘文娟", 11), tea(102, "测试教师10", 11, 10))));
List<FlowMapAdminService.SelectUserNodeVo> out = service.teacherTree(3L);
assertEquals(1, out.size());
FlowMapAdminService.SelectUserNodeVo root = out.get(0);
assertEquals(1, root.getChildren().size()); // 学生组整棵剔除
FlowMapAdminService.SelectUserNodeVo jiaoshi = root.getChildren().get(0);
assertEquals("教师组", jiaoshi.getName());
FlowMapAdminService.SelectUserNodeVo xzs = jiaoshi.getChildren().stream()
.filter(c -> "校长室".equals(c.getName())).findFirst()
.orElseThrow(() -> new AssertionError("校长室应未被剪除"));
assertEquals("校长室", xzs.getName());
List<String> names = new ArrayList<>();
xzs.getChildren().forEach(c -> names.add(c.getName()));
assertTrue(names.contains("刘文娟"), "教师应按 GroupIds 挂组");
// 空组(无教师后代)剪除:教师组直属挂教师 102(getGroupUsers 不再混入)
assertEquals(2, jiaoshi.getChildren().size());
assertTrue(jiaoshi.getChildren().stream()
.anyMatch(c -> c.getChildren().stream().anyMatch(l -> "测试教师10".equals(l.getName()))));
}
@Test
void teacherWithoutInTreeGroupFallsBackToRoot() {
BoaGroup school = group(3, "云海小学", 5);
when(groupClient.getGroupById(3, true)).thenReturn(school);
when(classClient.getSchTeaList(3)).thenReturn(new ArrayList<>(Arrays.asList(tea(9, "张三", 999))));
FlowMapAdminService.SelectUserNodeVo root = service.teacherTree(3L).get(0);
assertEquals(1, root.getChildren().size());
assertEquals("张三", root.getChildren().get(0).getName());
assertTrue(!Boolean.TRUE.equals(root.getChildren().get(0).getIsParent()));
}
@Test
void schoolGroupMissingThrows() {
when(groupClient.getGroupById(99, true)).thenReturn(null);
try {
service.teacherTree(99L);
org.junit.jupiter.api.Assertions.fail("应当抛业务异常");
} catch (com.yunhai.platform.apistd.BizException expected) {
// expected
}
}
}