@Test public void updateProjectTest() throws SQLException { Project project = Project.builder().id(1L).name("name").build(); Assert.assertTrue(projectService.updateProject(project).getCode() == ServiceResult.SUCCESS); }
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); }
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); } }
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); }  }
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); }  ValidatorChain validatePermision(LoginUser user, Project project, Errors errors); ServiceResult<String> insertProject(Project project); ServiceResult<String> updateProject(Project project); ServiceResult deleteCheck(Long projectId); ServiceResult<String> deleteProject(Project project); ListResult<ProjectView> findProjectPageList(Paging<ProjectModel> paging); boolean isExistByAppId(String appid); boolean isNotExistByAppId(Project project); boolean isNotExistByName(Project project); ServiceResult generateProjectXml(LoginUser user, Long projectId, String codeGenFilePath); ServiceResult<String> addDataCenter(LoginUser user, Project project); ServiceResult<String> updateDataCenter(LoginUser user, Project oldProject, ProjectView oldProjectView, Project newProject); ServiceResult<String> deleteDataCenter(LoginUser user, Project projec); ServiceResult<String> syncProject(LoginUser user, Project project); ConfigCkeckResult<List<ConfigDataResponse>> getCheckData(LoginUser user, Project project); ServiceResult getProjectButton(LoginUser user); }
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); }  ValidatorChain validatePermision(LoginUser user, Project project, Errors errors); ServiceResult<String> insertProject(Project project); ServiceResult<String> updateProject(Project project); ServiceResult deleteCheck(Long projectId); ServiceResult<String> deleteProject(Project project); ListResult<ProjectView> findProjectPageList(Paging<ProjectModel> paging); boolean isExistByAppId(String appid); boolean isNotExistByAppId(Project project); boolean isNotExistByName(Project project); ServiceResult generateProjectXml(LoginUser user, Long projectId, String codeGenFilePath); ServiceResult<String> addDataCenter(LoginUser user, Project project); ServiceResult<String> updateDataCenter(LoginUser user, Project oldProject, ProjectView oldProjectView, Project newProject); ServiceResult<String> deleteDataCenter(LoginUser user, Project projec); ServiceResult<String> syncProject(LoginUser user, Project project); ConfigCkeckResult<List<ConfigDataResponse>> getCheckData(LoginUser user, Project project); ServiceResult getProjectButton(LoginUser user);  }