Refactor TED Calendar and EForm Structure for Enhanced Functionality
- Updated the GetOJS function to accept a base URL parameter, improving flexibility in constructing the calendar URL. - Removed the deprecated eform.go file, streamlining the codebase by eliminating unused components. - Introduced new eform structures for BusinessRegistrationInformationNotice, ContractNotice, ContractAwardNotice, and PriorInformationNotice, enhancing the handling of TED XML data. - Implemented mapping functions to convert eform notices to the Tender entity, improving integration with the tender management system. - Added a service layer to encapsulate business logic related to eform processing, adhering to Clean Architecture principles.
This commit is contained in:
+4
-102
@@ -283,7 +283,7 @@ func (s *TEDScraper) processXMLContent(ctx context.Context, content []byte, file
|
||||
})
|
||||
|
||||
// Parse XML using the flexible TED parser that detects notice type
|
||||
_, id, noticeType, err := s.xmlParser.Parse(content)
|
||||
notice, id, noticeType, err := s.xmlParser.Parse(content)
|
||||
if err != nil {
|
||||
s.logger.Error("XML parsing failed", map[string]interface{}{
|
||||
"file_name": fileName,
|
||||
@@ -293,6 +293,8 @@ func (s *TEDScraper) processXMLContent(ctx context.Context, content []byte, file
|
||||
return fmt.Errorf("failed to parse XML: %w", err)
|
||||
}
|
||||
|
||||
_ = notice
|
||||
|
||||
// Log detailed parsed information based on notice type
|
||||
s.logger.Info("Successfully parsed notice", map[string]interface{}{
|
||||
"notice_id": id,
|
||||
@@ -311,7 +313,7 @@ func (s *TEDScraper) Run(ctx context.Context) error {
|
||||
})
|
||||
|
||||
// get ojs
|
||||
ojs, err := GetOJS(now.Year(), now.Format("02/01/2006"))
|
||||
ojs, err := GetOJS(s.config.BaseURL, now.Year(), now.Format("02/01/2006"))
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get OJS", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -337,103 +339,3 @@ func (s *TEDScraper) Run(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseDate parses various date formats used in TED XML
|
||||
func (s *TEDScraper) parseDate(dateStr string) (time.Time, error) {
|
||||
if dateStr == "" {
|
||||
return time.Time{}, fmt.Errorf("empty date string")
|
||||
}
|
||||
|
||||
// Common TED date formats
|
||||
formats := []string{
|
||||
"2006-01-02+07:00",
|
||||
"2006-01-02-07:00",
|
||||
"2006-01-02T15:04:05+07:00",
|
||||
"2006-01-02T15:04:05-07:00",
|
||||
"2006-01-02T15:04:05Z",
|
||||
"2006-01-02Z",
|
||||
"2006-01-02",
|
||||
time.RFC3339,
|
||||
time.RFC3339Nano,
|
||||
}
|
||||
|
||||
for _, format := range formats {
|
||||
if parsedTime, err := time.Parse(format, dateStr); err == nil {
|
||||
return parsedTime, nil
|
||||
}
|
||||
}
|
||||
|
||||
return time.Time{}, fmt.Errorf("unable to parse date: %s", dateStr)
|
||||
}
|
||||
|
||||
// parseDateToUnixMilli converts string date to Unix milliseconds (int64)
|
||||
func (s *TEDScraper) parseDateToUnixMilli(dateStr string) int64 {
|
||||
if dateStr == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
if parsedTime, err := s.parseDate(dateStr); err == nil {
|
||||
return parsedTime.UnixMilli()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// parseTimeToUnixMilli converts string time to Unix milliseconds (int64)
|
||||
func (s *TEDScraper) parseTimeToUnixMilli(timeStr string) int64 {
|
||||
if timeStr == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
// If time string is just time without date, use today's date
|
||||
if !strings.Contains(timeStr, "T") && !strings.Contains(timeStr, " ") {
|
||||
// Assume it's just a time like "15:04:05"
|
||||
today := time.Now().Format("2006-01-02")
|
||||
timeStr = fmt.Sprintf("%sT%s", today, timeStr)
|
||||
}
|
||||
|
||||
if parsedTime, err := s.parseDate(timeStr); err == nil {
|
||||
return parsedTime.UnixMilli()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// unixMilliToDateString converts Unix milliseconds to date string for TenderID generation
|
||||
func (s *TEDScraper) unixMilliToDateString(unixMilli int64) string {
|
||||
if unixMilli == 0 {
|
||||
return "00000000"
|
||||
}
|
||||
|
||||
return time.UnixMilli(unixMilli).Format("20060102")
|
||||
}
|
||||
|
||||
func (s *TEDScraper) calculateSubmissionDeadline(publicationDate time.Time) time.Time {
|
||||
deadline := publicationDate
|
||||
workingHoursAdded := 0
|
||||
|
||||
for workingHoursAdded < 48 {
|
||||
deadline = deadline.Add(1 * time.Hour)
|
||||
|
||||
if deadline.Weekday() != time.Saturday && deadline.Weekday() != time.Sunday {
|
||||
workingHoursAdded++
|
||||
}
|
||||
}
|
||||
|
||||
return deadline
|
||||
}
|
||||
|
||||
func (s *TEDScraper) calculateApplicationDeadline(tenderDeadline time.Time) time.Time {
|
||||
applicationDeadline := tenderDeadline
|
||||
workingDaysSubtracted := 0
|
||||
|
||||
for workingDaysSubtracted < 7 {
|
||||
applicationDeadline = applicationDeadline.AddDate(0, 0, -1)
|
||||
|
||||
if applicationDeadline.Weekday() != time.Saturday && applicationDeadline.Weekday() != time.Sunday {
|
||||
workingDaysSubtracted++
|
||||
}
|
||||
}
|
||||
|
||||
return applicationDeadline
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user