feat: Start sample numbering at 10000 for each veterinarian
- Add findTopByOwnerAccountIdOrderBySampleNumberDesc to SampleRepository - Modify nextSampleNumber to accept ownerAccountId parameter - Calculate next sample number per user based on ownerAccountId - Update dashboardOverview and createSample to use user-specific numbering
This commit is contained in:
@@ -12,6 +12,8 @@ public interface SampleRepository extends MongoRepository<Sample, String> {
|
||||
|
||||
Optional<Sample> findTopByOrderBySampleNumberDesc();
|
||||
|
||||
Optional<Sample> findTopByOwnerAccountIdOrderBySampleNumberDesc(String ownerAccountId);
|
||||
|
||||
List<Sample> findTop12ByOrderByUpdatedAtDesc();
|
||||
|
||||
List<Sample> findByFarmerBusinessKeyOrderByCreatedAtDesc(String farmerBusinessKey);
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -67,7 +68,8 @@ public class SampleService {
|
||||
.filter(sample -> !sample.completedAt().isBefore(today.atStartOfDay()))
|
||||
.filter(sample -> sample.completedAt().isBefore(today.plusDays(1).atStartOfDay()))
|
||||
.count();
|
||||
return new DashboardOverview(nextSampleNumber(), openCount, completedToday, recent);
|
||||
String ownerAccountId = authorizationService.accountId(actor);
|
||||
return new DashboardOverview(nextSampleNumber(ownerAccountId), openCount, completedToday, recent);
|
||||
}
|
||||
|
||||
public LookupResult lookup(String actorId, long sampleNumber) {
|
||||
@@ -104,9 +106,10 @@ public class SampleService {
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "Landwirt nicht gefunden"));
|
||||
|
||||
String ownerAccountId = authorizationService.accountId(actor);
|
||||
Sample sample = new Sample(
|
||||
null,
|
||||
nextSampleNumber(),
|
||||
nextSampleNumber(ownerAccountId),
|
||||
farmer.businessKey(),
|
||||
farmer.name(),
|
||||
farmer.email(),
|
||||
@@ -513,9 +516,19 @@ public class SampleService {
|
||||
}
|
||||
|
||||
public long nextSampleNumber() {
|
||||
return nextSampleNumber(null);
|
||||
}
|
||||
|
||||
public long nextSampleNumber(String ownerAccountId) {
|
||||
if (ownerAccountId != null) {
|
||||
Optional<Sample> lastSample = sampleRepository.findTopByOwnerAccountIdOrderBySampleNumberDesc(ownerAccountId);
|
||||
if (lastSample.isPresent()) {
|
||||
return lastSample.get().sampleNumber() + 1;
|
||||
}
|
||||
}
|
||||
return sampleRepository.findTopByOrderBySampleNumberDesc()
|
||||
.map(sample -> sample.sampleNumber() + 1)
|
||||
.orElse(100001L);
|
||||
.orElse(10000L);
|
||||
}
|
||||
|
||||
public Sample loadSampleEntity(String actorId, String id) {
|
||||
|
||||
Reference in New Issue
Block a user