From 2ffba3aa3251450585e95fdd253446f2e17eb66e Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Tue, 19 Aug 2025 12:09:25 +0330 Subject: [PATCH] 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. --- ted/scraper.go | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/ted/scraper.go b/ted/scraper.go index 84e05b8..0c8c998 100644 --- a/ted/scraper.go +++ b/ted/scraper.go @@ -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)