Enhance Tender Management with Company-Based Matching and API Updates
- Updated the tender service to include company-based matching for tenders, allowing for more relevant results based on company CPV codes. - Modified the ListTenders endpoint to accept a company ID parameter for calculating match percentages and sorting tenders accordingly. - Refactored the tender response structure to include match percentage and days until deadline for better client-side handling. - Updated API documentation to reflect changes in the tender listing functionality and added new endpoints for public tender access. - Removed deprecated customer-related methods and streamlined customer listing functionality for improved clarity and performance.
This commit is contained in:
@@ -416,3 +416,62 @@ func (s *ScrapingState) MarkAsCompleted(year, number int) {
|
||||
s.NextRunAt = time.Now().Add(4 * time.Hour).Unix() // Schedule next run in 4 hours
|
||||
s.UpdatedAt = time.Now().Unix()
|
||||
}
|
||||
|
||||
// CalculateMatchPercentage calculates the match percentage between tender classifications and company CPV codes
|
||||
func (t *Tender) CalculateMatchPercentage(companyCPVCodes []string) int {
|
||||
if len(companyCPVCodes) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
mainMatch := false
|
||||
additionalMatch := false
|
||||
|
||||
// Check if main classification matches any company CPV codes
|
||||
if t.MainClassification != "" {
|
||||
for _, companyCode := range companyCPVCodes {
|
||||
if companyCode == t.MainClassification {
|
||||
mainMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any additional classification matches any company CPV codes
|
||||
if len(t.AdditionalClassifications) > 0 {
|
||||
for _, additionalCode := range t.AdditionalClassifications {
|
||||
for _, companyCode := range companyCPVCodes {
|
||||
if companyCode == additionalCode {
|
||||
additionalMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if additionalMatch {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate percentage based on matches
|
||||
if mainMatch && additionalMatch {
|
||||
return 100
|
||||
} else if mainMatch || additionalMatch {
|
||||
return 50
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetDaysUntilDeadline returns the number of days until the tender deadline
|
||||
func (t *Tender) GetDaysUntilDeadline() int {
|
||||
if t.TenderDeadline == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
if t.TenderDeadline <= now {
|
||||
return 0 // Already expired
|
||||
}
|
||||
|
||||
diffMillis := t.TenderDeadline - now
|
||||
diffDays := diffMillis / (24 * 60 * 60 * 1000)
|
||||
return int(diffDays)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user