Прогон в DEPO: у копии перевода свои REFERENCE (раньше повторялись исходные — в DEPO задваивались строки M2M-поручений)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
zuevav
2026-09-24 12:20:02 +03:00
parent d964bdb005
commit cd51722e91
+28 -12
View File
@@ -1042,9 +1042,11 @@ func depoSimulateIncoming(ctx context.Context, rc *RuntimeConfig, it *IncomingTr
}
guid := strings.ToUpper(fmt.Sprintf("%08x-%04x-4000-8000-%012x", time.Now().Unix()&0xFFFFFFFF, time.Now().UnixNano()&0xFFFF, time.Now().UnixNano()&0xFFFFFFFFFFFF))
place := rc.Snapshot().NSD.SectionID
// у копии — свои REFERENCE: иначе в DEPO появляются M2M-поручения с одинаковым номером строки (задвоение)
ref := depoSimRefs(guid, it.Securities)
var lines []depoLine
for _, s := range it.Securities {
lines = append(lines, depoLine{Ref: s.ReferenceID, ISIN: s.ISIN, Code: s.SecurityCode, Amount: parseQty(s.Quantity), Place: place})
lines = append(lines, depoLine{Ref: ref[s.ReferenceID], ISIN: s.ISIN, Code: s.SecurityCode, Amount: parseQty(s.Quantity), Place: place})
}
cp := handbookNameByCode(it.SenderCode)
if !depoUpsertOrder(rc, guid, "IN", it.SenderCode, name, strings.TrimSpace(ser+" "+num), ser, num, lines, "ТЕСТ по образцу "+shortGUID(it.GUID)+": входящий от "+it.SenderCode+" "+cp+", реальный клиент") {
@@ -1052,19 +1054,19 @@ func depoSimulateIncoming(ctx context.Context, rc *RuntimeConfig, it *IncomingTr
}
now := time.Now()
for _, s := range it.Securities {
depoEventAt(rc, now, guid, s.ReferenceID, "BJ_RECEIVED", "", "")
depoEventAt(rc, now, guid, ref[s.ReferenceID], "BJ_RECEIVED", "", "")
}
anyConfirmed := false
for _, s := range it.Securities {
switch s.Decision {
case "confirmed":
anyConfirmed = true
depoEventAt(rc, now.Add(time.Minute), guid, s.ReferenceID, "BJ_DECISION_CONFIRM", "", "")
depoEventAt(rc, now.Add(time.Minute), guid, ref[s.ReferenceID], "BJ_DECISION_CONFIRM", "", "")
case "rejected":
depoEventAt(rc, now.Add(time.Minute), guid, s.ReferenceID, "BJ_DECISION_REJECT", s.RejectCode, m2mCodeLabel(s.RejectCode))
depoEventAt(rc, now.Add(time.Minute), guid, ref[s.ReferenceID], "BJ_DECISION_REJECT", s.RejectCode, m2mCodeLabel(s.RejectCode))
default:
anyConfirmed = true
depoEventAt(rc, now.Add(time.Minute), guid, s.ReferenceID, "BJ_DECISION_CONFIRM", "", "")
depoEventAt(rc, now.Add(time.Minute), guid, ref[s.ReferenceID], "BJ_DECISION_CONFIRM", "", "")
}
}
// Исходы — по строкам (REFERENCE), как в бою: по каждой принятой бумаге своё поручение.
@@ -1073,9 +1075,9 @@ func depoSimulateIncoming(ctx context.Context, rc *RuntimeConfig, it *IncomingTr
if s.Decision == "rejected" {
continue
}
depoEventAt(rc, now.Add(2*time.Minute), guid, s.ReferenceID, "BJ_ORDER_SENT", "", "")
depoEventAt(rc, now.Add(3*time.Minute), guid, s.ReferenceID, "BJ_ORDER_ACCEPTED", "", "")
depoEventAt(rc, now.Add(3*time.Minute), guid, s.ReferenceID, "BJ_EXECUTED", "", "")
depoEventAt(rc, now.Add(2*time.Minute), guid, ref[s.ReferenceID], "BJ_ORDER_SENT", "", "")
depoEventAt(rc, now.Add(3*time.Minute), guid, ref[s.ReferenceID], "BJ_ORDER_ACCEPTED", "", "")
depoEventAt(rc, now.Add(3*time.Minute), guid, ref[s.ReferenceID], "BJ_EXECUTED", "", "")
}
}
return guid, nil
@@ -1110,9 +1112,13 @@ func depoSimulateOutgoing(ctx context.Context, rc *RuntimeConfig, svc *Service,
req := d.Request
guid := strings.ToUpper(fmt.Sprintf("%08x-%04x-4000-8000-%012x", time.Now().Unix()&0xFFFFFFFF, time.Now().UnixNano()&0xFFFF, time.Now().UnixNano()&0xFFFFFFFFFFFF))
place := rc.Snapshot().NSD.SectionID
newRef := map[string]string{}
for k, s := range req.Data.TransferredSecurities.Securities {
newRef[string(s.ReferenceID)] = fmt.Sprintf("M2MS%s%02d", guid[:8], k+1)
}
var lines []depoLine
for _, s := range req.Data.TransferredSecurities.Securities {
lines = append(lines, depoLine{Ref: string(s.ReferenceID), ISIN: quikSecISIN(s), Code: string(s.SecurityCode), Amount: quikSecQty(s.Quantity), Place: place})
lines = append(lines, depoLine{Ref: newRef[string(s.ReferenceID)], ISIN: quikSecISIN(s), Code: string(s.SecurityCode), Amount: quikSecQty(s.Quantity), Place: place})
}
inn := string(req.Data.ReceivingDepository.INN)
cp := handbookCodeByINN(inn)
@@ -1130,12 +1136,13 @@ func depoSimulateOutgoing(ctx context.Context, rc *RuntimeConfig, svc *Service,
}
}
for _, s := range req.Data.TransferredSecurities.Securities {
ref := string(s.ReferenceID)
ref := newRef[string(s.ReferenceID)]
orig := string(s.ReferenceID)
depoEventAt(rc, now, guid, ref, "BJ_SENT", "", "")
if rejected[ref] {
if rejected[orig] {
var codes []string
for _, sec := range d.Decision.Data.Securities {
if string(sec.ReferenceID) == ref && sec.TransferDecision.Rejection != nil {
if string(sec.ReferenceID) == orig && sec.TransferDecision.Rejection != nil {
codes = sec.TransferDecision.Rejection.Codes
}
}
@@ -1150,3 +1157,12 @@ func depoSimulateOutgoing(ctx context.Context, rc *RuntimeConfig, svc *Service,
}
return guid, nil
}
// depoSimRefs — новые REFERENCE для копии входящего (уникальны в DEPO: M2MS + начало GUID + №).
func depoSimRefs(guid string, secs []IncomingSecurity) map[string]string {
m := map[string]string{}
for k, s := range secs {
m[s.ReferenceID] = fmt.Sprintf("M2MS%s%02d", guid[:8], k+1)
}
return m
}