更新外观模块
This commit is contained in:
+53
-2
@@ -25,6 +25,7 @@ import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressSnapshotService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskResultItemService;
|
||||
@@ -66,6 +67,7 @@ public class QueryAsinTaskService {
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
private final TaskResultItemService taskResultItemService;
|
||||
private final TaskProgressSnapshotService taskProgressSnapshotService;
|
||||
private final TaskDistributedLockService taskDistributedLockService;
|
||||
|
||||
private FileTaskEntity loadTaskForExecution(Long taskId) {
|
||||
Map<Long, FileTaskEntity> cachedTasks = taskCacheService.getTaskCacheBatch(List.of(taskId));
|
||||
@@ -468,8 +470,18 @@ public class QueryAsinTaskService {
|
||||
throw new BusinessException("记录不存在");
|
||||
}
|
||||
Long taskId = entity.getTaskId();
|
||||
fileResultMapper.deleteById(resultId);
|
||||
reconcileTaskAfterResultRemoval(taskId);
|
||||
if (taskId == null || taskId <= 0) {
|
||||
fileResultMapper.deleteById(resultId);
|
||||
return;
|
||||
}
|
||||
try (TaskDistributedLockService.LockHandle ignored = acquireTaskLockOrThrow(taskId)) {
|
||||
FileResultEntity latestEntity = fileResultMapper.selectById(resultId);
|
||||
if (latestEntity == null || !MODULE_TYPE.equals(latestEntity.getModuleType()) || !userId.equals(latestEntity.getUserId())) {
|
||||
throw new BusinessException("record not found");
|
||||
}
|
||||
fileResultMapper.deleteById(resultId);
|
||||
reconcileTaskAfterResultRemoval(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
private void reconcileTaskAfterResultRemoval(Long taskId) {
|
||||
@@ -719,6 +731,9 @@ public class QueryAsinTaskService {
|
||||
long successCount = rows.stream().filter(row -> Integer.valueOf(RESULT_SUCCESS).equals(row.getSuccess())).count();
|
||||
long failedCount = rows.stream().filter(row -> Integer.valueOf(RESULT_FAILED).equals(row.getSuccess())).count();
|
||||
long pendingCount = rows.stream().filter(row -> !isResultFinished(row)).count();
|
||||
if (pendingCount == 0 && successCount > 0 && isTaskWorkbookPending(task, rows)) {
|
||||
pendingCount = 1;
|
||||
}
|
||||
task.setSuccessFileCount((int) successCount);
|
||||
task.setFailedFileCount((int) failedCount);
|
||||
task.setUpdatedAt(LocalDateTime.now());
|
||||
@@ -948,11 +963,47 @@ public class QueryAsinTaskService {
|
||||
fileResultMapper.updateById(row);
|
||||
}
|
||||
}
|
||||
updateTaskStatusFromRows(task, rows);
|
||||
persistSnapshotJson(task, buildSnapshotFromDb(task, rows));
|
||||
fileTaskMapper.updateById(task);
|
||||
} finally {
|
||||
FileUtil.del(xlsx);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTaskWorkbookPending(FileTaskEntity task, List<FileResultEntity> rows) {
|
||||
if (task == null || task.getId() == null || rows == null || rows.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
FileResultEntity firstSuccess = rows.stream()
|
||||
.filter(row -> Integer.valueOf(RESULT_SUCCESS).equals(row.getSuccess()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (firstSuccess == null) {
|
||||
return false;
|
||||
}
|
||||
if (!blank(firstSuccess.getResultFileUrl())) {
|
||||
return false;
|
||||
}
|
||||
TaskFileJobEntity job = taskFileJobService.findAssembleJob(task.getId(), MODULE_TYPE, firstSuccess.getId());
|
||||
return job != null && !"SUCCESS".equals(job.getStatus());
|
||||
}
|
||||
|
||||
private TaskDistributedLockService.LockHandle acquireTaskLockOrThrow(Long taskId) {
|
||||
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(taskId);
|
||||
if (lockHandle == null) {
|
||||
throw new BusinessException(40901, "浠诲姟姝e湪澶勭悊涓紝璇风◢鍚庡啀璇?");
|
||||
}
|
||||
return lockHandle;
|
||||
}
|
||||
|
||||
private TaskDistributedLockService.LockHandle acquireTaskLock(Long taskId) {
|
||||
if (taskId == null || taskId <= 0) {
|
||||
return null;
|
||||
}
|
||||
return taskDistributedLockService.acquire(MODULE_TYPE, taskId);
|
||||
}
|
||||
|
||||
private void markResultSuccess(FileResultEntity row) {
|
||||
row.setSuccess(RESULT_SUCCESS);
|
||||
row.setErrorMessage(null);
|
||||
|
||||
Reference in New Issue
Block a user