|
|
|
@ -22,9 +22,16 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
private static final String BANK_A = "BKCHCNBJ00001";
|
|
|
|
private static final String BANK_A = "BKCHCNBJ00001";
|
|
|
|
private static final String BANK_B = "BKCHCNBJ00002";
|
|
|
|
private static final String BANK_B = "BKCHCNBJ00002";
|
|
|
|
private static final String PAYEE_A_USER = "00000000-0000-0000-0000-000000000951";
|
|
|
|
private static final String PAYEE_A_USER = "00000000-0000-0000-0000-000000000951";
|
|
|
|
private static final String PAYEE_B_USER = "00000000-0000-0000-0000-000000000952";
|
|
|
|
private static final String PAYEE_B_USER = "00000000-0000-0000-0000-000000000953";
|
|
|
|
private static final String PAYEE_A_WALLET = "WALLET_TRAINING_PAYEE_A";
|
|
|
|
private static final String PAYEE_A_WALLET = "WALLET_TRAINING_PAYEE_A";
|
|
|
|
private static final String PAYEE_B_WALLET = "WALLET_TRAINING_PAYEE_B";
|
|
|
|
private static final String PAYEE_B_WALLET =
|
|
|
|
|
|
|
|
"WALLET_B_7D8E9F0A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0C1D2E3F4A5B6";
|
|
|
|
|
|
|
|
private static final PayeeDefinition PAYEE_A = new PayeeDefinition(
|
|
|
|
|
|
|
|
PAYEE_A_USER, PAYEE_A_WALLET, "TYPE_II", "CERT_" + PAYEE_A_WALLET,
|
|
|
|
|
|
|
|
BANK_A, "教学商业银行A", "ORG_TRAINING_PAYEE_A");
|
|
|
|
|
|
|
|
private static final PayeeDefinition PAYEE_B = new PayeeDefinition(
|
|
|
|
|
|
|
|
PAYEE_B_USER, PAYEE_B_WALLET, "一类钱包", "00C3D4E5F6A7B890",
|
|
|
|
|
|
|
|
BANK_B, "建设银行(BKCHCNBJ00002)", "ORG_5F6G7B8E9G0W");
|
|
|
|
|
|
|
|
|
|
|
|
private final JdbcTemplate jdbc;
|
|
|
|
private final JdbcTemplate jdbc;
|
|
|
|
private final InstitutionIdentityCryptography cryptography;
|
|
|
|
private final InstitutionIdentityCryptography cryptography;
|
|
|
|
@ -39,9 +46,21 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public WalletPrerequisiteReference resolveForDifferentBank(String payerBankCode) {
|
|
|
|
public WalletPrerequisiteReference resolveForDifferentBank(String payerBankCode) {
|
|
|
|
PayeeDefinition payee = BANK_B.equals(payerBankCode)
|
|
|
|
return resolve(BANK_B.equals(payerBankCode) ? PAYEE_A : PAYEE_B);
|
|
|
|
? new PayeeDefinition(PAYEE_A_USER, PAYEE_A_WALLET, BANK_A, "教学商业银行A", "ORG_TRAINING_PAYEE_A")
|
|
|
|
}
|
|
|
|
: new PayeeDefinition(PAYEE_B_USER, PAYEE_B_WALLET, BANK_B, "教学商业银行B", "ORG_TRAINING_PAYEE_B");
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isTeachingWallet(String walletId) {
|
|
|
|
|
|
|
|
return definitionFor(walletId) != null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public WalletPrerequisiteReference resolve(String walletId) {
|
|
|
|
|
|
|
|
PayeeDefinition payee = definitionFor(walletId);
|
|
|
|
|
|
|
|
if (payee == null) throw conflict("教学收款方钱包不存在");
|
|
|
|
|
|
|
|
return resolve(payee);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private WalletPrerequisiteReference resolve(PayeeDefinition payee) {
|
|
|
|
ensureWallet(payee);
|
|
|
|
ensureWallet(payee);
|
|
|
|
ensureCertificate(payee);
|
|
|
|
ensureCertificate(payee);
|
|
|
|
ensureBankAccount(payee);
|
|
|
|
ensureBankAccount(payee);
|
|
|
|
@ -50,6 +69,12 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
payee.bankCode, payee.organizationId);
|
|
|
|
payee.bankCode, payee.organizationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PayeeDefinition definitionFor(String walletId) {
|
|
|
|
|
|
|
|
if (PAYEE_A_WALLET.equals(walletId)) return PAYEE_A;
|
|
|
|
|
|
|
|
if (PAYEE_B_WALLET.equals(walletId)) return PAYEE_B;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ensureWallet(PayeeDefinition payee) {
|
|
|
|
private void ensureWallet(PayeeDefinition payee) {
|
|
|
|
List<WalletRow> wallets = jdbc.query("SELECT user_id,wallet_type,status FROM digital_wallet WHERE wallet_id=?",
|
|
|
|
List<WalletRow> wallets = jdbc.query("SELECT user_id,wallet_type,status FROM digital_wallet WHERE wallet_id=?",
|
|
|
|
(rs, row) -> new WalletRow(rs.getString("user_id"), rs.getString("wallet_type"),
|
|
|
|
(rs, row) -> new WalletRow(rs.getString("user_id"), rs.getString("wallet_type"),
|
|
|
|
@ -58,15 +83,20 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
jdbc.update("INSERT INTO digital_wallet (wallet_id,user_id,wallet_type,status,balance,frozen_amount," +
|
|
|
|
jdbc.update("INSERT INTO digital_wallet (wallet_id,user_id,wallet_type,status,balance,frozen_amount," +
|
|
|
|
"central_bank_confirmation_signature,opened_at,created_at,updated_at) " +
|
|
|
|
"central_bank_confirmation_signature,opened_at,created_at,updated_at) " +
|
|
|
|
"VALUES (?,?, 'TYPE_II','ACTIVE',0,0,'TEACHING_PAYEE_CONFIRMED',CURRENT_TIMESTAMP," +
|
|
|
|
"VALUES (?,?, ?,'ACTIVE',0,0,'TEACHING_PAYEE_CONFIRMED',CURRENT_TIMESTAMP," +
|
|
|
|
"CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", payee.walletId, payee.userId);
|
|
|
|
"CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", payee.walletId, payee.userId, payee.walletType);
|
|
|
|
} catch (DuplicateKeyException exception) {
|
|
|
|
} catch (DuplicateKeyException exception) {
|
|
|
|
|
|
|
|
List<WalletRow> afterConflict = jdbc.query(
|
|
|
|
|
|
|
|
"SELECT user_id,wallet_type,status FROM digital_wallet WHERE wallet_id=?",
|
|
|
|
|
|
|
|
(rs, row) -> new WalletRow(rs.getString("user_id"), rs.getString("wallet_type"),
|
|
|
|
|
|
|
|
rs.getString("status")), payee.walletId);
|
|
|
|
|
|
|
|
if (afterConflict.isEmpty()) throw conflict("教学收款方的钱包标识或用户标识已被占用");
|
|
|
|
ensureWallet(payee);
|
|
|
|
ensureWallet(payee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WalletRow wallet = wallets.get(0);
|
|
|
|
WalletRow wallet = wallets.get(0);
|
|
|
|
if (!payee.userId.equals(wallet.userId) || !"TYPE_II".equals(wallet.walletType)
|
|
|
|
if (!payee.userId.equals(wallet.userId) || !payee.walletType.equals(wallet.walletType)
|
|
|
|
|| !"ACTIVE".equals(wallet.status)) {
|
|
|
|
|| !"ACTIVE".equals(wallet.status)) {
|
|
|
|
throw conflict("教学收款方钱包状态或归属异常");
|
|
|
|
throw conflict("教学收款方钱包状态或归属异常");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -81,7 +111,7 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
jdbc.update("INSERT INTO wallet_certificate (certificate_serial,wallet_id,public_key,encrypted_private_key," +
|
|
|
|
jdbc.update("INSERT INTO wallet_certificate (certificate_serial,wallet_id,public_key,encrypted_private_key," +
|
|
|
|
"filing_status,central_bank_root_signature,status,issued_at) " +
|
|
|
|
"filing_status,central_bank_root_signature,status,issued_at) " +
|
|
|
|
"VALUES (?,?,?,?, 'REGISTERED','TEACHING_PAYEE_ROOT','VALID',CURRENT_TIMESTAMP)",
|
|
|
|
"VALUES (?,?,?,?, 'REGISTERED','TEACHING_PAYEE_ROOT','VALID',CURRENT_TIMESTAMP)",
|
|
|
|
"CERT_" + payee.walletId, payee.walletId, keyPair.getPublicKey(),
|
|
|
|
payee.certificateSerial, payee.walletId, keyPair.getPublicKey(),
|
|
|
|
walletCipher.encrypt(keyPair.getPrivateKey()));
|
|
|
|
walletCipher.encrypt(keyPair.getPrivateKey()));
|
|
|
|
} catch (DuplicateKeyException exception) {
|
|
|
|
} catch (DuplicateKeyException exception) {
|
|
|
|
ensureCertificate(payee);
|
|
|
|
ensureCertificate(payee);
|
|
|
|
@ -137,14 +167,19 @@ public class TeachingPaymentPayeeWhitelist {
|
|
|
|
private static final class PayeeDefinition {
|
|
|
|
private static final class PayeeDefinition {
|
|
|
|
private final String userId;
|
|
|
|
private final String userId;
|
|
|
|
private final String walletId;
|
|
|
|
private final String walletId;
|
|
|
|
|
|
|
|
private final String walletType;
|
|
|
|
|
|
|
|
private final String certificateSerial;
|
|
|
|
private final String bankCode;
|
|
|
|
private final String bankCode;
|
|
|
|
private final String bankName;
|
|
|
|
private final String bankName;
|
|
|
|
private final String organizationId;
|
|
|
|
private final String organizationId;
|
|
|
|
|
|
|
|
|
|
|
|
private PayeeDefinition(String userId, String walletId, String bankCode, String bankName,
|
|
|
|
private PayeeDefinition(String userId, String walletId, String walletType, String certificateSerial,
|
|
|
|
|
|
|
|
String bankCode, String bankName,
|
|
|
|
String organizationId) {
|
|
|
|
String organizationId) {
|
|
|
|
this.userId = userId;
|
|
|
|
this.userId = userId;
|
|
|
|
this.walletId = walletId;
|
|
|
|
this.walletId = walletId;
|
|
|
|
|
|
|
|
this.walletType = walletType;
|
|
|
|
|
|
|
|
this.certificateSerial = certificateSerial;
|
|
|
|
this.bankCode = bankCode;
|
|
|
|
this.bankCode = bankCode;
|
|
|
|
this.bankName = bankName;
|
|
|
|
this.bankName = bankName;
|
|
|
|
this.organizationId = organizationId;
|
|
|
|
this.organizationId = organizationId;
|
|
|
|
|