SDF57 processing
This commit is contained in:
parent
8a9cb9f201
commit
a8e5bcc1ee
1 changed files with 18 additions and 14 deletions
|
|
@ -37,7 +37,6 @@ import java.time.LocalDate;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
|
@ -113,22 +112,22 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
log.error("error while validating sdf57.id={} - {}", sdf57.getId(), messageResolver.resolve(error.get()));
|
||||
continue;
|
||||
}
|
||||
BiFunction<Company, Account, Optional<Statement>> createStatementIfNeeded = (company, account) -> {
|
||||
TriFunction<Company, Account, InOutDirection, Optional<Statement>> createStatementIfNeeded = (company, account, inOut) -> {
|
||||
if (company == null || account == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Statement statement = create(sdf57, company, account);
|
||||
Statement statement = create(sdf57, company, account, inOut);
|
||||
statementImdg.insert(statement);
|
||||
return Optional.of(statement);
|
||||
};
|
||||
//create by companyDeb
|
||||
Company companyDeb = validator.getStored(ValidationStored.Sdf57CompanyDeb);
|
||||
Account accountDeb = validator.getStored(ValidationStored.Sdf57AccountDeb);
|
||||
Optional<Statement> statementDeb = createStatementIfNeeded.apply(companyDeb, accountDeb);
|
||||
Optional<Statement> statementDeb = createStatementIfNeeded.apply(companyDeb, accountDeb, InOutDirection.out);
|
||||
//create by companyCred
|
||||
Company companyCred = validator.getStored(ValidationStored.Sdf57CompanyCred);
|
||||
Account accountCred = validator.getStored(ValidationStored.Sdf57AccountCred);
|
||||
Optional<Statement> statementCred = createStatementIfNeeded.apply(companyCred, accountCred);
|
||||
Optional<Statement> statementCred = createStatementIfNeeded.apply(companyCred, accountCred, InOutDirection.in);
|
||||
|
||||
Consumer<StmtCmpAcc> createRegistryIfNeeded = stmtCmpAcc -> {
|
||||
Statement stmt = stmtCmpAcc.statement();
|
||||
|
|
@ -140,12 +139,12 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
updateReg(stmt, rgs);
|
||||
registryImdg.update(rgs);
|
||||
};
|
||||
Runnable create = () -> {
|
||||
Registry registry = createRegistryByStatement(stmt, company, account);
|
||||
Consumer<RegistryDesignation> create = (dsgn) -> {
|
||||
Registry registry = createRegistryByStatement(stmt, company, account, dsgn);
|
||||
registryImdg.insert(registry);
|
||||
};
|
||||
findReg(stmt, RegistryDesignation.A).ifPresentOrElse(update, create);
|
||||
findReg(stmt, RegistryDesignation.D).ifPresentOrElse(update, create);
|
||||
findReg(stmt, RegistryDesignation.A).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.A));
|
||||
findReg(stmt, RegistryDesignation.D).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.D));
|
||||
stmt.setOperationStatus(OperationStatus.Executed.getKey());
|
||||
} else {
|
||||
stmt.setErrorCodeId(err.get().getSubject().getId()); // fixme ErrorText insert
|
||||
|
|
@ -172,7 +171,7 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Statement create(SDf57 sdf57, Company companyDeb, Account accountDeb) {
|
||||
private Statement create(SDf57 sdf57, Company companyDeb, Account accountDeb, InOutDirection inOutDirection) {
|
||||
Statement statement = new Statement();
|
||||
statement.setAddresseeId(companyDeb.getId());
|
||||
statement.setSenderId(Sender.Prc.getId());
|
||||
|
|
@ -180,7 +179,7 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
statement.setContract(getContractFromSpecif(sdf57.getSpecif()));
|
||||
statement.setAccountId(accountDeb.getId());
|
||||
statement.setAccount(accountDeb.getAccount());
|
||||
statement.setInOutDirection(InOutDirection.out.getKey()); //fixme ! явно может быть разное
|
||||
statement.setInOutDirection(inOutDirection.getKey());
|
||||
statement.setSettlementDate(payDate(sdf57.getPay_date())); //fixme ! pay_date format
|
||||
statement.setAmount(TextUtil.isEmpty(sdf57.getSum_deb()) ? null : new BigDecimal(sdf57.getSum_deb()));
|
||||
statement.setOperationStatus(OperationStatus.Pending.getKey());
|
||||
|
|
@ -189,7 +188,7 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
return statement;
|
||||
}
|
||||
|
||||
private Registry createRegistryByStatement(Statement statement, Company company, Account account) {
|
||||
private Registry createRegistryByStatement(Statement statement, Company company, Account account, RegistryDesignation designation) {
|
||||
Registry rgs = new Registry();
|
||||
rgs.setCompanyId(statement.getAddresseeId());
|
||||
rgs.setTradingCode(company.getTradingCode());
|
||||
|
|
@ -199,8 +198,8 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
rgs.setAccountId(account.getId());
|
||||
rgs.setAccountType(account.getAccountType());
|
||||
rgs.setAccount(account.getAccount());
|
||||
rgs.setRegistryDesignation(RegistryDesignation.A.getKey());
|
||||
rgs.setRegistryInstrumentType(RegistryInstrumentType.M.getKey()); //fixme ! а депозита быть не может??? искать то мы его ищем
|
||||
rgs.setRegistryDesignation(designation.getKey());
|
||||
rgs.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
rgs.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
rgs.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
rgs.setRegistryCode(RegistryUtil.clearingCode(rgs));
|
||||
|
|
@ -283,4 +282,9 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
}
|
||||
return specif.substring(index + 1);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private static interface TriFunction<T1, T2, T3, R> {
|
||||
R apply(T1 arg1, T2 arg2, T3 arg3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue