更新外观模块
This commit is contained in:
+71
-6
@@ -27,6 +27,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.TaskResultPayloadService;
|
||||
import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService;
|
||||
@@ -71,6 +72,7 @@ public class PriceTrackTaskService {
|
||||
private final TaskPressureProperties taskPressureProperties;
|
||||
private final TaskResultPayloadService taskResultPayloadService;
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
private final TaskDistributedLockService taskDistributedLockService;
|
||||
|
||||
private FileTaskEntity loadTaskForExecution(Long taskId) {
|
||||
Map<Long, FileTaskEntity> cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(List.of(taskId));
|
||||
@@ -239,8 +241,16 @@ public class PriceTrackTaskService {
|
||||
throw new BusinessException("记录不存在");
|
||||
}
|
||||
Long taskId = entity.getTaskId();
|
||||
fileResultMapper.deleteById(resultId);
|
||||
if (taskId != null && taskId > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -281,10 +291,18 @@ public class PriceTrackTaskService {
|
||||
FileTaskEntity task = loadTaskForExecution(fr.getTaskId());
|
||||
if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) continue;
|
||||
if (!"RUNNING".equals(task.getStatus())) continue;
|
||||
fileResultMapper.deleteById(fr.getId());
|
||||
reconcileTaskAfterResultRemoval(fr.getTaskId());
|
||||
vo.setRemoved(true);
|
||||
return vo;
|
||||
try (TaskDistributedLockService.LockHandle ignored = acquireTaskLock(fr.getTaskId())) {
|
||||
if (ignored == null) continue;
|
||||
FileTaskEntity lockedTask = loadTaskForExecution(fr.getTaskId());
|
||||
if (lockedTask == null || !MODULE_TYPE.equals(lockedTask.getModuleType()) || !userId.equals(lockedTask.getUserId())) continue;
|
||||
if (!"RUNNING".equals(lockedTask.getStatus())) continue;
|
||||
FileResultEntity lockedResult = fileResultMapper.selectById(fr.getId());
|
||||
if (lockedResult == null || !MODULE_TYPE.equals(lockedResult.getModuleType())) continue;
|
||||
fileResultMapper.deleteById(fr.getId());
|
||||
reconcileTaskAfterResultRemoval(fr.getTaskId());
|
||||
vo.setRemoved(true);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
@@ -687,6 +705,15 @@ public class PriceTrackTaskService {
|
||||
throw new BusinessException("结果文件载荷不存在");
|
||||
}
|
||||
assembleShopResult(result, job.getScopeKey(), payload);
|
||||
FileTaskEntity task = loadTaskForExecution(job.getTaskId());
|
||||
if (task != null && MODULE_TYPE.equals(task.getModuleType())) {
|
||||
List<FileResultEntity> latest = fileResultMapper.selectList(
|
||||
new LambdaQueryWrapper<FileResultEntity>()
|
||||
.eq(FileResultEntity::getTaskId, job.getTaskId())
|
||||
.eq(FileResultEntity::getModuleType, MODULE_TYPE)
|
||||
.orderByAsc(FileResultEntity::getId));
|
||||
updateTaskStatusFromLatestRows(task, latest);
|
||||
}
|
||||
}
|
||||
|
||||
private void enqueueResultFileAssembly(FileResultEntity result,
|
||||
@@ -1280,10 +1307,20 @@ public class PriceTrackTaskService {
|
||||
int fail = 0;
|
||||
List<String> allErrors = new ArrayList<>();
|
||||
boolean allDone = true;
|
||||
Map<Long, TaskFileJobEntity> jobMap = taskFileJobService.findAssembleJobsByResultIds(
|
||||
MODULE_TYPE,
|
||||
latest.stream()
|
||||
.map(FileResultEntity::getId)
|
||||
.filter(id -> id != null && id > 0)
|
||||
.toList());
|
||||
for (FileResultEntity fr : latest) {
|
||||
boolean success = fr.getSuccess() != null && fr.getSuccess() == 1;
|
||||
boolean failed = fr.getErrorMessage() != null && !fr.getErrorMessage().isBlank();
|
||||
if (success) {
|
||||
if (isResultAwaitingFileAssembly(fr, jobMap.get(fr.getId()))) {
|
||||
allDone = false;
|
||||
continue;
|
||||
}
|
||||
ok++;
|
||||
} else if (failed) {
|
||||
fail++;
|
||||
@@ -1327,6 +1364,34 @@ public class PriceTrackTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isResultAwaitingFileAssembly(FileResultEntity result, TaskFileJobEntity job) {
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
if (result.getResultFileUrl() != null && !result.getResultFileUrl().isBlank()) {
|
||||
return false;
|
||||
}
|
||||
if (result.getResultFilename() == null || result.getResultFilename().isBlank()) {
|
||||
return false;
|
||||
}
|
||||
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 cleanupTaskCacheIfTerminal(Long taskId, String taskStatus) {
|
||||
if (!"SUCCESS".equals(taskStatus) && !"FAILED".equals(taskStatus) && !"DELETE_EMPTY".equals(taskStatus)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user