class ProjectService {

    public ServiceResult<String> updateProject(Project project) throws SQLException {
        boolean isSussess = projectDbsetRelationDao.getDasClient().execute(() -> {
            //更新项目对应的逻辑库
            List<ProjectDbsetRelation> list = projectDbsetRelationDao.getAllProjectDbsetRelation(project.getId());
            Set<Long> oldDbsetIds = list.stream().map(e -> e.getDbsetId()).collect(Collectors.toSet());
            Set<Long> newDbsetIds = project.getItems().stream().map(e -> e.getId()).collect(Collectors.toSet());
            Set<Long> deleteDbsetIds = Sets.difference(oldDbsetIds, newDbsetIds).stream().collect(Collectors.toSet());
            Set<Long> addDbsetIds = Sets.difference(newDbsetIds, oldDbsetIds).stream().collect(Collectors.toSet());
            if (deleteCheckDao.isDbsetIdInTaskSQL(project.getId(), deleteDbsetIds) || deleteCheckDao.isDbsetIdInTaskTable(project.getId(), deleteDbsetIds)) {
                throw new RuntimeException("请在'代码生成器 --> 实体类管理'页先删除对应的实体类！！");
            }
            if (CollectionUtils.isNotEmpty(deleteDbsetIds) && projectDbsetRelationDao.deleteByProjectAndDbSetIdS(project.getId(), deleteDbsetIds) <= 0) {
                throw new RuntimeException(message.db_message_delete_operation_failed);
            }
            list = toProjectDbsetRelations(project, addDbsetIds);
            if (CollectionUtils.isNotEmpty(addDbsetIds) && projectDbsetRelationDao.insertRelationList(list).length <= 0) {
                throw new RuntimeException(message.db_message_update_operation_failed);
            }

            //更新项目负责人
            List<UserProject> users = userProjectDao.getUsersByProjectId(project.getId());
            Set<Long> oldUserIds = users.stream().map(e -> e.getUserId()).collect(Collectors.toSet());
            Set<Long> newUserIds = project.getUsers().stream().map(e -> e.getId()).collect(Collectors.toSet());
            Set<Long> deleteUserIds = Sets.difference(oldUserIds, newUserIds).stream().collect(Collectors.toSet());
            Set<Long> addUserIds = Sets.difference(newUserIds, oldUserIds).stream().collect(Collectors.toSet());
            if (CollectionUtils.isNotEmpty(deleteUserIds) && userProjectDao.deleteByProjectAndUserIdS(project.getId(), deleteUserIds) <= 0) {
                throw new TransactionException(message.db_message_delete_operation_failed);
            }
            users = toUserProjects(project, addUserIds);
            if (CollectionUtils.isNotEmpty(addUserIds) && userProjectDao.insertUserProjectList(users).length <= 0) {
                throw new TransactionException(message.db_message_update_operation_failed);
            }
            if (projectDao.updateProject(project) <= 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);
    }

}