增加rufts
This commit is contained in:
+28
-3
@@ -125,15 +125,18 @@ public class TaskResultItemService {
|
||||
String status,
|
||||
Object payload) {
|
||||
String payloadJson = writeJson(payload);
|
||||
String payloadHash = hash(payloadJson);
|
||||
String normalizedScopeKey = firstNonBlank(scopeKey, "task:" + taskId).trim();
|
||||
String normalizedItemKey = firstNonBlank(itemKey, "result:" + resultId).trim();
|
||||
String scopeHash = hash(normalizedScopeKey);
|
||||
String storedPayload = transientPayloadStorageService.storeResultItemPayload(
|
||||
moduleType, taskId, scopeHash, normalizedItemKey, payloadJson);
|
||||
String payloadHash = hash(payloadJson);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
TaskResultItemEntity existing = find(taskId, moduleType, scopeHash, normalizedItemKey);
|
||||
if (isUnchanged(existing, resultId, normalizedScopeKey, countryCode, asin, status, payloadHash)) {
|
||||
return;
|
||||
}
|
||||
String storedPayload = transientPayloadStorageService.storeResultItemPayload(
|
||||
moduleType, taskId, scopeHash, normalizedItemKey, payloadJson);
|
||||
if (existing == null) {
|
||||
TaskResultItemEntity entity = new TaskResultItemEntity();
|
||||
entity.setTaskId(taskId);
|
||||
@@ -159,6 +162,10 @@ public class TaskResultItemService {
|
||||
if (existing == null) {
|
||||
throw new BusinessException("保存任务结果明细失败");
|
||||
}
|
||||
if (isUnchanged(existing, resultId, normalizedScopeKey, countryCode, asin, status, payloadHash)) {
|
||||
transientPayloadStorageService.deleteReplacedPayloadIfNeeded(storedPayload, existing.getPayloadJson());
|
||||
return;
|
||||
}
|
||||
transientPayloadStorageService.deleteReplacedPayloadIfNeeded(existing.getPayloadJson(), storedPayload);
|
||||
taskResultItemMapper.update(null, new LambdaUpdateWrapper<TaskResultItemEntity>()
|
||||
.eq(TaskResultItemEntity::getId, existing.getId())
|
||||
@@ -172,6 +179,24 @@ public class TaskResultItemService {
|
||||
.set(TaskResultItemEntity::getUpdatedAt, now));
|
||||
}
|
||||
|
||||
private boolean isUnchanged(TaskResultItemEntity existing,
|
||||
Long resultId,
|
||||
String scopeKey,
|
||||
String countryCode,
|
||||
String asin,
|
||||
String status,
|
||||
String payloadHash) {
|
||||
if (existing == null) {
|
||||
return false;
|
||||
}
|
||||
return java.util.Objects.equals(existing.getResultId(), resultId)
|
||||
&& java.util.Objects.equals(existing.getScopeKey(), scopeKey)
|
||||
&& java.util.Objects.equals(existing.getCountryCode(), countryCode)
|
||||
&& java.util.Objects.equals(existing.getAsin(), asin)
|
||||
&& java.util.Objects.equals(existing.getStatus(), status)
|
||||
&& java.util.Objects.equals(existing.getPayloadHash(), payloadHash);
|
||||
}
|
||||
|
||||
private TaskResultItemEntity find(Long taskId, String moduleType, String scopeHash, String itemKey) {
|
||||
return taskResultItemMapper.selectOne(new LambdaQueryWrapper<TaskResultItemEntity>()
|
||||
.eq(TaskResultItemEntity::getTaskId, taskId)
|
||||
|
||||
Reference in New Issue
Block a user