Refactor Tender ID Generation Logic in TED Scraper
- Updated the `generateTenderID` method to improve the structure and clarity of the tender ID generation process. - Changed the source identifier from "TED" to "1" for consistency. - Modified the handling of the Notice Publication ID, ensuring it is used correctly in the tender ID. - Simplified the buyer code logic by commenting out the previous implementation, focusing on the essential components. - Adjusted the date and location code handling to enhance clarity and maintainability, ensuring adherence to Clean Architecture principles.
This commit is contained in:
+14
-19
@@ -1196,34 +1196,29 @@ func (s *TEDScraper) generateTenderID(t *tender.Tender) string {
|
||||
var parts []string
|
||||
|
||||
// Source (TED)
|
||||
parts = append(parts, "TED")
|
||||
parts = append(parts, "1")
|
||||
|
||||
// Buyer code (first 8 chars of buyer organization ID, or 8 zeros if not available)
|
||||
buyerCode := "00000000"
|
||||
if t.BuyerOrganization != nil && t.BuyerOrganization.ID != "" {
|
||||
buyerCode = s.padOrTruncate(t.BuyerOrganization.ID, 8)
|
||||
}
|
||||
parts = append(parts, buyerCode)
|
||||
|
||||
// TED code (Contract Notice ID, first 8 chars)
|
||||
// TED code (Notice Publication ID, first 8 chars)
|
||||
tedCode := "00000000"
|
||||
if t.ContractNoticeID != "" {
|
||||
tedCode = s.padOrTruncate(t.ContractNoticeID, 8)
|
||||
if t.NoticePublicationID != "" {
|
||||
tedCode = s.padOrTruncate(t.NoticePublicationID, 8)
|
||||
}
|
||||
parts = append(parts, tedCode)
|
||||
|
||||
// Buyer code (first 8 chars of buyer organization ID, or 8 zeros if not available)
|
||||
// buyerCode := "00000000"
|
||||
// if t.BuyerOrganization != nil && t.BuyerOrganization.ID != "" {
|
||||
// buyerCode = s.padOrTruncate(t.BuyerOrganization.ID, 8)
|
||||
// }
|
||||
// parts = append(parts, buyerCode)
|
||||
|
||||
// Date (YYYYMMDD format from issue date)
|
||||
dateCode := s.unixMilliToDateString(t.IssueDate)
|
||||
parts = append(parts, dateCode)
|
||||
parts = append(parts, s.padOrTruncate(s.unixMilliToDateString(t.IssueDate), 4))
|
||||
|
||||
// Location code (country code + region code, padded to 6 chars)
|
||||
locationCode := "000000"
|
||||
locationCode := "EURO"
|
||||
if t.CountryCode != "" {
|
||||
location := t.CountryCode
|
||||
if t.RegionCode != "" {
|
||||
location += t.RegionCode
|
||||
}
|
||||
locationCode = s.padOrTruncate(location, 6)
|
||||
locationCode = t.CountryCode
|
||||
}
|
||||
parts = append(parts, locationCode)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user