From 1debfd81da971fa862618ec43fef17cb9de0eb8c Mon Sep 17 00:00:00 2001 From: AKurakin Date: Wed, 1 Feb 2023 20:06:23 +0300 Subject: [PATCH] =?UTF-8?q?clearing-service=20http://jira.mfd.msk:8088/bro?= =?UTF-8?q?wse/CLS-189=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20PaymentInstruction...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/order/PaymentInstructionCreator.java | 9 +++++---- .../service/order/PaymentInstructionCreatorTest.java | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/order/PaymentInstructionCreator.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/order/PaymentInstructionCreator.java index 950e3c7a3..94761ff50 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/order/PaymentInstructionCreator.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/order/PaymentInstructionCreator.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicLong; public class PaymentInstructionCreator { protected static final Long SPVB_ID = 1L; // СПВБ protected static final Long PRC_ID = 2L; // 2 "НКО АО ПРЦ" + private static final DateTimeFormatter DATE_FORMATTER_ddMMyy = DateTimeFormatter.ofPattern("ddMMyy"); private final Logger log = LoggerFactory.getLogger(getClass()); @@ -39,7 +40,7 @@ public class PaymentInstructionCreator { protected final Imdg accountImdg; protected final Imdg paymentInstructionImdg; - protected AtomicLong documentNumberId = new AtomicLong(); // порядковый номер (сквозной по всем компаниям за день + protected AtomicLong documentNumberId = new AtomicLong(0L); // порядковый номер (сквозной по всем компаниям за день protected LocalDate documentNumberResetAt; @Autowired @@ -379,7 +380,7 @@ public class PaymentInstructionCreator { protected String nextDocumentNumber(LiabilitiesClaimsAssets liabilitiesClaimsAssets, PaymentInstruction paymentInstruction) { LocalDate nowD = LocalDate.now(); - if (documentNumberResetAt == null || documentNumberResetAt.isBefore(nowD)) synchronized (this){ + if (documentNumberResetAt == null || documentNumberResetAt.isBefore(nowD)) synchronized (this) { long oldNum = documentNumberId.get(); // reset optimistic if (oldNum > 0) { while (!documentNumberId.compareAndSet(oldNum, 0)) { @@ -389,9 +390,9 @@ public class PaymentInstructionCreator { } documentNumberResetAt = nowD; } - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyy"); + String paymentDate = DATE_FORMATTER_ddMMyy.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate())); String num = String.format("%s/%s/%s/%s", - liabilitiesClaimsAssets.getContract(), formatter.format(paymentInstruction.getPaymentDate()), + liabilitiesClaimsAssets.getContract(), paymentDate, paymentInstruction.getSenderId(), documentNumberId.incrementAndGet() ); return num; diff --git a/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/order/PaymentInstructionCreatorTest.java b/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/order/PaymentInstructionCreatorTest.java index 6e4c63700..f5a632ab1 100644 --- a/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/order/PaymentInstructionCreatorTest.java +++ b/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/order/PaymentInstructionCreatorTest.java @@ -22,8 +22,8 @@ class PaymentInstructionCreatorTest { PaymentInstruction paymentInstruction = new PaymentInstruction(); paymentInstruction.setPaymentDate(TimeUtil.localDateToInstant(LocalDate.of(2023,1,4))); paymentInstruction.setSenderId(1234L); - assertEquals("contract/230104/1234/1", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); - assertEquals("contract/230104/1234/2", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); - assertEquals("contract/230104/1234/3", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); + assertEquals("contract/040123/1234/1", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); + assertEquals("contract/040123/1234/2", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); + assertEquals("contract/040123/1234/3", instance.nextDocumentNumber(liabilitiesClaimsAssets, paymentInstruction)); } } \ No newline at end of file