clearing-service http://jira.mfd.msk:8088/browse/CLS-189 создание PaymentInstruction...

This commit is contained in:
AKurakin 2023-02-01 20:06:23 +03:00
parent 5f41508df3
commit 1debfd81da
2 changed files with 8 additions and 7 deletions

View file

@ -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<Account> accountImdg;
protected final Imdg<PaymentInstruction> 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;

View file

@ -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));
}
}