@Test public void updateAppGroupTest() throws SQLException { AppGroup appGroup = AppGroup.builder().id(1L).build(); ServiceResult<String> sr = appGroupService.deleteAppGroup(appGroup); Assert.assertTrue(sr.getCode() == ServiceResult.SUCCESS); }
public ServiceResult<String> updateAppGroup(AppGroup appGroup) throws SQLException { boolean isSussess = projectDao.getDasClient().execute(() -> { List<Project> list = projectDao.getProjectByAppGroupId(appGroup.getId()); Set<Long> oldProjectIds = list.stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> newProjectIds = appGroup.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> deleteProjectIds = Sets.difference(oldProjectIds, newProjectIds).stream().collect(Collectors.toSet()); Set<Long> addProjectIds = Sets.difference(newProjectIds, oldProjectIds).stream().collect(Collectors.toSet()); if (CollectionUtils.isNotEmpty(deleteProjectIds) && projectDao.deleteProjectAppGroupIdByIdS(deleteProjectIds) <= 0) { throw new TransactionException(message.db_message_delete_operation_failed); } if (CollectionUtils.isNotEmpty(addProjectIds) && projectDao.updateProjectAppGroupIdById(appGroup.getId(), addProjectIds) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } if (appGroupDao.updateAppGroup(appGroup) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } return true; }); if (isSussess) { return ServiceResult.success(); } return ServiceResult.fail(message.db_message_update_operation_failed); }
AppGroupService { public ServiceResult<String> updateAppGroup(AppGroup appGroup) throws SQLException { boolean isSussess = projectDao.getDasClient().execute(() -> { List<Project> list = projectDao.getProjectByAppGroupId(appGroup.getId()); Set<Long> oldProjectIds = list.stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> newProjectIds = appGroup.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> deleteProjectIds = Sets.difference(oldProjectIds, newProjectIds).stream().collect(Collectors.toSet()); Set<Long> addProjectIds = Sets.difference(newProjectIds, oldProjectIds).stream().collect(Collectors.toSet()); if (CollectionUtils.isNotEmpty(deleteProjectIds) && projectDao.deleteProjectAppGroupIdByIdS(deleteProjectIds) <= 0) { throw new TransactionException(message.db_message_delete_operation_failed); } if (CollectionUtils.isNotEmpty(addProjectIds) && projectDao.updateProjectAppGroupIdById(appGroup.getId(), addProjectIds) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } if (appGroupDao.updateAppGroup(appGroup) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } return true; }); if (isSussess) { return ServiceResult.success(); } return ServiceResult.fail(message.db_message_update_operation_failed); } }
AppGroupService { public ServiceResult<String> updateAppGroup(AppGroup appGroup) throws SQLException { boolean isSussess = projectDao.getDasClient().execute(() -> { List<Project> list = projectDao.getProjectByAppGroupId(appGroup.getId()); Set<Long> oldProjectIds = list.stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> newProjectIds = appGroup.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> deleteProjectIds = Sets.difference(oldProjectIds, newProjectIds).stream().collect(Collectors.toSet()); Set<Long> addProjectIds = Sets.difference(newProjectIds, oldProjectIds).stream().collect(Collectors.toSet()); if (CollectionUtils.isNotEmpty(deleteProjectIds) && projectDao.deleteProjectAppGroupIdByIdS(deleteProjectIds) <= 0) { throw new TransactionException(message.db_message_delete_operation_failed); } if (CollectionUtils.isNotEmpty(addProjectIds) && projectDao.updateProjectAppGroupIdById(appGroup.getId(), addProjectIds) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } if (appGroupDao.updateAppGroup(appGroup) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } return true; }); if (isSussess) { return ServiceResult.success(); } return ServiceResult.fail(message.db_message_update_operation_failed); }  }
AppGroupService { public ServiceResult<String> updateAppGroup(AppGroup appGroup) throws SQLException { boolean isSussess = projectDao.getDasClient().execute(() -> { List<Project> list = projectDao.getProjectByAppGroupId(appGroup.getId()); Set<Long> oldProjectIds = list.stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> newProjectIds = appGroup.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> deleteProjectIds = Sets.difference(oldProjectIds, newProjectIds).stream().collect(Collectors.toSet()); Set<Long> addProjectIds = Sets.difference(newProjectIds, oldProjectIds).stream().collect(Collectors.toSet()); if (CollectionUtils.isNotEmpty(deleteProjectIds) && projectDao.deleteProjectAppGroupIdByIdS(deleteProjectIds) <= 0) { throw new TransactionException(message.db_message_delete_operation_failed); } if (CollectionUtils.isNotEmpty(addProjectIds) && projectDao.updateProjectAppGroupIdById(appGroup.getId(), addProjectIds) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } if (appGroupDao.updateAppGroup(appGroup) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } return true; }); if (isSussess) { return ServiceResult.success(); } return ServiceResult.fail(message.db_message_update_operation_failed); }  ValidatorChain validatePermision(LoginUser user, Errors errors); ListResult<AppGroupView> findProjectGroupPageList(Paging<AppGroup> paging); ServiceResult<String> insertAppGroup(AppGroup appGroup); ServiceResult deleteCheck(Long dbsetId); ServiceResult<String> deleteAppGroup(AppGroup appGroup); ServiceResult<String> updateAppGroup(AppGroup appGroup); boolean isNotExistByName(AppGroup appGroup); }
AppGroupService { public ServiceResult<String> updateAppGroup(AppGroup appGroup) throws SQLException { boolean isSussess = projectDao.getDasClient().execute(() -> { List<Project> list = projectDao.getProjectByAppGroupId(appGroup.getId()); Set<Long> oldProjectIds = list.stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> newProjectIds = appGroup.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet()); Set<Long> deleteProjectIds = Sets.difference(oldProjectIds, newProjectIds).stream().collect(Collectors.toSet()); Set<Long> addProjectIds = Sets.difference(newProjectIds, oldProjectIds).stream().collect(Collectors.toSet()); if (CollectionUtils.isNotEmpty(deleteProjectIds) && projectDao.deleteProjectAppGroupIdByIdS(deleteProjectIds) <= 0) { throw new TransactionException(message.db_message_delete_operation_failed); } if (CollectionUtils.isNotEmpty(addProjectIds) && projectDao.updateProjectAppGroupIdById(appGroup.getId(), addProjectIds) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } if (appGroupDao.updateAppGroup(appGroup) <= 0) { throw new TransactionException(message.db_message_update_operation_failed); } return true; }); if (isSussess) { return ServiceResult.success(); } return ServiceResult.fail(message.db_message_update_operation_failed); }  ValidatorChain validatePermision(LoginUser user, Errors errors); ListResult<AppGroupView> findProjectGroupPageList(Paging<AppGroup> paging); ServiceResult<String> insertAppGroup(AppGroup appGroup); ServiceResult deleteCheck(Long dbsetId); ServiceResult<String> deleteAppGroup(AppGroup appGroup); ServiceResult<String> updateAppGroup(AppGroup appGroup); boolean isNotExistByName(AppGroup appGroup);  }