@Test public void deleteTest() { SysDept deptA = new SysDept("A", "deptA"); List<SysDept> depts = new ArrayList<>(); depts.addAll(Arrays.asList(deptA)); for (SysDept dept : depts) { Response response = sysDeptRestApi.add(dept); CommonDataTest.assertDeptResponseSuccess(response); } for (SysDept dept : depts) { Response response = sysDeptRestApi.delete(dept.getId(), 1); CommonDataTest.assertDeptResponseSuccess(response); } JsonResponse<ListResult<SysDeptTree>> response2 = CommonDataTest.queryDeptTreeList(); assertTrue(response2.getSuccess()); for (SysDeptTree deptTree : response2.getResult().getRecords()) { assertTrue(deptTree.getDeleted() == 1); } }
@DELETE @Path("/delete") @SubmarineApi public Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted) { LOG.info("delete({}, {})", id, deleted); String msgOperation = "Delete"; if (deleted == 0) { msgOperation = "Restore"; } try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = new SysDept(); dept.setId(id); dept.setDeleted(deleted); sysDeptMapper.updateBy(dept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department successfully!").success(true).build(); }
SysDeptRestApi { @DELETE @Path("/delete") @SubmarineApi public Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted) { LOG.info("delete({}, {})", id, deleted); String msgOperation = "Delete"; if (deleted == 0) { msgOperation = "Restore"; } try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = new SysDept(); dept.setId(id); dept.setDeleted(deleted); sysDeptMapper.updateBy(dept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department successfully!").success(true).build(); } }
SysDeptRestApi { @DELETE @Path("/delete") @SubmarineApi public Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted) { LOG.info("delete({}, {})", id, deleted); String msgOperation = "Delete"; if (deleted == 0) { msgOperation = "Restore"; } try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = new SysDept(); dept.setId(id); dept.setDeleted(deleted); sysDeptMapper.updateBy(dept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department successfully!").success(true).build(); } @Inject  SysDeptRestApi(); }
SysDeptRestApi { @DELETE @Path("/delete") @SubmarineApi public Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted) { LOG.info("delete({}, {})", id, deleted); String msgOperation = "Delete"; if (deleted == 0) { msgOperation = "Restore"; } try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = new SysDept(); dept.setId(id); dept.setDeleted(deleted); sysDeptMapper.updateBy(dept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department successfully!").success(true).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 { @DELETE @Path("/delete") @SubmarineApi public Response delete(@QueryParam("id") String id, @QueryParam("deleted") int deleted) { LOG.info("delete({}, {})", id, deleted); String msgOperation = "Delete"; if (deleted == 0) { msgOperation = "Restore"; } try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class); SysDept dept = new SysDept(); dept.setId(id); dept.setDeleted(deleted); sysDeptMapper.updateBy(dept); sqlSession.commit(); } catch (Exception e) { LOG.error(e.getMessage(), e); return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department failed!").success(false).build(); } return new JsonResponse.Builder<>(Response.Status.OK) .message(msgOperation + " department successfully!").success(true).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; }