contractNoticeID duplication fix

This commit is contained in:
Mazyar
2026-05-13 13:18:26 +03:30
parent 83c8ece91f
commit ba9e7483ad
2 changed files with 20 additions and 4 deletions
+17 -4
View File
@@ -575,10 +575,16 @@ func (w *NoticeWorker) ToTender(n *notice.Notice) (*tender.Tender, error) {
return t, nil
}
// resolveExistingTender finds the tender that this notice should update, preferring the procedure-level
// ContractFolderID (so follow-up notices like a Result for an earlier Competition notice merge into the
// same tender), then UBL ProcurementProject/ID (merges per-lot CAN/CN notices), then NoticePublicationID.
// resolveExistingTender finds the tender that this notice should update. TED ContractNoticeID uniquely
// identifies the notice document; try it first so we never open a second tender row for the same notice.
// Then procedure-level ContractFolderID (follow-up notices merge), UBL ProcurementProject/ID (per-lot),
// then NoticePublicationID.
func (w *NoticeWorker) resolveExistingTender(ctx context.Context, n *notice.Notice) *tender.Tender {
if strings.TrimSpace(n.ContractNoticeID) != "" {
if t, err := w.TenderRepo.GetByContractNoticeID(ctx, n.ContractNoticeID); err == nil && t != nil {
return t
}
}
if strings.TrimSpace(n.ContractFolderID) != "" {
if t, err := w.TenderRepo.GetByContractFolderID(ctx, n.ContractFolderID); err == nil && t != nil {
return t
@@ -998,7 +1004,7 @@ func (w *NoticeWorker) persistTender(ctx context.Context, t *tender.Tender, n *n
lastErr = err
// Another goroutine inserted the same procedure/publication first: merge into the winner row.
if isDuplicateKeyError(err) && (isDuplicateTenderBusinessKeyError(err) || isDuplicateContractFolderIDKeyError(err) || isDuplicateProcurementProjectIDKeyError(err)) {
if isDuplicateKeyError(err) && (isDuplicateTenderBusinessKeyError(err) || isDuplicateContractNoticeIDKeyError(err) || isDuplicateContractFolderIDKeyError(err) || isDuplicateProcurementProjectIDKeyError(err)) {
tMerged, convErr := w.ToTender(n)
if convErr != nil {
return convErr
@@ -1062,6 +1068,13 @@ func isDuplicateTenderBusinessKeyError(err error) bool {
return strings.Contains(msg, "notice_publication_id")
}
func isDuplicateContractNoticeIDKeyError(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), "contract_notice_id")
}
func isDuplicateContractFolderIDKeyError(err error) bool {
if err == nil {
return false