diff --git a/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java b/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java index 8794f2c..8fd84bb 100644 --- a/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java +++ b/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java @@ -4,10 +4,7 @@ import com.databasir.core.domain.DomainErrors; import com.databasir.core.domain.group.converter.GroupPojoConverter; import com.databasir.core.domain.group.converter.GroupResponseConverter; import com.databasir.core.domain.group.data.*; -import com.databasir.dao.impl.GroupDao; -import com.databasir.dao.impl.ProjectDao; -import com.databasir.dao.impl.UserDao; -import com.databasir.dao.impl.UserRoleDao; +import com.databasir.dao.impl.*; import com.databasir.dao.tables.pojos.GroupPojo; import com.databasir.dao.tables.pojos.UserPojo; import com.databasir.dao.tables.pojos.UserRolePojo; @@ -36,6 +33,8 @@ public class GroupService { private final ProjectDao projectDao; + private final ProjectSyncRuleDao projectSyncRuleDao; + private final GroupPojoConverter groupPojoConverter; private final GroupResponseConverter groupResponseConverter; @@ -78,6 +77,9 @@ public class GroupService { public void delete(Integer groupId) { groupDao.deleteById(groupId); userRoleDao.deleteByGroupId(groupId); + List projectIds = projectDao.selectProjectIdsByGroupId(groupId); + projectSyncRuleDao.disableAutoSyncByProjectIds(projectIds); + projectDao.deleteByGroupId(groupId); } public Page list(Pageable pageable, GroupPageCondition condition) { diff --git a/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java b/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java index f6a7228..027c58a 100644 --- a/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java +++ b/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java @@ -49,11 +49,11 @@ public class ProjectService { public ProjectDetailResponse getOne(Integer id) { return projectDao.selectOptionalById(id) .map(schemaSource -> { - DataSourcePojo dataSource = dataSourceDao.selectByProjectId(id); - List properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId()); - ProjectDetailResponse.DataSourceResponse dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties); - ProjectSyncRulePojo rule = projectSyncRuleDao.selectByProjectId(id); - ProjectDetailResponse.ProjectSyncRuleResponse ruleResponse = projectResponseConverter.toResponse(rule); + var dataSource = dataSourceDao.selectByProjectId(id); + var properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId()); + var dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties); + var projectSyncRule = projectSyncRuleDao.selectOptionalByProjectId(id).orElse(null); + var ruleResponse = projectResponseConverter.toResponse(projectSyncRule); return projectResponseConverter.toResponse(schemaSource, dataSourceResponse, ruleResponse); }) .orElseThrow(DomainErrors.PROJECT_NOT_FOUND::exception); @@ -125,6 +125,7 @@ public class ProjectService { public void delete(Integer projectId) { projectDao.updateDeletedById(true, projectId); + projectSyncRuleDao.disableAutoSyncByProjectId(projectId); } public Page list(Pageable page, ProjectListCondition condition) { diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java index ffb50b1..7e59940 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java @@ -86,4 +86,18 @@ public class ProjectDao extends BaseDao { + " where project.deleted = false and `group`.id in " + groupIdIn + " group by `group`.id;"; return dslContext.resultQuery(sql).fetchInto(GroupProjectCountPojo.class); } + + public void deleteByGroupId(Integer groupId) { + dslContext + .update(PROJECT).set(PROJECT.DELETED, true) + .where(PROJECT.GROUP_ID.eq(groupId).and(PROJECT.DELETED.eq(false))) + .execute(); + } + + public List selectProjectIdsByGroupId(Integer groupId) { + return dslContext + .select(PROJECT.ID).from(PROJECT) + .where(PROJECT.GROUP_ID.eq(groupId).and(PROJECT.DELETED.eq(false))) + .fetchInto(Integer.class); + } } diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java index a0a45f5..06a3f3e 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java @@ -95,4 +95,22 @@ public class ProjectSyncRuleDao extends BaseDao projectIds) { + if (projectIds == null || projectIds.isEmpty()) { + return; + } + dslContext + .update(PROJECT_SYNC_RULE).set(PROJECT_SYNC_RULE.IS_AUTO_SYNC, false) + .where(PROJECT_SYNC_RULE.PROJECT_ID.in(projectIds)) + .execute(); + } }