+101
@@ -815,11 +815,112 @@ public class PriceTrackTaskService {
|
||||
private void enqueueResultFileAssembly(FileResultEntity result,
|
||||
String shopKey,
|
||||
PriceTrackSubmitResultRequest.ShopResult payload) {
|
||||
applyServerModifyCounts(result.getTaskId(), payload);
|
||||
taskResultPayloadService.saveLatest(result.getTaskId(), MODULE_TYPE, shopKey, payload);
|
||||
markResultFilePending(result, shopKey, payload);
|
||||
taskFileJobService.enqueueAssembleResult(result.getTaskId(), MODULE_TYPE, result.getId(), shopKey);
|
||||
}
|
||||
|
||||
private void applyServerModifyCounts(
|
||||
Long taskId,
|
||||
PriceTrackSubmitResultRequest.ShopResult payload) {
|
||||
if (payload == null || payload.getCountries() == null || payload.getCountries().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<String, Integer> baselineByAsin = buildModifyCountBaseline(taskId);
|
||||
for (Map.Entry<String, List<PriceTrackSubmitResultRequest.AsinResult>> entry : payload.getCountries().entrySet()) {
|
||||
String countryCode = normalizeCountryCode(entry.getKey());
|
||||
if (entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
for (PriceTrackSubmitResultRequest.AsinResult row : entry.getValue()) {
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String asin = normalizeAsin(row.getAsin());
|
||||
int baseline = baselineByAsin.getOrDefault(buildModifyCountKey(countryCode, asin), 0);
|
||||
row.setModifyCount(String.valueOf(addOneIfChanged(baseline, row)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Integer> buildModifyCountBaseline(Long taskId) {
|
||||
Map<String, List<Map<String, String>>> originalRows = loadTaskAsinRowsPayload(taskId);
|
||||
if (originalRows == null || originalRows.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, Integer> out = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, List<Map<String, String>>> entry : originalRows.entrySet()) {
|
||||
String countryCode = normalizeCountryCode(entry.getKey());
|
||||
if (entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
for (Map<String, String> row : entry.getValue()) {
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String asin = normalizeAsin(row.get("asin"));
|
||||
if (asin.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
out.putIfAbsent(
|
||||
buildModifyCountKey(countryCode, asin),
|
||||
parseModifyCountBaseline(row.get("modifyCount")));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private String buildModifyCountKey(String countryCode, String asin) {
|
||||
return countryCode + "|" + asin;
|
||||
}
|
||||
|
||||
private String normalizeCountryCode(String countryCode) {
|
||||
return countryCode == null ? "" : countryCode.trim().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private String normalizeAsin(String asin) {
|
||||
return asin == null ? "" : asin.trim().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private int parseModifyCountBaseline(String value) {
|
||||
String normalized = normalizeCellText(value);
|
||||
if (normalized.isBlank()) {
|
||||
return 0;
|
||||
}
|
||||
int decimalPoint = normalized.indexOf('.');
|
||||
if (decimalPoint >= 0) {
|
||||
for (int i = decimalPoint + 1; i < normalized.length(); i++) {
|
||||
if (normalized.charAt(i) != '0') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
normalized = normalized.substring(0, decimalPoint);
|
||||
}
|
||||
try {
|
||||
long parsed = Long.parseLong(normalized);
|
||||
if (parsed <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return parsed > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) parsed;
|
||||
} catch (NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int addOneIfChanged(int baseline, PriceTrackSubmitResultRequest.AsinResult row) {
|
||||
if (!isPriceUpdateSuccessStatus(row.getPriceChangeStatus())) {
|
||||
return baseline;
|
||||
}
|
||||
return baseline >= Integer.MAX_VALUE ? Integer.MAX_VALUE : baseline + 1;
|
||||
}
|
||||
|
||||
private boolean isPriceUpdateSuccessStatus(String value) {
|
||||
String normalized = normalizeCellText(value);
|
||||
return "\u6539\u4ef7\u6210\u529f".equals(normalized)
|
||||
|| "UPDATED".equalsIgnoreCase(normalized);
|
||||
}
|
||||
|
||||
private void markResultFilePending(FileResultEntity result,
|
||||
String shopKey,
|
||||
PriceTrackSubmitResultRequest.ShopResult payload) {
|
||||
|
||||
Reference in New Issue
Block a user