db14bfe270
continuous-integration/drone/push Build is passing
- Introduced `ProcedureReference` struct to encapsulate AI procedure coordinates for better data management. - Added `GetByProcedureReferences` method in the `TenderRepository` to retrieve multiple tenders based on AI procedure references in a single query. - Updated the `resolveRecommendedTenders` method in the service layer to utilize the new repository method, improving efficiency in fetching recommended tenders. - Enhanced error handling and logging for the new repository method to ensure robust operation. This update improves the handling of AI procedure references, streamlining tender retrieval processes and enhancing overall system performance.
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package tender
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
)
|
|
|
|
const aiProcedurePrefix = "PROC_"
|
|
|
|
// FormatAIProcedureRef builds the AI service tender reference:
|
|
// PROC_{contract_folder_id}/{notice_publication_id}
|
|
func FormatAIProcedureRef(contractFolderID, noticePublicationID string) string {
|
|
contractFolderID = strings.TrimSpace(contractFolderID)
|
|
noticePublicationID = strings.TrimSpace(noticePublicationID)
|
|
if contractFolderID == "" || noticePublicationID == "" {
|
|
return ""
|
|
}
|
|
return aiProcedurePrefix + contractFolderID + "/" + noticePublicationID
|
|
}
|
|
|
|
// ProcedureReference identifies a tender using AI procedure coordinates.
|
|
type ProcedureReference struct {
|
|
Ref string
|
|
ContractFolderID string
|
|
NoticePublicationID string
|
|
}
|
|
|
|
// ParseAIProcedureRef parses PROC_{contract_folder_id}/{notice_publication_id}.
|
|
func ParseAIProcedureRef(ref string) (contractFolderID, noticePublicationID string, ok bool) {
|
|
ref = strings.TrimSpace(ref)
|
|
if ref == "" {
|
|
return "", "", false
|
|
}
|
|
|
|
withoutPrefix := ref
|
|
if len(ref) >= len(aiProcedurePrefix) && strings.EqualFold(ref[:len(aiProcedurePrefix)], aiProcedurePrefix) {
|
|
withoutPrefix = ref[len(aiProcedurePrefix):]
|
|
}
|
|
|
|
slash := strings.Index(withoutPrefix, "/")
|
|
if slash <= 0 || slash >= len(withoutPrefix)-1 {
|
|
return "", "", false
|
|
}
|
|
|
|
contractFolderID = strings.TrimSpace(withoutPrefix[:slash])
|
|
noticePublicationID = strings.TrimSpace(withoutPrefix[slash+1:])
|
|
if contractFolderID == "" || noticePublicationID == "" {
|
|
return "", "", false
|
|
}
|
|
|
|
return contractFolderID, noticePublicationID, true
|
|
}
|
|
|
|
func tenderMatchesProcedureRef(t Tender, contractFolderID, noticePublicationID string) bool {
|
|
if strings.TrimSpace(t.ContractFolderID) != strings.TrimSpace(contractFolderID) {
|
|
return false
|
|
}
|
|
if t.NoticePublicationID == noticePublicationID {
|
|
return true
|
|
}
|
|
for _, related := range t.RelatedNoticePublicationIDs {
|
|
if related == noticePublicationID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsMongoObjectIDRef reports whether ref is a 24-char hex MongoDB ObjectId.
|
|
func IsMongoObjectIDRef(ref string) bool {
|
|
ref = strings.TrimSpace(ref)
|
|
if len(ref) != 24 {
|
|
return false
|
|
}
|
|
_, err := bson.ObjectIDFromHex(ref)
|
|
return err == nil
|
|
}
|