fix: distinguish exchange and payment coin locks

agent/payment-training-progress
chenyuan 2 weeks ago
parent c5e5256395
commit 3a6cdae136

@ -238,7 +238,7 @@ public class JdbcExchangeResourceRepository implements ExchangeResourceRepositor
"AND c.received_by_user_id=? AND r.status='RESERVED' " + "AND c.received_by_user_id=? AND r.status='RESERVED' " +
"AND c.complete_currency IS NOT NULL AND c.issuance_ownership_original_text IS NOT NULL " + "AND c.complete_currency IS NOT NULL AND c.issuance_ownership_original_text IS NOT NULL " +
"AND c.issuance_ownership_signature IS NOT NULL AND o.owner_type='BANK' AND o.owner_id=? " + "AND c.issuance_ownership_signature IS NOT NULL AND o.owner_type='BANK' AND o.owner_id=? " +
"AND o.status='LOCKED' AND o.lock_business_type='EXCHANGE' AND o.lock_business_id=?", "AND o.status='EXCHANGE_LOCKED' AND o.lock_business_type='EXCHANGE' AND o.lock_business_id=?",
Integer.class, order.getId().toString(), coin.getCurrencyId(), order.getBankCode(), Integer.class, order.getId().toString(), coin.getCurrencyId(), order.getBankCode(),
order.getOrganizationId(), actor.getUserId(), order.getBankCode(), order.getId().toString()); order.getOrganizationId(), actor.getUserId(), order.getBankCode(), order.getId().toString());
if (valid == null || valid != 1) { if (valid == null || valid != 1) {

@ -14,9 +14,9 @@ public class CurrencyOwnershipLockRepository {
public boolean tryLock(String currencyId, String ownerType, String ownerId, public boolean tryLock(String currencyId, String ownerType, String ownerId,
String businessType, String businessId) { String businessType, String businessId) {
return jdbc.update("UPDATE central_bank_currency_ownership " + return jdbc.update("UPDATE central_bank_currency_ownership " +
"SET status='LOCKED',lock_business_type=?,lock_business_id=?,updated_at=CURRENT_TIMESTAMP " + "SET status=?,lock_business_type=?,lock_business_id=?,updated_at=CURRENT_TIMESTAMP " +
"WHERE currency_id=? AND owner_type=? AND owner_id=? AND status='AVAILABLE'", "WHERE currency_id=? AND owner_type=? AND owner_id=? AND status='AVAILABLE'",
businessType, businessId, currencyId, ownerType, ownerId) == 1; lockStatus(businessType), businessType, businessId, currencyId, ownerType, ownerId) == 1;
} }
public boolean transferLocked(String currencyId, String ownerType, String ownerId, public boolean transferLocked(String currencyId, String ownerType, String ownerId,
@ -24,18 +24,24 @@ public class CurrencyOwnershipLockRepository {
String newOwnerType, String newOwnerId, String transactionId) { String newOwnerType, String newOwnerId, String transactionId) {
return jdbc.update("UPDATE central_bank_currency_ownership SET owner_type=?,owner_id=?,status='AVAILABLE'," + return jdbc.update("UPDATE central_bank_currency_ownership SET owner_type=?,owner_id=?,status='AVAILABLE'," +
"lock_business_type=NULL,lock_business_id=NULL,last_transaction_id=?,updated_at=CURRENT_TIMESTAMP " + "lock_business_type=NULL,lock_business_id=NULL,last_transaction_id=?,updated_at=CURRENT_TIMESTAMP " +
"WHERE currency_id=? AND owner_type=? AND owner_id=? AND status='LOCKED' " + "WHERE currency_id=? AND owner_type=? AND owner_id=? AND status=? " +
"AND lock_business_type=? AND lock_business_id=?", "AND lock_business_type=? AND lock_business_id=?",
newOwnerType, newOwnerId, transactionId, currencyId, ownerType, ownerId, newOwnerType, newOwnerId, transactionId, currencyId, ownerType, ownerId,
businessType, businessId) == 1; lockStatus(businessType), businessType, businessId) == 1;
} }
public boolean release(String currencyId, String ownerType, String ownerId, public boolean release(String currencyId, String ownerType, String ownerId,
String businessType, String businessId) { String businessType, String businessId) {
return jdbc.update("UPDATE central_bank_currency_ownership SET status='AVAILABLE'," + return jdbc.update("UPDATE central_bank_currency_ownership SET status='AVAILABLE'," +
"lock_business_type=NULL,lock_business_id=NULL,updated_at=CURRENT_TIMESTAMP " + "lock_business_type=NULL,lock_business_id=NULL,updated_at=CURRENT_TIMESTAMP " +
"WHERE currency_id=? AND owner_type=? AND owner_id=? AND status='LOCKED' " + "WHERE currency_id=? AND owner_type=? AND owner_id=? AND status=? " +
"AND lock_business_type=? AND lock_business_id=?", "AND lock_business_type=? AND lock_business_id=?",
currencyId, ownerType, ownerId, businessType, businessId) == 1; currencyId, ownerType, ownerId, lockStatus(businessType), businessType, businessId) == 1;
}
private String lockStatus(String businessType) {
if ("EXCHANGE".equals(businessType)) return "EXCHANGE_LOCKED";
if ("PAYMENT".equals(businessType)) return "PAYMENT_LOCKED";
throw new IllegalArgumentException("不支持的币串锁业务类型:" + businessType);
} }
} }

@ -206,7 +206,7 @@ class PaymentControllerTest {
.andExpect(jsonPath("$.data.coinCount").value(2)); .andExpect(jsonPath("$.data.coinCount").value(2));
assertThat(jdbc.queryForObject("SELECT status FROM central_bank_currency_ownership " + assertThat(jdbc.queryForObject("SELECT status FROM central_bank_currency_ownership " +
"WHERE currency_id='DC_PAYMENT_1'", String.class)).isEqualTo("LOCKED"); "WHERE currency_id='DC_PAYMENT_1'", String.class)).isEqualTo("PAYMENT_LOCKED");
assertThat(jdbc.queryForObject("SELECT lock_business_type FROM central_bank_currency_ownership " + assertThat(jdbc.queryForObject("SELECT lock_business_type FROM central_bank_currency_ownership " +
"WHERE currency_id='DC_PAYMENT_1'", String.class)).isEqualTo("PAYMENT"); "WHERE currency_id='DC_PAYMENT_1'", String.class)).isEqualTo("PAYMENT");
assertThat(jdbc.queryForObject("SELECT lock_business_id FROM central_bank_currency_ownership " + assertThat(jdbc.queryForObject("SELECT lock_business_id FROM central_bank_currency_ownership " +

@ -60,7 +60,7 @@ class CurrencyOwnershipConcurrencyTest {
List<Boolean> results = Arrays.asList(first.get(), second.get()); List<Boolean> results = Arrays.asList(first.get(), second.get());
assertThat(results).containsExactlyInAnyOrder(true, false); assertThat(results).containsExactlyInAnyOrder(true, false);
assertThat(jdbc.queryForObject("SELECT status FROM central_bank_currency_ownership WHERE currency_id=?", assertThat(jdbc.queryForObject("SELECT status FROM central_bank_currency_ownership WHERE currency_id=?",
String.class, CURRENCY_ID)).isEqualTo("LOCKED"); String.class, CURRENCY_ID)).isEqualTo("PAYMENT_LOCKED");
assertThat(jdbc.queryForObject("SELECT lock_business_id FROM central_bank_currency_ownership WHERE currency_id=?", assertThat(jdbc.queryForObject("SELECT lock_business_id FROM central_bank_currency_ownership WHERE currency_id=?",
String.class, CURRENCY_ID)).isIn("PAYMENT_A", "PAYMENT_B"); String.class, CURRENCY_ID)).isIn("PAYMENT_A", "PAYMENT_B");
} finally { } finally {

Loading…
Cancel
Save