From cd51722e91b9c6ae82679e7505fdcc6cbd6047aa Mon Sep 17 00:00:00 2001 From: zuevav Date: Thu, 24 Sep 2026 12:20:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B3=D0=BE=D0=BD=20=D0=B2?= =?UTF-8?q?=20DEPO:=20=D1=83=20=D0=BA=D0=BE=D0=BF=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=B0=20=D1=81=D0=B2=D0=BE?= =?UTF-8?q?=D0=B8=20REFERENCE=20(=D1=80=D0=B0=D0=BD=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D1=8F=D0=BB=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=E2=80=94=20=D0=B2=20DEPO=20=D0=B7=D0=B0=D0=B4=D0=B2=D0=B0?= =?UTF-8?q?=D0=B8=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20M2M-=D0=BF=D0=BE=D1=80=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- internal/lkgateway/depoevents.go | 40 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/internal/lkgateway/depoevents.go b/internal/lkgateway/depoevents.go index 83f972b..edb6b60 100644 --- a/internal/lkgateway/depoevents.go +++ b/internal/lkgateway/depoevents.go @@ -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 +}