-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
492 additions
and
114 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/de/focusshift/zeiterfassung/overtime/OvertimeDuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package de.focusshift.zeiterfassung.overtime; | ||
|
||
import de.focusshift.zeiterfassung.timeentry.TimeEntryDuration; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
public final class OvertimeDuration implements TimeEntryDuration { | ||
|
||
public static OvertimeDuration ZERO = new OvertimeDuration(Duration.ZERO); | ||
|
||
private final Duration value; | ||
|
||
public OvertimeDuration(Duration value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Duration value() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Duration minutes() { | ||
final long seconds = value.toSeconds(); | ||
|
||
return seconds % 60 == 0 | ||
? value | ||
: Duration.ofMinutes(value.toMinutes() + 1); | ||
} | ||
|
||
@Override | ||
public double hoursDoubleValue() { | ||
final long minutes = minutes().toMinutes(); | ||
return minutesToHours(minutes); | ||
} | ||
|
||
public OvertimeDuration plus(Duration duration) { | ||
return new OvertimeDuration(value.plus(duration)); | ||
} | ||
|
||
public OvertimeDuration plus(OvertimeDuration overtimeDuration) { | ||
return new OvertimeDuration(value.plus(overtimeDuration.value)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
OvertimeDuration that = (OvertimeDuration) o; | ||
return Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OvertimeDuration{" + | ||
"value=" + value + | ||
'}'; | ||
} | ||
|
||
private static double minutesToHours(long minutes) { | ||
return BigDecimal.valueOf(minutes).divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING).doubleValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/de/focusshift/zeiterfassung/overtime/OvertimeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.focusshift.zeiterfassung.overtime; | ||
|
||
import de.focusshift.zeiterfassung.usermanagement.UserLocalId; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
public interface OvertimeService { | ||
|
||
/** | ||
* Get accumulated overtime for all given users until the given date, exclusive. | ||
* | ||
* @param date exclusive date | ||
* @param userLocalIds users | ||
* @return accumulated overtime till the given date grouped by user | ||
*/ | ||
Map<UserLocalId, OvertimeDuration> accumulatedOvertimeToDate(LocalDate date, Collection<UserLocalId> userLocalIds); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/de/focusshift/zeiterfassung/overtime/OvertimeServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package de.focusshift.zeiterfassung.overtime; | ||
|
||
import de.focusshift.zeiterfassung.usermanagement.User; | ||
import de.focusshift.zeiterfassung.usermanagement.UserLocalId; | ||
import de.focusshift.zeiterfassung.usermanagement.UserManagementService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.time.ZoneOffset.UTC; | ||
import static java.util.stream.Collectors.groupingBy; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
@Service | ||
class OvertimeServiceImpl implements OvertimeService { | ||
|
||
private final OvertimeRepository overtimeRepository; | ||
private final UserManagementService userManagementService; | ||
|
||
OvertimeServiceImpl(OvertimeRepository overtimeRepository, UserManagementService userManagementService) { | ||
this.overtimeRepository = overtimeRepository; | ||
this.userManagementService = userManagementService; | ||
} | ||
|
||
@Override | ||
public Map<UserLocalId, OvertimeDuration> accumulatedOvertimeToDate(LocalDate date, Collection<UserLocalId> userLocalIds) { | ||
|
||
final Instant dateExclusive = date.atStartOfDay().toInstant(UTC); | ||
final Map<String, UserLocalId> localIdById = userManagementService.findAllUsersByLocalIds(userLocalIds).stream() | ||
.collect(toMap(user -> user.id().value(), User::localId)); | ||
|
||
final Map<String, List<TimeEntryBreakEntityView>> byUserIdValue = overtimeRepository.getOvertimeDurationsToDate(false, localIdById.keySet(), dateExclusive) | ||
.stream() | ||
.collect(groupingBy(TimeEntryBreakEntityView::getUserId)); | ||
|
||
return byUserIdValue.entrySet() | ||
.stream() | ||
.map(entry -> Map.entry(localIdById.get(entry.getKey()), new OvertimeDuration(toDuration(entry.getValue())))) | ||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
private Duration toDuration(List<TimeEntryBreakEntityView> views) { | ||
return views.stream().map(TimeEntryBreakEntityView::getDuration).reduce(Duration.ZERO, Duration::plus); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/de/focusshift/zeiterfassung/overtime/TimeEntryBreakEntityView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.focusshift.zeiterfassung.overtime; | ||
|
||
import java.time.Duration; | ||
|
||
interface TimeEntryBreakEntityView { | ||
|
||
String getUserId(); | ||
|
||
Duration getDuration(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/de/focusshift/zeiterfassung/report/ReportOvertimeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.focusshift.zeiterfassung.report; | ||
|
||
import java.util.List; | ||
|
||
record ReportOvertimeDto(String personName, List<Double> overtimes) { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/de/focusshift/zeiterfassung/report/ReportOvertimesDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.focusshift.zeiterfassung.report; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
record ReportOvertimesDto(List<LocalDate> dayOfWeeks, List<ReportOvertimeDto> overtimes) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.