@Test public void correctDeptDepend() { SysDept deptA = new SysDept("A", "deptA"); SysDept deptAA = new SysDept("AA", "deptAA"); deptAA.setParentCode("A"); SysDept deptAB = new SysDept("AB", "deptAB"); deptAB.setParentCode("A"); SysDept deptAAA = new SysDept("AAA", "deptAAA"); deptAAA.setParentCode("AA"); SysDept deptABA = new SysDept("ABA", "deptABA"); deptABA.setParentCode("AB"); List<SysDept> depts = new ArrayList<>(); depts.addAll(Arrays.asList(deptA, deptAA, deptAB, deptAAA, deptABA)); for (SysDept dept : depts) { Response response = sysDeptRestApi.add(dept); CommonDataTest.assertDeptResponseSuccess(response); } JsonResponse<ListResult<SysDeptTree>> response = CommonDataTest.queryDeptTreeList(); assertEquals(response.getAttributes().size(), 0); assertEquals(response.getResult().getTotal(), 5); }
@POST @Path("/add") @SubmarineApi public Response add(SysDept sysDept) { LOG.info("add({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.add(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK).success(false) .message("Save department failed!").build(); } return new JsonResponse.Builder<SysDept>(Response.Status.OK) .success(true).message("Save department successfully!").result(sysDept).build(); }
SysDeptRestApi { @POST @Path("/add") @SubmarineApi public Response add(SysDept sysDept) { LOG.info("add({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.add(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK).success(false) .message("Save department failed!").build(); } return new JsonResponse.Builder<SysDept>(Response.Status.OK) .success(true).message("Save department successfully!").result(sysDept).build(); } }
SysDeptRestApi { @POST @Path("/add") @SubmarineApi public Response add(SysDept sysDept) { LOG.info("add({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.add(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK).success(false) .message("Save department failed!").build(); } return new JsonResponse.Builder<SysDept>(Response.Status.OK) .success(true).message("Save department successfully!").result(sysDept).build(); } @Inject  SysDeptRestApi(); }
SysDeptRestApi { @POST @Path("/add") @SubmarineApi public Response add(SysDept sysDept) { LOG.info("add({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.add(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK).success(false) .message("Save department failed!").build(); } return new JsonResponse.Builder<SysDept>(Response.Status.OK) .success(true).message("Save department successfully!").result(sysDept).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); }
SysDeptRestApi { @POST @Path("/add") @SubmarineApi public Response add(SysDept sysDept) { LOG.info("add({})", sysDept.toString()); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); sysDeptMapper.add(sysDept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK).success(false) .message("Save department failed!").build(); } return new JsonResponse.Builder<SysDept>(Response.Status.OK) .success(true).message("Save department successfully!").result(sysDept).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; }