NewAttendanceSummariesCompute
Function
Overview
The NewAttendanceSummariesCompute
function is responsible for creating new attendance summaries based on calendar schedules and shifts. It does not recalculate existing summaries but instead generates them using provided basic information, including schedules, shifts, flags, and holidays. If the necessary calendar schedule does not exist, the function triggers its creation.
Function Signature
func NewAttendanceSummariesCompute(
curUser *entity.UserProfileTable,
calcDate string,
force, cacheFollowForce bool,
cache *caching.AllCacheStruct,
) []AttendanceSummariesCompute
Parameters
Parameter | Type | Description |
---|---|---|
curUser | *entity.UserProfileTable | The user profile for which the attendance summaries are to be generated. |
calcDate | string | The date for which attendance summaries should be computed. |
force | bool | Whether to force the creation or recalculation of the calendar schedule. |
cacheFollowForce | bool | Whether cache operations should follow the force flag. |
cache | *caching.AllCacheStruct | Cached data structure to optimize data access during computation. |
Returns
[]AttendanceSummariesCompute
:
A slice of attendance summaries computed for the given user and date.
Workflow
-
Fetch Calendar Schedule
- Invokes
getCalendarSchedule
with the provided parameters to retrieve the calendar schedule. - If the schedule does not exist, it triggers the schedule creation.
- Invokes
-
Process Calendar Schedule
- If the calendar schedule exists:
- Iterates through the
CalendarScheduleDetails
of the fetched schedule. - For each valid (non-deleted) detail, creates an attendance summary using
createSummaryFromCalendarDetail
.
- Iterates through the
- If the calendar schedule exists:
-
Return Results
- Returns a slice of attendance summaries generated from the schedule details.
Key Operations
-
Logging and Timing
- Prints elapsed time for key operations, such as fetching the calendar schedule and creating summaries, for performance monitoring.
-
Conditional Logic
- Ensures that only valid (non-deleted) calendar details are processed.
Example Usage
curUser := &entity.UserProfileTable{ID: 1, Name: "John Doe"}
calcDate := "2024-12-01"
force := true
cacheFollowForce := false
cache := &caching.AllCacheStruct{}
attendanceSummaries := NewAttendanceSummariesCompute(curUser, calcDate, force, cacheFollowForce, cache)
for _, summary := range attendanceSummaries {
fmt.Println(summary)
}
Notes
- The function assumes that
getCalendarSchedule
andcreateSummaryFromCalendarDetail
are properly implemented and handle their respective tasks. - The logic relies on
CalendarScheduleDetails[idx].DeleteThis
to exclude unwanted details. Ensure this field is accurately set in the data source. - Performance optimizations rely heavily on the caching mechanism. The
cache
parameter must be properly initialized to maximize efficiency.