clearing-service dbf-exporter ASGN.M.BT10-1.1 и ASGN.M.BT10-1.2. S_DF03 S_DF11 правка для множества вариантов learing_member_category

This commit is contained in:
AKurakin 2023-01-18 11:08:06 +03:00
parent 8644d18a90
commit 718bb594ef
3 changed files with 95 additions and 66 deletions

View file

@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.spcex.platform.utils.log.ExceptionUtils;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -29,20 +30,38 @@ public class ClearingService implements DisposableBean {
this.executor = Executors.newSingleThreadExecutor(); this.executor = Executors.newSingleThreadExecutor();
} }
// @Scheduled(cron = "${clearing-service.scheduler.check-payment-instruction}") // @Scheduled(cron = "${clearing-service.scheduler.check-payment-instruction}")
public void sdfCreate() { public void sdfCreate() {
log.info("creating sdf03/11 from STLD payments task added to queue"); log.info("creating sdf03/11 from STLD payments task added to queue");
executor.execute(sdfCreator::createSdfFromPaymentInstructionSTLD); executor.execute(() -> {
try {
sdfCreator.createSdfFromPaymentInstructionSTLD();
} catch (Throwable e) {
log.error("{}", ExceptionUtils.getStackTrace(e));
}
});
} }
public void paymentUpdateBySdf04(Long sdf04GroupId) { public void paymentUpdateBySdf04(Long sdf04GroupId) {
log.info("updating payment.transactionStatus by sdf04 task added to queue"); log.info("updating payment.transactionStatus by sdf04 task added to queue");
executor.execute(() -> paymentUpdater.updatePayments(sdf04GroupId)); executor.execute(() -> {
try {
paymentUpdater.updatePayments(sdf04GroupId);
} catch (Throwable e) {
log.error("{}", ExceptionUtils.getStackTrace(e));
}
});
} }
public void executeVerification() { public void executeVerification() {
log.info("execute verification"); log.info("execute verification");
executor.execute(() -> verificationResultComponent.executeRevision()); executor.execute(() -> {
try {
verificationResultComponent.executeRevision();
} catch (Throwable e) {
log.error("{}", ExceptionUtils.getStackTrace(e));
}
});
} }
@Override @Override

View file

@ -19,9 +19,11 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver; import ru.spcex.platform.utils.enumeration.IMessageResolver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
@Component @Component
public class PaymentInstructionSorter { public class PaymentInstructionSorter {
@ -41,55 +43,60 @@ public class PaymentInstructionSorter {
} }
public PaymentBatchInfo sortCompanyPayments(Long generationId, Long senderId, List<PaymentInstruction> payments) { public PaymentBatchInfo sortCompanyPayments(Long generationId, Long senderId, List<PaymentInstruction> payments) {
PaymentBatchInfo batchInfo = new PaymentBatchInfo();
log.info("processing PaymentInstruction's generationId={} senderId={} size={}", generationId, senderId, payments.size()); log.info("processing PaymentInstruction's generationId={} senderId={} size={}", generationId, senderId, payments.size());
ClearingMemberCategory category = clrngMmbrImdg.getSingleObjectByFieldValues(Map.of("companyId", senderId)); Collection<ClearingMemberCategory> cmcList = clrngMmbrImdg.getCollectionObjectsByFieldValues(Map.of("companyId", senderId));
ClearingMemberCategoryD categoryValue = IEnumKey.getEnumByKey(ClearingMemberCategoryD.class, category.getClearingMemberCategory()); Collection<ClearingMemberCategoryD> companyCategory = cmcList.stream()
batchInfo.setCategoryD(categoryValue); .filter(cat -> cat.getClearingMemberCategory()!=null)
if (ClearingMemberCategoryD.I.equals(categoryValue)) { .map(cat -> IEnumKey.getEnumByKey(ClearingMemberCategoryD.class, cat.getClearingMemberCategory()))
EnumMessage error = null; .collect(Collectors.toSet());
List<PaymentInstruction> aList = new ArrayList<>(); for (ClearingMemberCategoryD categoryValue: companyCategory) {
List<PaymentInstruction> bList = new ArrayList<>(); log.debug("For category {}", categoryValue);
for (PaymentInstruction payment : payments) { PaymentBatchInfo batchInfo = new PaymentBatchInfo();
Account creditLegAcc = accImdg.getSingleObjectByID(payment.getCreditLegAccountId()); batchInfo.setCategoryD(categoryValue);
Account debitLegAcc = accImdg.getSingleObjectByID(payment.getDebitLegAccountId()); if (ClearingMemberCategoryD.I.equals(categoryValue)) {
if (creditLegAcc == null || debitLegAcc == null) { EnumMessage error = null;
String message = String.format("cannot find account CreditLegAccountId/DebitLegAccountId %d/%d", payment.getCreditLegAccountId(), payment.getDebitLegAccountId()); List<PaymentInstruction> aList = new ArrayList<>();
log.error("generationId={}, senderId={} payment.id={} {}", List<PaymentInstruction> bList = new ArrayList<>();
generationId, senderId, payment.getId(), message); for (PaymentInstruction payment : payments) {
continue; Account creditLegAcc = accImdg.getSingleObjectByID(payment.getCreditLegAccountId());
Account debitLegAcc = accImdg.getSingleObjectByID(payment.getDebitLegAccountId());
if (creditLegAcc == null || debitLegAcc == null) {
String message = String.format("cannot find account CreditLegAccountId/DebitLegAccountId %d/%d", payment.getCreditLegAccountId(), payment.getDebitLegAccountId());
log.error("generationId={}, senderId={} payment.id={} {}",
generationId, senderId, payment.getId(), message);
continue;
}
if (AccountType.Clrn.equalsByKey(creditLegAcc.getAccountType())
&& AccountType.Bank.equalsByKey(debitLegAcc.getAccountType())) {
aList.add(payment);
} else if (AccountType.Bank.equalsByKey(creditLegAcc.getAccountType())
&& AccountType.Clrn.equalsByKey(debitLegAcc.getAccountType())) {
bList.add(payment);
} else {
String message = String.format("cannot sort creditLegAccount.type=%s, debitLegAccount.type=%s", creditLegAcc.getAccountType(), debitLegAcc.getAccountType());
log.error("generationId={}, senderId={} payment.id={} {}",
generationId, senderId, payment.getId(), message);
//continue;
}
} }
if (AccountType.Clrn.equalsByKey(creditLegAcc.getAccountType()) Function<List<PaymentInstruction>, Long> creditAmountSum = paymentInstructions -> paymentInstructions
&& AccountType.Bank.equalsByKey(debitLegAcc.getAccountType())) { .stream()
aList.add(payment); .map(PaymentInstruction::getCreditLegAmount)
} else if (AccountType.Bank.equalsByKey(creditLegAcc.getAccountType()) .reduce(0L, Long::sum);
&& AccountType.Clrn.equalsByKey(debitLegAcc.getAccountType())) { Function<List<PaymentInstruction>, Long> debitAmountSum = paymentInstructions -> paymentInstructions
bList.add(payment); .stream()
} else { .map(PaymentInstruction::getDebitLegAmount)
String message = String.format("cannot sort creditLegAccount.type=%s, debitLegAccount.type=%s", creditLegAcc.getAccountType(), debitLegAcc.getAccountType()); .reduce(0L, Long::sum);
log.error("generationId={}, senderId={} payment.id={} {}", Long fromClearingToBankCreditAmount = creditAmountSum.apply(aList);
generationId, senderId, payment.getId(), message); Long fromBankToClearingCreditAmount = creditAmountSum.apply(bList);
//continue; Long fromClearingToBankDebitAmount = debitAmountSum.apply(aList);
Long fromBankToClearingDebitAmount = debitAmountSum.apply(bList);
if (!fromClearingToBankCreditAmount.equals(fromBankToClearingCreditAmount)) {
error = new EnumMessage(ClearingError.CompanyCreditCheck, senderId.toString());
} else if (!fromClearingToBankDebitAmount.equals(fromBankToClearingDebitAmount)) {
error = new EnumMessage(ClearingError.CompanyDebitCheck, senderId.toString());
} }
} log.info("processing PaymentInstruction's generationId={} senderId={} [fromClearingToBankCreditAmount={}, " +
Function<List<PaymentInstruction>, Long> creditAmountSum = paymentInstructions -> paymentInstructions
.stream()
.map(PaymentInstruction::getCreditLegAmount)
.reduce(0L, Long::sum);
Function<List<PaymentInstruction>, Long> debitAmountSum = paymentInstructions -> paymentInstructions
.stream()
.map(PaymentInstruction::getDebitLegAmount)
.reduce(0L, Long::sum);
Long fromClearingToBankCreditAmount = creditAmountSum.apply(aList);
Long fromBankToClearingCreditAmount = creditAmountSum.apply(bList);
Long fromClearingToBankDebitAmount = debitAmountSum.apply(aList);
Long fromBankToClearingDebitAmount = debitAmountSum.apply(bList);
if (!fromClearingToBankCreditAmount.equals(fromBankToClearingCreditAmount)) {
error = new EnumMessage(ClearingError.CompanyCreditCheck, senderId.toString());
} else if (!fromClearingToBankDebitAmount.equals(fromBankToClearingDebitAmount)) {
error = new EnumMessage(ClearingError.CompanyDebitCheck, senderId.toString());
}
log.info("processing PaymentInstruction's generationId={} senderId={} [fromClearingToBankCreditAmount={}, " +
"fromBankToClearingCreditAmount={}, " + "fromBankToClearingCreditAmount={}, " +
"fromClearingToBankDebitAmount={}, " + "fromClearingToBankDebitAmount={}, " +
"fromBankToClearingDebitAmount={}] {}", generationId, senderId, "fromBankToClearingDebitAmount={}] {}", generationId, senderId,
@ -98,24 +105,27 @@ public class PaymentInstructionSorter {
fromClearingToBankDebitAmount, fromClearingToBankDebitAmount,
fromBankToClearingDebitAmount, fromBankToClearingDebitAmount,
error != null ? ("error " + messageResolver.resolve(error)) : "ok"); error != null ? ("error " + messageResolver.resolve(error)) : "ok");
if (error != null) { if (error != null) {
batchInfo.setError(error); batchInfo.setError(error);
payments.forEach(pmt -> { payments.forEach(pmt -> {
pmt.setTransactionStatus(TransactionStatus.cher.getKey()); pmt.setTransactionStatus(TransactionStatus.cher.getKey());
pmtInstrctnsImdg.update(pmt); pmtInstrctnsImdg.update(pmt);
}); });
return batchInfo;
} else {
batchInfo.setFromClearingToBank(aList);
batchInfo.setFromBankToClearing(bList);
return batchInfo;
}
} else if (ClearingMemberCategoryD.B.equals(categoryValue)) {
batchInfo.setInitialOrder(payments);
return batchInfo; return batchInfo;
} else { } else {
batchInfo.setFromClearingToBank(aList); log.debug("Do nothing as category {}, check next", categoryValue);
batchInfo.setFromBankToClearing(bList); // проверить следующую категорил, когда закончатся выдать ошибку
return batchInfo;
} }
} else if (ClearingMemberCategoryD.B.equals(categoryValue)) {
batchInfo.setInitialOrder(payments);
return batchInfo;
} else {
throw new IllegalStateException("unknown clearing member category for generationId="
+ generationId + " companyId=" + senderId + "");
} }
throw new IllegalStateException("unknown clearing member category ["+companyCategory+"] for generationId="
+ generationId + " companyId=" + senderId + "");
} }
} }

View file

@ -36,7 +36,7 @@ public class CommandService extends QueueConsumer implements InitializingBean {
.setConsumer(this::process) .setConsumer(this::process)
.forDestination(Consts.EXPORT_PROCESS, callbacks::put); .forDestination(Consts.EXPORT_PROCESS, callbacks::put);
callback(SdfClearingRequest.class) callback(SdfClearingRequest.class)
.setConsumer(r -> processSpecial(Table.S_DF03, r)) .setConsumer(r -> processSpecial(Table.S_DF03, r)) // todo необходимо в отдельную папку: "в отдельную директорию SettlementHouse_Fail (чтобы не отдавать такие файлы в ПРЦ"
.forDestination(Consts.SDF03_PROCESS, callbacks::put); .forDestination(Consts.SDF03_PROCESS, callbacks::put);
callback(SdfClearingRequest.class) callback(SdfClearingRequest.class)
.setConsumer(r -> processSpecial(Table.S_DF11, r)) .setConsumer(r -> processSpecial(Table.S_DF11, r))