已删除项目继续从管理员列表和详情中隐藏。
删除后,同一 GitHub 来源可通过“新建迁移”重新拉取,生成新的项目、任务和仓库。 旧任务的“重试迁移”保持原有校验。
This commit is contained in:
+29
-12
@@ -79,13 +79,26 @@ public class AdminImportService {
|
||||
}
|
||||
|
||||
private Project existing(long sourceId) {
|
||||
ProjectImportTask task =
|
||||
tasks.selectOne(
|
||||
new LambdaQueryWrapper<ProjectImportTask>()
|
||||
.eq(ProjectImportTask::getSourceRepositoryId, sourceId));
|
||||
String code = task == null ? ProjectCodes.github(sourceId) : task.getProjectCode();
|
||||
Project active = tasks.activeProject(sourceId);
|
||||
if (active != null) return active;
|
||||
// 兼容旧命令行导入的项目:可能尚未建立在线迁移任务。
|
||||
return projects.selectOne(
|
||||
new LambdaQueryWrapper<Project>().eq(Project::getProjectCode, code));
|
||||
new LambdaQueryWrapper<Project>()
|
||||
.eq(Project::getProjectCode, ProjectCodes.github(sourceId))
|
||||
.eq(Project::getDeleted, false));
|
||||
}
|
||||
|
||||
private String nextProjectCode(long sourceId) {
|
||||
long generation = tasks.selectCount(
|
||||
new LambdaQueryWrapper<ProjectImportTask>()
|
||||
.eq(ProjectImportTask::getSourceRepositoryId, sourceId));
|
||||
// 跳过旧导入或其他历史记录已经占用的编码,签名与创建可推导出同一目标。
|
||||
for (int attempt = 0; attempt < 32; attempt++) {
|
||||
String code = ProjectCodes.github(sourceId, generation + attempt);
|
||||
if (!projects.exists(new LambdaQueryWrapper<Project>()
|
||||
.eq(Project::getProjectCode, code))) return code;
|
||||
}
|
||||
throw BusinessException.conflict("迁移项目编码无法分配,请联系维护人员核对");
|
||||
}
|
||||
|
||||
private void requireNewSource(long sourceId) {
|
||||
@@ -104,7 +117,7 @@ public class AdminImportService {
|
||||
urdfResources.requireEnabled();
|
||||
GitHubSourceChecks.Repository source = check(input.repositoryUrl());
|
||||
requireNewSource(source.id());
|
||||
String code = ProjectCodes.github(source.id());
|
||||
String code = nextProjectCode(source.id());
|
||||
UrdfUploadSignature signature = urdfResources.sign(code, input.files());
|
||||
log.info(
|
||||
"生成迁移项目 URDF 签名 userCode={} projectCode={} batchCode={} fileCount={}",
|
||||
@@ -119,7 +132,7 @@ public class AdminImportService {
|
||||
|
||||
private PreparedUrdf prepareUrdf(String projectCode, UrdfConfirmInput input) {
|
||||
if (input == null) return null;
|
||||
// 项目编码由重新校验的 GitHub 稳定标识生成,不能借用其他项目的上传批次。
|
||||
// 项目编码由重新校验的 GitHub 稳定标识和迁移代次生成,不能借用其他项目的上传批次。
|
||||
// OSS 核验在数据库事务及项目锁之外完成,不依赖尚未创建的 Git 仓库。
|
||||
urdfResources.verify(projectCode, input.batchCode(), input.files());
|
||||
String prefix = urdfResources.prefix(projectCode, input.batchCode());
|
||||
@@ -132,14 +145,17 @@ public class AdminImportService {
|
||||
rateLimits.operation("create", 0);
|
||||
ProjectInputs.validate(input.project(), properties);
|
||||
GitHubSourceChecks.Repository source = check(input.repositoryUrl());
|
||||
String code = ProjectCodes.github(source.id());
|
||||
requireNewSource(source.id());
|
||||
String code = nextProjectCode(source.id());
|
||||
PreparedUrdf urdf = prepareUrdf(code, input.urdf());
|
||||
User owner = management.owner(input.ownerUserCode());
|
||||
return locks.serial(
|
||||
code,
|
||||
// 各次迁移的项目编码不同,来源锁始终使用首代编码,防止并发创建两个有效项目。
|
||||
ProjectCodes.github(source.id()),
|
||||
() -> {
|
||||
requireNewSource(source.id());
|
||||
if (!code.equals(nextProjectCode(source.id())))
|
||||
throw BusinessException.conflict("来源迁移记录已变化,请刷新并重新申请上传签名");
|
||||
try {
|
||||
return transactions.execute(
|
||||
status -> {
|
||||
@@ -182,10 +198,11 @@ public class AdminImportService {
|
||||
task.setUpdatedAt(task.getCreatedAt());
|
||||
tasks.insert(task);
|
||||
log.info(
|
||||
"创建迁移任务 userCode={} taskCode={} projectCode={}",
|
||||
"创建迁移任务 userCode={} taskCode={} projectCode={} reimport={}",
|
||||
task.getOperatorUserCode(),
|
||||
task.getTaskCode(),
|
||||
code);
|
||||
code,
|
||||
!code.equals(ProjectCodes.github(source.id())));
|
||||
if (urdf != null)
|
||||
log.info(
|
||||
"迁移项目绑定 URDF userCode={} taskCode={} projectCode={}"
|
||||
|
||||
+12
-1
@@ -1,6 +1,17 @@
|
||||
package com.linkerbot.vibemake.service.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.linkerbot.vibemake.bean.entity.Project;
|
||||
import com.linkerbot.vibemake.bean.entity.ProjectImportTask;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
public interface ProjectImportTaskMapper extends BaseMapper<ProjectImportTask> {}
|
||||
public interface ProjectImportTaskMapper extends BaseMapper<ProjectImportTask> {
|
||||
@Select("""
|
||||
SELECT p.* FROM project p
|
||||
JOIN project_import_task t ON t.project_code = p.project_code
|
||||
WHERE t.source_repository_id = #{sourceId} AND p.deleted = 0
|
||||
ORDER BY t.id DESC LIMIT 1
|
||||
""")
|
||||
Project activeProject(@Param("sourceId") long sourceId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user