From 155b899e5de09e84a2b2c617fcb400907018a9b7 Mon Sep 17 00:00:00 2001 From: AKurakin Date: Mon, 25 Sep 2023 16:16:07 +0300 Subject: [PATCH] =?UTF-8?q?account-service=20backend-api=20http://jira.mfd?= =?UTF-8?q?.msk:8088/browse/CLS-548=20information-account-new=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BD=D0=B5=20=D0=BD=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD,=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20account-new?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/service/AccountService.java | 64 ++++++++++++------- .../service/InformationAccountService.java | 1 + .../account/InformationAccountController.java | 18 +++--- .../src/main/resources/meta/meta.json | 31 +-------- .../src/main/resources/meta/meta.xml | 10 +-- .../backend-api/src/test/resources/meta.json | 31 +-------- 6 files changed, 56 insertions(+), 99 deletions(-) diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/AccountService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/AccountService.java index 974494327..7fa1a3634 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/AccountService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/AccountService.java @@ -49,9 +49,6 @@ public class AccountService extends QueueConsumer implements InitializingBean { private final Logger log = LoggerFactory.getLogger(getClass()); private final ImdgProvider imdgProvider; private final Imdg accountMap; - private final Imdg informationAccountMap; - private final Imdg depoAccountMap; - private final Imdg clearingAccountMap; private final Imdg clearingMemberCategoryMap; private final Imdg relationMap; private final KafkaSender kafkaSender; @@ -87,9 +84,6 @@ public class AccountService extends QueueConsumer implements InitializingBean { this.relationMap = imdgProvider.getImdg( IMDGDistributedNames.Map_Relation, Relation.class ); - this.informationAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class); - this.depoAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class); - this.clearingAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class); this.kafkaSender = kafkaSender; this.messageResolver = messageResolver; this.userRoleVerification = userRoleVerification; @@ -147,25 +141,47 @@ public class AccountService extends QueueConsumer implements InitializingBean { requestInfoUpdate = fillAccountFromRelation(account, userRequest.getId(), false); if (requestInfoUpdate != null) return requestInfoUpdate; - Long newId = accountMap.insert(account); - + Long newId = null; if (AccountType.Corr.equalsByKey(account.getAccountType())) { // default, дополнительные таблицы не требуются - } else if (AccountType.Info.equalsByKey(account.getAccountType())) - makeInfoPart(account); - else if (AccountType.Depo.equalsByKey(account.getAccountType())) - makeDepoPart(account); - else if (AccountType.Clrn.equalsByKey(account.getAccountType())) - makeClrnPart(account); - else { - log.warn("Unexpected AccountType={}. Do not create additional record to other table's", account.getAccountType()); + newId = accountMap.insert(account); + } else { + // Транзакцией + ImdgTransaction imdgTransaction = imdgProvider.newTransaction(); + imdgTransaction.beginTransaction(); + boolean txOk = false; + try { + Imdg accountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class); + newId = accountMap.insert(account); + + if (AccountType.Corr.equalsByKey(account.getAccountType())) { + // default, дополнительные таблицы не требуются + } else if (AccountType.Info.equalsByKey(account.getAccountType())) + makeInfoPart(imdgTransaction, account); + else if (AccountType.Depo.equalsByKey(account.getAccountType())) + makeDepoPart(imdgTransaction, account); + else if (AccountType.Clrn.equalsByKey(account.getAccountType())) + makeClrnPart(imdgTransaction, account); + else { + log.warn("Unexpected AccountType={}. Do not create additional record to other table's", account.getAccountType()); + } + txOk = true; + } finally { + if (txOk) { + imdgTransaction.commitTransaction(); + } else { + log.debug("failed insert, new account id {} rollback", newId); + imdgTransaction.rollbackTransaction(); + } + } } log.debug("successfully processed, new account id {}", newId); return null; } - protected void makeInfoPart(Account account) { + protected void makeInfoPart(ImdgTransaction imdgTransaction, Account account) { + Imdg informationAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class); InformationAccount infoAcc = new InformationAccount(); infoAcc.setAccountId(account.getId()); Account firstAccountAntl = accountMap.getFirstObjectByFieldValues(Map.of( @@ -182,20 +198,22 @@ public class AccountService extends QueueConsumer implements InitializingBean { log.debug("For account id={} make InformationAccount id={}", account.getId(), infoId); } - protected void makeDepoPart(Account account) { + protected void makeDepoPart(ImdgTransaction imdgTransaction, Account account) { + Imdg depoAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);; DepoAccount depoAcc = new DepoAccount(); depoAcc.setAccountId(account.getId()); depoAcc.setCompanyId(account.getCompanyId()); - Long infoId = depoAccountMap.insert(depoAcc); - log.debug("For account id={} make DepoAccount id={}", account.getId(), infoId); + Long depoId = depoAccountMap.insert(depoAcc); + log.debug("For account id={} make DepoAccount id={}", account.getId(), depoId); } - protected void makeClrnPart(Account account) { + protected void makeClrnPart(ImdgTransaction imdgTransaction, Account account) { + Imdg clearingAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);; ClearingAccount clnrAcc = new ClearingAccount(); clnrAcc.setAccountId(account.getId()); clnrAcc.setCompanyId(account.getCompanyId()); - Long infoId = clearingAccountMap.insert(clnrAcc); - log.debug("For account id={} make ClearingAccount id={}", account.getId(), infoId); + Long clrnId = clearingAccountMap.insert(clnrAcc); + log.debug("For account id={} make ClearingAccount id={}", account.getId(), clrnId); } public RequestInfoUpdate correspondentAccountUpdate(BaseRequest userRequest) { diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/InformationAccountService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/InformationAccountService.java index d559fc1b2..7ad79b489 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/InformationAccountService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/InformationAccountService.java @@ -105,6 +105,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali init(); } + @Deprecated public RequestInfoUpdate informationAccountNew(BaseRequest userRequest) { log.debug("InformationAccountNewRequest received"); diff --git a/clearing-parent/backend-api/src/main/java/ru/spcex/clearing/backendapi/controller/queue/account/InformationAccountController.java b/clearing-parent/backend-api/src/main/java/ru/spcex/clearing/backendapi/controller/queue/account/InformationAccountController.java index a83f758fb..823b12dd5 100644 --- a/clearing-parent/backend-api/src/main/java/ru/spcex/clearing/backendapi/controller/queue/account/InformationAccountController.java +++ b/clearing-parent/backend-api/src/main/java/ru/spcex/clearing/backendapi/controller/queue/account/InformationAccountController.java @@ -51,13 +51,13 @@ public class InformationAccountController extends AbstractQueueController { } - @ApiOperation(value = "Добавление информационного счета.") - @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)}) - @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CudResponse add( - @ApiParam(value = "Параметры команды в JSON формате.", required = true) - @RequestBody AccountInformationNewAction accountNewInformationAction) throws ExecutionException, InterruptedException { - return processRequest(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, accountNewInformationAction); - } +// @ApiOperation(value = "Добавление информационного счета.") +// @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)}) +// @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) +// @ResponseBody +// public CudResponse add( +// @ApiParam(value = "Параметры команды в JSON формате.", required = true) +// @RequestBody AccountInformationNewAction accountNewInformationAction) throws ExecutionException, InterruptedException { +// return processRequest(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, accountNewInformationAction); +// } } diff --git a/clearing-parent/backend-api/src/main/resources/meta/meta.json b/clearing-parent/backend-api/src/main/resources/meta/meta.json index 3f7bdffce..2df744b57 100644 --- a/clearing-parent/backend-api/src/main/resources/meta/meta.json +++ b/clearing-parent/backend-api/src/main/resources/meta/meta.json @@ -1,6 +1,6 @@ { - "version": "3.8.0.54", + "version": "3.8.0.55", "enums": { @@ -4627,34 +4627,7 @@ "type": 1,"name": "Идентификатор записи","shortname": "ID","searchable": true,"sortable": true } ] - ,"actions":[ - {"method":"post", - - "name": "Добавление информационного счета", - - "confirmation": "companyId,account,status", - - "class": "ru.spcex.clearing.backendapi.controller.request.cud.account.AccountInformationNewAction", - - "fields": [ - {"code": "companyId", - "type": 1,"name": "Наименование компании","shortname": "Компания","link": "company","linkCode": "shortName","required": true - } - , - {"code": "account", - "type": 2,"length": 50,"name": "Номер счета","shortname": "Счет","required": true - } - , - {"code": "status", - "type": 12,"name": "Наименование статуса","shortname": "Статус","link": "serviceStatus" - } - , - {"code": "accountType", - "type": 12,"name": "Наименование типа счета","shortname": "Тип","link": "accountType","required": true,"visible": false - } - ] - } - ] + } , "depoAccount": { diff --git a/clearing-parent/backend-api/src/main/resources/meta/meta.xml b/clearing-parent/backend-api/src/main/resources/meta/meta.xml index 0961cd17b..01ff75610 100644 --- a/clearing-parent/backend-api/src/main/resources/meta/meta.xml +++ b/clearing-parent/backend-api/src/main/resources/meta/meta.xml @@ -1,6 +1,6 @@ - + @@ -1075,14 +1075,6 @@ - - - - - - - - diff --git a/clearing-parent/backend-api/src/test/resources/meta.json b/clearing-parent/backend-api/src/test/resources/meta.json index 3f7bdffce..2df744b57 100644 --- a/clearing-parent/backend-api/src/test/resources/meta.json +++ b/clearing-parent/backend-api/src/test/resources/meta.json @@ -1,6 +1,6 @@ { - "version": "3.8.0.54", + "version": "3.8.0.55", "enums": { @@ -4627,34 +4627,7 @@ "type": 1,"name": "Идентификатор записи","shortname": "ID","searchable": true,"sortable": true } ] - ,"actions":[ - {"method":"post", - - "name": "Добавление информационного счета", - - "confirmation": "companyId,account,status", - - "class": "ru.spcex.clearing.backendapi.controller.request.cud.account.AccountInformationNewAction", - - "fields": [ - {"code": "companyId", - "type": 1,"name": "Наименование компании","shortname": "Компания","link": "company","linkCode": "shortName","required": true - } - , - {"code": "account", - "type": 2,"length": 50,"name": "Номер счета","shortname": "Счет","required": true - } - , - {"code": "status", - "type": 12,"name": "Наименование статуса","shortname": "Статус","link": "serviceStatus" - } - , - {"code": "accountType", - "type": 12,"name": "Наименование типа счета","shortname": "Тип","link": "accountType","required": true,"visible": false - } - ] - } - ] + } , "depoAccount": {