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:
parent
8644d18a90
commit
718bb594ef
3 changed files with 95 additions and 66 deletions
|
|
@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -29,20 +30,38 @@ public class ClearingService implements DisposableBean {
|
|||
this.executor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "${clearing-service.scheduler.check-payment-instruction}")
|
||||
// @Scheduled(cron = "${clearing-service.scheduler.check-payment-instruction}")
|
||||
public void sdfCreate() {
|
||||
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) {
|
||||
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() {
|
||||
log.info("execute verification");
|
||||
executor.execute(() -> verificationResultComponent.executeRevision());
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
verificationResultComponent.executeRevision();
|
||||
} catch (Throwable e) {
|
||||
log.error("{}", ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
|
|||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class PaymentInstructionSorter {
|
||||
|
|
@ -41,55 +43,60 @@ public class PaymentInstructionSorter {
|
|||
}
|
||||
|
||||
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());
|
||||
ClearingMemberCategory category = clrngMmbrImdg.getSingleObjectByFieldValues(Map.of("companyId", senderId));
|
||||
ClearingMemberCategoryD categoryValue = IEnumKey.getEnumByKey(ClearingMemberCategoryD.class, category.getClearingMemberCategory());
|
||||
batchInfo.setCategoryD(categoryValue);
|
||||
if (ClearingMemberCategoryD.I.equals(categoryValue)) {
|
||||
EnumMessage error = null;
|
||||
List<PaymentInstruction> aList = new ArrayList<>();
|
||||
List<PaymentInstruction> bList = new ArrayList<>();
|
||||
for (PaymentInstruction payment : payments) {
|
||||
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;
|
||||
Collection<ClearingMemberCategory> cmcList = clrngMmbrImdg.getCollectionObjectsByFieldValues(Map.of("companyId", senderId));
|
||||
Collection<ClearingMemberCategoryD> companyCategory = cmcList.stream()
|
||||
.filter(cat -> cat.getClearingMemberCategory()!=null)
|
||||
.map(cat -> IEnumKey.getEnumByKey(ClearingMemberCategoryD.class, cat.getClearingMemberCategory()))
|
||||
.collect(Collectors.toSet());
|
||||
for (ClearingMemberCategoryD categoryValue: companyCategory) {
|
||||
log.debug("For category {}", categoryValue);
|
||||
PaymentBatchInfo batchInfo = new PaymentBatchInfo();
|
||||
batchInfo.setCategoryD(categoryValue);
|
||||
if (ClearingMemberCategoryD.I.equals(categoryValue)) {
|
||||
EnumMessage error = null;
|
||||
List<PaymentInstruction> aList = new ArrayList<>();
|
||||
List<PaymentInstruction> bList = new ArrayList<>();
|
||||
for (PaymentInstruction payment : payments) {
|
||||
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())
|
||||
&& 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;
|
||||
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());
|
||||
}
|
||||
}
|
||||
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={}, " +
|
||||
log.info("processing PaymentInstruction's generationId={} senderId={} [fromClearingToBankCreditAmount={}, " +
|
||||
"fromBankToClearingCreditAmount={}, " +
|
||||
"fromClearingToBankDebitAmount={}, " +
|
||||
"fromBankToClearingDebitAmount={}] {}", generationId, senderId,
|
||||
|
|
@ -98,24 +105,27 @@ public class PaymentInstructionSorter {
|
|||
fromClearingToBankDebitAmount,
|
||||
fromBankToClearingDebitAmount,
|
||||
error != null ? ("error " + messageResolver.resolve(error)) : "ok");
|
||||
if (error != null) {
|
||||
batchInfo.setError(error);
|
||||
payments.forEach(pmt -> {
|
||||
pmt.setTransactionStatus(TransactionStatus.cher.getKey());
|
||||
pmtInstrctnsImdg.update(pmt);
|
||||
});
|
||||
if (error != null) {
|
||||
batchInfo.setError(error);
|
||||
payments.forEach(pmt -> {
|
||||
pmt.setTransactionStatus(TransactionStatus.cher.getKey());
|
||||
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;
|
||||
} else {
|
||||
batchInfo.setFromClearingToBank(aList);
|
||||
batchInfo.setFromBankToClearing(bList);
|
||||
return batchInfo;
|
||||
log.debug("Do nothing as category {}, check next", categoryValue);
|
||||
// проверить следующую категорил, когда закончатся выдать ошибку
|
||||
}
|
||||
} 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 + "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class CommandService extends QueueConsumer implements InitializingBean {
|
|||
.setConsumer(this::process)
|
||||
.forDestination(Consts.EXPORT_PROCESS, callbacks::put);
|
||||
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);
|
||||
callback(SdfClearingRequest.class)
|
||||
.setConsumer(r -> processSpecial(Table.S_DF11, r))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue