fix: disable auto sync after delete project/group (#5)
This commit is contained in:
parent
4bf7f5161a
commit
82feab3f1a
|
@ -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.GroupPojoConverter;
|
||||||
import com.databasir.core.domain.group.converter.GroupResponseConverter;
|
import com.databasir.core.domain.group.converter.GroupResponseConverter;
|
||||||
import com.databasir.core.domain.group.data.*;
|
import com.databasir.core.domain.group.data.*;
|
||||||
import com.databasir.dao.impl.GroupDao;
|
import com.databasir.dao.impl.*;
|
||||||
import com.databasir.dao.impl.ProjectDao;
|
|
||||||
import com.databasir.dao.impl.UserDao;
|
|
||||||
import com.databasir.dao.impl.UserRoleDao;
|
|
||||||
import com.databasir.dao.tables.pojos.GroupPojo;
|
import com.databasir.dao.tables.pojos.GroupPojo;
|
||||||
import com.databasir.dao.tables.pojos.UserPojo;
|
import com.databasir.dao.tables.pojos.UserPojo;
|
||||||
import com.databasir.dao.tables.pojos.UserRolePojo;
|
import com.databasir.dao.tables.pojos.UserRolePojo;
|
||||||
|
@ -36,6 +33,8 @@ public class GroupService {
|
||||||
|
|
||||||
private final ProjectDao projectDao;
|
private final ProjectDao projectDao;
|
||||||
|
|
||||||
|
private final ProjectSyncRuleDao projectSyncRuleDao;
|
||||||
|
|
||||||
private final GroupPojoConverter groupPojoConverter;
|
private final GroupPojoConverter groupPojoConverter;
|
||||||
|
|
||||||
private final GroupResponseConverter groupResponseConverter;
|
private final GroupResponseConverter groupResponseConverter;
|
||||||
|
@ -78,6 +77,9 @@ public class GroupService {
|
||||||
public void delete(Integer groupId) {
|
public void delete(Integer groupId) {
|
||||||
groupDao.deleteById(groupId);
|
groupDao.deleteById(groupId);
|
||||||
userRoleDao.deleteByGroupId(groupId);
|
userRoleDao.deleteByGroupId(groupId);
|
||||||
|
List<Integer> projectIds = projectDao.selectProjectIdsByGroupId(groupId);
|
||||||
|
projectSyncRuleDao.disableAutoSyncByProjectIds(projectIds);
|
||||||
|
projectDao.deleteByGroupId(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<GroupPageResponse> list(Pageable pageable, GroupPageCondition condition) {
|
public Page<GroupPageResponse> list(Pageable pageable, GroupPageCondition condition) {
|
||||||
|
|
|
@ -49,11 +49,11 @@ public class ProjectService {
|
||||||
public ProjectDetailResponse getOne(Integer id) {
|
public ProjectDetailResponse getOne(Integer id) {
|
||||||
return projectDao.selectOptionalById(id)
|
return projectDao.selectOptionalById(id)
|
||||||
.map(schemaSource -> {
|
.map(schemaSource -> {
|
||||||
DataSourcePojo dataSource = dataSourceDao.selectByProjectId(id);
|
var dataSource = dataSourceDao.selectByProjectId(id);
|
||||||
List<DataSourcePropertyPojo> properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId());
|
var properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId());
|
||||||
ProjectDetailResponse.DataSourceResponse dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties);
|
var dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties);
|
||||||
ProjectSyncRulePojo rule = projectSyncRuleDao.selectByProjectId(id);
|
var projectSyncRule = projectSyncRuleDao.selectOptionalByProjectId(id).orElse(null);
|
||||||
ProjectDetailResponse.ProjectSyncRuleResponse ruleResponse = projectResponseConverter.toResponse(rule);
|
var ruleResponse = projectResponseConverter.toResponse(projectSyncRule);
|
||||||
return projectResponseConverter.toResponse(schemaSource, dataSourceResponse, ruleResponse);
|
return projectResponseConverter.toResponse(schemaSource, dataSourceResponse, ruleResponse);
|
||||||
})
|
})
|
||||||
.orElseThrow(DomainErrors.PROJECT_NOT_FOUND::exception);
|
.orElseThrow(DomainErrors.PROJECT_NOT_FOUND::exception);
|
||||||
|
@ -125,6 +125,7 @@ public class ProjectService {
|
||||||
|
|
||||||
public void delete(Integer projectId) {
|
public void delete(Integer projectId) {
|
||||||
projectDao.updateDeletedById(true, projectId);
|
projectDao.updateDeletedById(true, projectId);
|
||||||
|
projectSyncRuleDao.disableAutoSyncByProjectId(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<ProjectSimpleResponse> list(Pageable page, ProjectListCondition condition) {
|
public Page<ProjectSimpleResponse> list(Pageable page, ProjectListCondition condition) {
|
||||||
|
|
|
@ -86,4 +86,18 @@ public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> {
|
||||||
+ " where project.deleted = false and `group`.id in " + groupIdIn + " group by `group`.id;";
|
+ " where project.deleted = false and `group`.id in " + groupIdIn + " group by `group`.id;";
|
||||||
return dslContext.resultQuery(sql).fetchInto(GroupProjectCountPojo.class);
|
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<Integer> selectProjectIdsByGroupId(Integer groupId) {
|
||||||
|
return dslContext
|
||||||
|
.select(PROJECT.ID).from(PROJECT)
|
||||||
|
.where(PROJECT.GROUP_ID.eq(groupId).and(PROJECT.DELETED.eq(false)))
|
||||||
|
.fetchInto(Integer.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,4 +95,22 @@ public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRuleRecord, ProjectSy
|
||||||
PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)
|
PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)
|
||||||
.and(PROJECT_SYNC_RULE.AUTO_SYNC_CRON.eq(cron)));
|
.and(PROJECT_SYNC_RULE.AUTO_SYNC_CRON.eq(cron)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disableAutoSyncByProjectId(Integer projectId) {
|
||||||
|
dslContext
|
||||||
|
.update(PROJECT_SYNC_RULE).set(PROJECT_SYNC_RULE.IS_AUTO_SYNC, false)
|
||||||
|
.where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAutoSyncByProjectIds(List<Integer> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue