This commit is contained in:
2026-10-09 17:36:24 +08:00
parent 74bf0e73c5
commit 261cdc87cb
27 changed files with 636 additions and 45 deletions
@@ -0,0 +1,31 @@
package com.baiyue.lastleg.service;
import com.baiyue.lastleg.dto.CustomerOrderProgress;
import com.baiyue.lastleg.mapper.CustomerOrderProgressMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CustomerOrderProgressService {
private final CustomerOrderProgressMapper mapper;
public CustomerOrderProgressService(CustomerOrderProgressMapper mapper) { this.mapper = mapper; }
@Transactional(readOnly=true)
public CustomerOrderProgress.Response read(long customerId) {
return new CustomerOrderProgress.Response(project(mapper.sources(Long.toString(customerId))));
}
static List<CustomerOrderProgress.Progress> project(List<CustomerOrderProgress.Source> sources) {
return sources.stream().collect(Collectors.groupingBy(CustomerOrderProgress.Source::orderId))
.entrySet().stream().map(entry -> {
long total = entry.getValue().stream().mapToLong(CustomerOrderProgress.Source::packages).sum();
long delivering = entry.getValue().stream().mapToLong(CustomerOrderProgress.Source::deliveringPackages).sum();
long scheduled = entry.getValue().stream().mapToLong(CustomerOrderProgress.Source::scheduledPackages).sum();
String stage = delivering > 0 ? "delivering" : scheduled > 0 ? "scheduled" : "none";
long covered = delivering > 0 ? delivering : scheduled;
// Equality is deliberate: duplicate or incomplete attribution must not claim full coverage.
boolean partial = total <= 0 || covered != total || entry.getValue().stream().anyMatch(s -> s.packages() <= 0);
return new CustomerOrderProgress.Progress(Long.parseLong(entry.getKey()), stage, partial);
}).filter(p -> !"none".equals(p.stage())).sorted(java.util.Comparator.comparingLong(CustomerOrderProgress.Progress::orderId)).toList();
}
}