SysDeptRestApi { @PUT @Path("/resetParentDept") @SubmarineApi public Response resetParentDept() { LOG.info("resetParentDept()"); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.resetDeptLevel(); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message("Reset department level failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK).success(true) .message("Reset department level successfully!").build(); } @Inject  SysDeptRestApi(); @GET @Path("/tree") @SubmarineApi // Query all departments and respond to the front end in tree structure data format Response tree(@QueryParam("deptCode") String likeDeptCode,
                       @QueryParam("deptName") String likeDeptName); @GET @Path("/queryIdTree") @SubmarineApi Response queryIdTree(@QueryParam("disableDeptCode") String disableDeptCode); @POST @Path("/add") @SubmarineApi Response add(SysDept sysDept); @PUT @Path("/edit") @SubmarineApi Response edit(SysDept sysDept); @PUT @Path("/resetParentDept") @SubmarineApi Response resetParentDept(); @DELETE @Path("/delete") @SubmarineApi Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted); @DELETE @Path("/deleteBatch") @SubmarineApi Response deleteBatch(@QueryParam("ids") String ids); @DELETE @Path("/remove") @SubmarineApi Response remove(String id); static final String SHOW_ALERT; }
@Test public void resetParentDeptTest() { SysDept deptA = new SysDept("A", "deptA"); SysDept deptAA = new SysDept("AA", "deptAA"); deptAA.setParentCode("A"); SysDept deptAB = new SysDept("AB", "deptAB"); deptAB.setParentCode("A"); List<SysDept> depts = new ArrayList<>(); depts.addAll(Arrays.asList(deptA, deptAA, deptAB)); for (SysDept dept : depts) { Response response = sysDeptRestApi.add(dept); CommonDataTest.assertDeptResponseSuccess(response); } Response response = sysDeptRestApi.resetParentDept(); CommonDataTest.assertDeptResponseSuccess(response); JsonResponse<ListResult<SysDeptTree>> response2 = CommonDataTest.queryDeptTreeList(); assertTrue(response2.getSuccess()); for (SysDeptTree deptTree : response2.getResult().getRecords()) { assertEquals(deptTree.getParentCode(), null); } }