account-service http://jira.mfd.msk:8088/browse/CLS-585 ClearingAccountService SDF52
This commit is contained in:
parent
9376f9f6b1
commit
8305137de5
1 changed files with 81 additions and 8 deletions
|
|
@ -46,6 +46,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
import ru.spcex.platform.utils.collection.Pair;
|
import ru.spcex.platform.utils.collection.Pair;
|
||||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
import ru.spcex.platform.utils.validation.IValidator;
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
@ -135,7 +136,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestInfoUpdate clearingAccountNew(BaseRequest<ClearingAccountNewRequest> userRequest) {
|
public synchronized RequestInfoUpdate clearingAccountNew(BaseRequest<ClearingAccountNewRequest> userRequest) {
|
||||||
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
||||||
userRequest, clearingAccountNewRequestValidator
|
userRequest, clearingAccountNewRequestValidator
|
||||||
);
|
);
|
||||||
|
|
@ -194,7 +195,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestInfoUpdate clearingAccountUpdate(BaseRequest<ClearingAccountUpdateRequest> userRequest) {
|
public synchronized RequestInfoUpdate clearingAccountUpdate(BaseRequest<ClearingAccountUpdateRequest> userRequest) {
|
||||||
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
||||||
userRequest, clearingAccountUpdateRequestValidator
|
userRequest, clearingAccountUpdateRequestValidator
|
||||||
);
|
);
|
||||||
|
|
@ -241,7 +242,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RequestInfoUpdate accountNewSdf01(BaseRequest<AccountSdf01Request> userRequest) {
|
public synchronized RequestInfoUpdate accountNewSdf01(BaseRequest<AccountSdf01Request> userRequest) {
|
||||||
log.debug("AccountSdf01Request received, id={}", userRequest.getId());
|
log.debug("AccountSdf01Request received, id={}", userRequest.getId());
|
||||||
|
|
||||||
AccountSdf01Request req = userRequest.getRequestPayload();
|
AccountSdf01Request req = userRequest.getRequestPayload();
|
||||||
|
|
@ -333,6 +334,66 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Логика похожа на SDF01
|
||||||
|
*
|
||||||
|
* @param accountValue account
|
||||||
|
* @param companyId
|
||||||
|
* @param userRequestId для лога
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private synchronized Account createSdf52Account(String accountValue, String acctType, Long companyId, Long userRequestId) {
|
||||||
|
Instant now = Instant.now();
|
||||||
|
Account account = new Account();
|
||||||
|
account.setAccount(accountValue);
|
||||||
|
account.setStatus(ServiceStatus.Active.getKey());
|
||||||
|
if (accountValue.length() >= 7) {
|
||||||
|
String currency = accountValue.substring(4, 3);
|
||||||
|
account.setCurrency(currency);
|
||||||
|
} else {
|
||||||
|
log.warn("Sdf52: Wrong accountValue=\"{}\" - can not parse for get currency", accountValue);
|
||||||
|
}
|
||||||
|
account.setCompanyId(companyId);
|
||||||
|
account.setCreated(now);
|
||||||
|
account.setUpdated(now);
|
||||||
|
RequestInfoUpdate requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequestId, true);
|
||||||
|
if (requestInfoUpdate != null) {
|
||||||
|
log.warn("Error fill new account from relation. {}", /*account.getId(),*/ requestInfoUpdate.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Account existAccount = accountImdg.getFirstObjectBySQL("account = '%s' and accountType='%s'"
|
||||||
|
.formatted(accountValue, AccountType.Clrn.getKey()));
|
||||||
|
if (existAccount != null) {
|
||||||
|
log.debug("Sdf52: Account {} already exists", accountValue);
|
||||||
|
if (companyId.equals(existAccount.getCompanyId())) {
|
||||||
|
return existAccount;
|
||||||
|
} else {
|
||||||
|
log.debug("Sdf52: Account {} already exists for other companyId={}, do not apply for companyId={}",
|
||||||
|
accountValue, existAccount.getCompanyId(), companyId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Long clearingAccountId = -1L;
|
||||||
|
Long accountId = -1L;
|
||||||
|
ClearingAccount clearingAccount = null;
|
||||||
|
accountId = accountImdg.insert(account);
|
||||||
|
|
||||||
|
clearingAccount = new ClearingAccount();
|
||||||
|
clearingAccount.setCompanyId(companyId);
|
||||||
|
clearingAccount.setAccountId(accountId);
|
||||||
|
ClearingAccountType caType = IEnumKey.getEnumByKey(ClearingAccountType.class, acctType);
|
||||||
|
if (caType == null) {
|
||||||
|
log.warn("Wrong ClearingAccountType=\"{}\" for account \"{}\"", acctType, accountValue);
|
||||||
|
}
|
||||||
|
clearingAccount.setClearingAccountType(acctType);
|
||||||
|
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||||
|
log.debug("New account {}, clearingAccount {} was created.", accountId, clearingAccountId);
|
||||||
|
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
public RequestInfoUpdate accountUpdateSdf52(BaseRequest<StatementRequest> systemRequest) {
|
public RequestInfoUpdate accountUpdateSdf52(BaseRequest<StatementRequest> systemRequest) {
|
||||||
log.debug("accountUpdateSdf52 StatementRequest received, id={}", systemRequest.getId());
|
log.debug("accountUpdateSdf52 StatementRequest received, id={}", systemRequest.getId());
|
||||||
|
|
||||||
|
|
@ -376,8 +437,17 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
Account account = sDf52.getAccount() == null ? null : accountImdg.getFirstObjectByFieldValues(accountQuery);
|
Account account = sDf52.getAccount() == null ? null : accountImdg.getFirstObjectByFieldValues(accountQuery);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
if (SDFProcessService.SDF52_STATUS_3Open.equals(sDf52.getStatus())) {
|
if (SDFProcessService.SDF52_STATUS_3Open.equals(sDf52.getStatus())) {
|
||||||
log.debug("By generationId={} s_df52[{}].status={}, but account not found (query: {}). COntinuse with result OK for status 3",
|
//log.debug("By generationId={} s_df52[{}].status={}, but account not found (query: {}). Continue with result OK for status 3",
|
||||||
|
// groupId, sDf52.getId(), sDf52.getStatus(), accountQuery);
|
||||||
|
// todo http://jira.mfd.msk:8088/browse/CLS-585 добавят поле acc_type в формат дф52
|
||||||
|
log.trace("By generationId={} s_df52[{}].status={}, account not found (query: {}). Try create new account.",
|
||||||
groupId, sDf52.getId(), sDf52.getStatus(), accountQuery);
|
groupId, sDf52.getId(), sDf52.getStatus(), accountQuery);
|
||||||
|
account = createSdf52Account(sDf52.getAccount(),sDf52.getAcc_type(), company.getId(), systemRequest.getId());
|
||||||
|
if (account == null) {
|
||||||
|
log.warn("Can not create account: \"{}\", companyId={}. Ignore SDF52.id={}",
|
||||||
|
sDf52.getAccount(), company.getId(), sDf52.getId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String msg = messageResolver.resolve(new EnumMessage(AccountError.AccountNotFound, sDf52.getAccount()));
|
String msg = messageResolver.resolve(new EnumMessage(AccountError.AccountNotFound, sDf52.getAccount()));
|
||||||
log.warn("By generationId={} s_df52[{}] (query: {}) error: {}", groupId, sDf52.getId(), accountQuery, msg);
|
log.warn("By generationId={} s_df52[{}] (query: {}) error: {}", groupId, sDf52.getId(), accountQuery, msg);
|
||||||
|
|
@ -387,7 +457,9 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toProcessSDF53.add(new MutableTriple<>(sDf52, account, SDFProcessService.SDF_STATUS_OK));
|
toProcessSDF53.add(new MutableTriple<>(sDf52, account, SDFProcessService.SDF_STATUS_OK));
|
||||||
toUpdate.add(new Pair<>(sDf52, account));
|
if (account != null) {
|
||||||
|
toUpdate.add(new Pair<>(sDf52, account));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("Selected to update {} account's", toUpdate.size());
|
log.debug("Selected to update {} account's", toUpdate.size());
|
||||||
|
|
@ -403,6 +475,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
}
|
}
|
||||||
if (newStatus.equalsByKey(account.getStatus())) {
|
if (newStatus.equalsByKey(account.getStatus())) {
|
||||||
// одинаковых обычно не бывает.
|
// одинаковых обычно не бывает.
|
||||||
|
log.trace("In sDF_52[{}] for account [{}] status {} not changed.", sdf.getId(), account.getId(), newStatus);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (AccountStatus.BLOCKED == newStatus || AccountStatus.CLOSE == newStatus) { // статус 0/2
|
if (AccountStatus.BLOCKED == newStatus || AccountStatus.CLOSE == newStatus) { // статус 0/2
|
||||||
|
|
@ -446,9 +519,9 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RequestInfoUpdate accountUpdateSdf52_part2(BaseRequest<StatementRequest> systemRequest1,
|
protected synchronized RequestInfoUpdate accountUpdateSdf52_part2(BaseRequest<StatementRequest> systemRequest1,
|
||||||
SDf52 sdf, Account account,
|
SDf52 sdf, Account account,
|
||||||
BaseRequest<NotificationFeedbackRequest> secondSystemRequest2) {
|
BaseRequest<NotificationFeedbackRequest> secondSystemRequest2) {
|
||||||
// 5. from notification:
|
// 5. from notification:
|
||||||
StatementRequest req = systemRequest1.getRequestPayload();
|
StatementRequest req = systemRequest1.getRequestPayload();
|
||||||
Long groupId = req.getGroupId();
|
Long groupId = req.getGroupId();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue