Split 5 oversized files (501-583 LOC each) into focused units all under 500 LOC: - license_policy.go → +_types.go (engine logic / type definitions) - models.go → +_intake.go, +_assessment.go (enums+domains / intake structs / output+DB types) - pdf_export.go → +_markdown.go (PDF export / markdown export) - escalation_store.go → +_dsb.go (main escalation ops / DSB pool ops) - obligations_registry.go → +_grouping.go (registry core / grouping methods) All files remain in package ucca. Zero behavior changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package ucca
|
|
|
|
import "time"
|
|
|
|
// ============================================================================
|
|
// Grouping Methods
|
|
// ============================================================================
|
|
|
|
// GroupByRegulation groups obligations by their regulation ID
|
|
func (r *ObligationsRegistry) GroupByRegulation(obligations []Obligation) map[string][]Obligation {
|
|
result := make(map[string][]Obligation)
|
|
for _, obl := range obligations {
|
|
result[obl.RegulationID] = append(result[obl.RegulationID], obl)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// GroupByDeadline groups obligations by deadline timeframe
|
|
func (r *ObligationsRegistry) GroupByDeadline(obligations []Obligation) ObligationsByDeadlineResponse {
|
|
result := ObligationsByDeadlineResponse{
|
|
Overdue: []Obligation{},
|
|
ThisWeek: []Obligation{},
|
|
ThisMonth: []Obligation{},
|
|
NextQuarter: []Obligation{},
|
|
Later: []Obligation{},
|
|
NoDeadline: []Obligation{},
|
|
}
|
|
|
|
now := time.Now()
|
|
oneWeek := now.AddDate(0, 0, 7)
|
|
oneMonth := now.AddDate(0, 1, 0)
|
|
threeMonths := now.AddDate(0, 3, 0)
|
|
|
|
for _, obl := range obligations {
|
|
if obl.Deadline == nil || obl.Deadline.Type != DeadlineAbsolute || obl.Deadline.Date == nil {
|
|
result.NoDeadline = append(result.NoDeadline, obl)
|
|
continue
|
|
}
|
|
|
|
deadline := *obl.Deadline.Date
|
|
switch {
|
|
case deadline.Before(now):
|
|
result.Overdue = append(result.Overdue, obl)
|
|
case deadline.Before(oneWeek):
|
|
result.ThisWeek = append(result.ThisWeek, obl)
|
|
case deadline.Before(oneMonth):
|
|
result.ThisMonth = append(result.ThisMonth, obl)
|
|
case deadline.Before(threeMonths):
|
|
result.NextQuarter = append(result.NextQuarter, obl)
|
|
default:
|
|
result.Later = append(result.Later, obl)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// GroupByResponsible groups obligations by responsible role
|
|
func (r *ObligationsRegistry) GroupByResponsible(obligations []Obligation) map[ResponsibleRole][]Obligation {
|
|
result := make(map[ResponsibleRole][]Obligation)
|
|
for _, obl := range obligations {
|
|
result[obl.Responsible] = append(result[obl.Responsible], obl)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// containsString checks if a slice contains a string
|
|
func containsString(slice []string, s string) bool {
|
|
for _, item := range slice {
|
|
if item == s {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|