feat: load module three wallet data for exchange

agent/payment-training-progress
chenyuan 2 weeks ago
parent ab5c2df7ed
commit 7f6738c2d6

@ -15,6 +15,7 @@ import com.yau.digitalrmb.shared.api.ErrorCode;
import com.yau.digitalrmb.shared.exception.BusinessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.yau.digitalrmb.shared.wallet.WalletPrerequisiteProjectionService;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -27,17 +28,22 @@ public class JdbcExchangeResourceRepository implements ExchangeResourceRepositor
private final InstitutionIdentityCryptography cryptography;
private final WalletPrivateKeyCipher cipher;
private final InstitutionKeyService keyService;
private final WalletPrerequisiteProjectionService walletPrerequisites;
public JdbcExchangeResourceRepository(JdbcTemplate jdbc, InstitutionIdentityCryptography cryptography,
WalletPrivateKeyCipher cipher, InstitutionKeyService keyService) {
WalletPrivateKeyCipher cipher, InstitutionKeyService keyService,
WalletPrerequisiteProjectionService walletPrerequisites) {
this.jdbc = jdbc;
this.cryptography = cryptography;
this.cipher = cipher;
this.keyService = keyService;
this.walletPrerequisites = walletPrerequisites;
}
@Override
public ExchangeContext loadContext(ExchangeActor actor) {
walletPrerequisites.ensureForSubject(new InstitutionKeySubject(
actor.getUserId(), actor.getSchoolId(), actor.getClassId()));
Institution institution = loadIssuedInstitution(actor);
List<ExchangeContext> values = jdbc.query(
"SELECT w.wallet_id,w.wallet_type,w.status wallet_status,w.balance wallet_balance," +

@ -11,11 +11,11 @@ import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import com.yau.digitalrmb.shared.wallet.WalletPrivateKeyCipher;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeyService;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
import com.yau.digitalrmb.institutionidentity.domain.InstitutionIdentityCryptography;
import com.yau.digitalrmb.institutionidentity.domain.InstitutionSm2KeyPair;
import com.yau.digitalrmb.testsupport.WalletOpeningTestData;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
@ -32,7 +32,6 @@ class ExchangeControllerTest {
@Autowired private MockMvc mockMvc;
@Autowired private JdbcTemplate jdbc;
@Autowired private InstitutionIdentityCryptography cryptography;
@Autowired private WalletPrivateKeyCipher walletCipher;
@Autowired private InstitutionKeyService keyService;
@BeforeEach
@ -52,6 +51,7 @@ class ExchangeControllerTest {
jdbc.update("DELETE FROM wallet_certificate");
jdbc.update("DELETE FROM simulated_bank_account");
jdbc.update("DELETE FROM digital_wallet");
WalletOpeningTestData.deleteWalletFacts(jdbc, USER_ID);
jdbc.update("DELETE FROM institution_identifier_application WHERE user_id=?", USER_ID);
jdbc.update("DELETE FROM commercial_bank_currency WHERE issuance_request_id='EXCHANGE_TEST_ISSUANCE'");
jdbc.update("INSERT INTO institution_identifier_application (id,bank_code,user_id,school_id,class_id," +
@ -64,25 +64,18 @@ class ExchangeControllerTest {
keyService.centralBankKey(subject, "test");
String issuanceSignature = keyService.signCentralBank(subject, "ISSUANCE_ORIGINAL");
InstitutionSm2KeyPair walletKey = cryptography.generateSm2KeyPair();
jdbc.update("INSERT INTO digital_wallet (wallet_id,user_id,wallet_type,status,balance," +
"central_bank_confirmation_signature,opened_at,created_at,updated_at) " +
"VALUES ('WALLET_EXCHANGE_TEST',?,'TYPE_II','ACTIVE',0,'CB_FINAL_TEST',CURRENT_TIMESTAMP," +
"CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", USER_ID);
jdbc.update("INSERT INTO wallet_certificate (certificate_serial,wallet_id,public_key,encrypted_private_key," +
"filing_status,central_bank_root_signature,status,issued_at) VALUES " +
"('CERT_EXCHANGE_TEST','WALLET_EXCHANGE_TEST',?,?,'REGISTERED','CB_ROOT_TEST','VALID',CURRENT_TIMESTAMP)",
walletKey.getPublicKey(), walletCipher.encrypt(walletKey.getPrivateKey()));
jdbc.update("INSERT INTO wallet_contract (contract_id,wallet_id,wallet_type,single_payment_limit," +
"daily_payment_limit,annual_payment_limit,balance_limit,valid_until,original_text,digest,status," +
"daily_used_amount,daily_counter_date,annual_used_amount,annual_counter_year,created_at,updated_at) VALUES " +
"('CONTRACT_EXCHANGE_TEST','WALLET_EXCHANGE_TEST','TYPE_II',50000,100000,500000,500000,NULL," +
"'CONTRACT|WALLET_EXCHANGE_TEST|TYPE_II','DIGEST','ACTIVE',0,CURRENT_DATE,0,2026,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)");
jdbc.update("INSERT INTO simulated_bank_account (account_id,user_id,bank_code,bank_name,card_number,card_last4," +
"balance,frozen_amount,status,created_at,updated_at) VALUES " +
"('BANK_ACCOUNT_EXCHANGE_TEST',?,'BKCHCNBJ00001','中国银行北京分行','6216610100001234567'," +
"'4567',50000,0,'ACTIVE',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", USER_ID);
jdbc.update("INSERT INTO wallet_bank_binding (wallet_id,bank_account_id,status,bound_at) VALUES " +
"('WALLET_EXCHANGE_TEST','BANK_ACCOUNT_EXCHANGE_TEST','BOUND',CURRENT_TIMESTAMP)");
WalletOpeningTestData.insertCompletedWallet(jdbc, 990100L, USER_ID, 1999L, 2999L,
"WALLET_EXCHANGE_TEST", walletKey.getPrivateKey(), walletKey.getPublicKey(),
"中国银行北京分行", "6216610100001234567", new java.math.BigDecimal("50000.00"));
jdbc.update("DELETE FROM wallet_bank_binding");
jdbc.update("DELETE FROM wallet_contract");
jdbc.update("DELETE FROM wallet_certificate");
jdbc.update("DELETE FROM simulated_bank_account");
jdbc.update("DELETE FROM digital_wallet");
for (int i = 1; i <= 2; i++) {
jdbc.update("INSERT INTO commercial_bank_currency (currency_id,source_currency_id,source_batch_id,"
+ "issuance_request_id,bank_code,organization_id,denomination,currency,complete_currency,"
@ -112,6 +105,7 @@ class ExchangeControllerTest {
jdbc.update("DELETE FROM wallet_certificate");
jdbc.update("DELETE FROM simulated_bank_account");
jdbc.update("DELETE FROM digital_wallet");
WalletOpeningTestData.deleteWalletFacts(jdbc, USER_ID);
jdbc.update("DELETE FROM commercial_bank_currency WHERE issuance_request_id='EXCHANGE_TEST_ISSUANCE'");
jdbc.update("DELETE FROM institution_sm2_key_audit WHERE user_id=?", USER_ID);
jdbc.update("DELETE FROM institution_sm2_key WHERE user_id=?", USER_ID);
@ -127,11 +121,15 @@ class ExchangeControllerTest {
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.bankCardLast4").value("4567"))
.andExpect(jsonPath("$.data.bankCardNumber").value("6216610100001234567"))
.andExpect(jsonPath("$.data.contractId").value("CONTRACT_EXCHANGE_TEST"))
.andExpect(jsonPath("$.data.contractId").value("CONTRACT_990100"))
.andExpect(jsonPath("$.data.annualLimit").value(500000.00))
.andExpect(jsonPath("$.data.balanceLimit").value(500000.00))
.andExpect(jsonPath("$.data.bankAccountBalance").value(50000.00))
.andReturn().getResponse().getContentAsString();
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM currency_exchange_order", Integer.class)).isZero();
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM exchange_step_log", Integer.class)).isZero();
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM digital_wallet WHERE user_id=?", Integer.class, USER_ID))
.isEqualTo(1);
String walletId = JsonPath.read(context, "$.data.walletId");
String accountId = JsonPath.read(context, "$.data.bankAccountId");
String body = "{\"walletId\":\"" + walletId + "\",\"bankAccountId\":\"" + accountId
@ -175,10 +173,11 @@ class ExchangeControllerTest {
jdbc.update("DELETE FROM wallet_certificate");
jdbc.update("DELETE FROM simulated_bank_account");
jdbc.update("DELETE FROM digital_wallet");
WalletOpeningTestData.deleteWalletFacts(jdbc, USER_ID);
mockMvc.perform(get("/api/v1/exchanges/context").with(user()))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.message").value(org.hamcrest.Matchers.containsString("个人数字钱包开通模块")));
.andExpect(jsonPath("$.message").value(org.hamcrest.Matchers.containsString("个人数字钱包开通实验")));
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM digital_wallet WHERE user_id=?", Integer.class, USER_ID))
.isZero();
}

Loading…
Cancel
Save