class 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);
    }

}