|
|
|
@ -31,10 +31,10 @@ public class IssuanceRequest {
|
|
|
|
|
|
|
|
|
|
|
|
private IssuanceRequest(IssuanceApplicationId id, String requestNo, String bankCode, String organizationId,
|
|
|
|
private IssuanceRequest(IssuanceApplicationId id, String requestNo, String bankCode, String organizationId,
|
|
|
|
BigDecimal totalAmount, String currency, List<DenominationItem> denominations) {
|
|
|
|
BigDecimal totalAmount, String currency, List<DenominationItem> denominations) {
|
|
|
|
this.id = Objects.requireNonNull(id, "id must not be null");
|
|
|
|
this.id = Objects.requireNonNull(id, "申请标识不能为空");
|
|
|
|
this.requestNo = Objects.requireNonNull(requestNo, "requestNo must not be null");
|
|
|
|
this.requestNo = Objects.requireNonNull(requestNo, "申请编号不能为空");
|
|
|
|
this.bankCode = Objects.requireNonNull(bankCode, "bankCode must not be null");
|
|
|
|
this.bankCode = Objects.requireNonNull(bankCode, "申请机构不能为空");
|
|
|
|
this.organizationId = Objects.requireNonNull(organizationId, "organizationId must not be null");
|
|
|
|
this.organizationId = Objects.requireNonNull(organizationId, "机构标识不能为空");
|
|
|
|
applyDraftValues(totalAmount, currency, denominations);
|
|
|
|
applyDraftValues(totalAmount, currency, denominations);
|
|
|
|
this.status = IssuanceRequestStatus.DRAFT;
|
|
|
|
this.status = IssuanceRequestStatus.DRAFT;
|
|
|
|
this.centralBankReceiveStatus = CentralBankReceiveStatus.NOT_RECEIVED;
|
|
|
|
this.centralBankReceiveStatus = CentralBankReceiveStatus.NOT_RECEIVED;
|
|
|
|
@ -185,34 +185,34 @@ public class IssuanceRequest {
|
|
|
|
List<DenominationItem> copiedDenominations = copyDenominations(denominations);
|
|
|
|
List<DenominationItem> copiedDenominations = copyDenominations(denominations);
|
|
|
|
BigDecimal denominationTotal = calculateDenominationTotal(copiedDenominations);
|
|
|
|
BigDecimal denominationTotal = calculateDenominationTotal(copiedDenominations);
|
|
|
|
if (denominationTotal.compareTo(normalizedAmount) != 0) {
|
|
|
|
if (denominationTotal.compareTo(normalizedAmount) != 0) {
|
|
|
|
throw new IllegalArgumentException("denomination total must equal totalAmount");
|
|
|
|
throw new IllegalArgumentException("各面额小计之和必须等于申请总金额");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String validatedCurrency = Objects.requireNonNull(currency, "currency must not be null");
|
|
|
|
String validatedCurrency = Objects.requireNonNull(currency, "币种不能为空");
|
|
|
|
this.totalAmount = normalizedAmount;
|
|
|
|
this.totalAmount = normalizedAmount;
|
|
|
|
this.currency = validatedCurrency;
|
|
|
|
this.currency = validatedCurrency;
|
|
|
|
this.denominations = Collections.unmodifiableList(copiedDenominations);
|
|
|
|
this.denominations = Collections.unmodifiableList(copiedDenominations);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal normalizeAmount(BigDecimal totalAmount) {
|
|
|
|
private BigDecimal normalizeAmount(BigDecimal totalAmount) {
|
|
|
|
BigDecimal amount = Objects.requireNonNull(totalAmount, "totalAmount must not be null")
|
|
|
|
BigDecimal amount = Objects.requireNonNull(totalAmount, "申请总金额不能为空")
|
|
|
|
.setScale(2, RoundingMode.UNNECESSARY);
|
|
|
|
.setScale(2, RoundingMode.UNNECESSARY);
|
|
|
|
if (amount.signum() <= 0) {
|
|
|
|
if (amount.signum() <= 0) {
|
|
|
|
throw new IllegalArgumentException("totalAmount must be positive");
|
|
|
|
throw new IllegalArgumentException("申请总金额必须大于零");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return amount;
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<DenominationItem> copyDenominations(List<DenominationItem> denominations) {
|
|
|
|
private List<DenominationItem> copyDenominations(List<DenominationItem> denominations) {
|
|
|
|
List<DenominationItem> copiedDenominations = new ArrayList<DenominationItem>(
|
|
|
|
List<DenominationItem> copiedDenominations = new ArrayList<DenominationItem>(
|
|
|
|
Objects.requireNonNull(denominations, "denominations must not be null"));
|
|
|
|
Objects.requireNonNull(denominations, "面额明细不能为空"));
|
|
|
|
if (copiedDenominations.isEmpty()) {
|
|
|
|
if (copiedDenominations.isEmpty()) {
|
|
|
|
throw new IllegalArgumentException("denominations must not be empty");
|
|
|
|
throw new IllegalArgumentException("面额明细不能为空");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<BigDecimal> faceValues = new HashSet<BigDecimal>();
|
|
|
|
Set<BigDecimal> faceValues = new HashSet<BigDecimal>();
|
|
|
|
for (DenominationItem denomination : copiedDenominations) {
|
|
|
|
for (DenominationItem denomination : copiedDenominations) {
|
|
|
|
Objects.requireNonNull(denomination, "denomination item must not be null");
|
|
|
|
Objects.requireNonNull(denomination, "面额明细不能为空");
|
|
|
|
if (!faceValues.add(denomination.getDenomination().stripTrailingZeros())) {
|
|
|
|
if (!faceValues.add(denomination.getDenomination().stripTrailingZeros())) {
|
|
|
|
throw new IllegalArgumentException("denomination values must be unique");
|
|
|
|
throw new IllegalArgumentException("面额不能重复");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return copiedDenominations;
|
|
|
|
return copiedDenominations;
|
|
|
|
@ -229,7 +229,7 @@ public class IssuanceRequest {
|
|
|
|
|
|
|
|
|
|
|
|
private void requireStatus(IssuanceRequestStatus expectedStatus) {
|
|
|
|
private void requireStatus(IssuanceRequestStatus expectedStatus) {
|
|
|
|
if (status != expectedStatus) {
|
|
|
|
if (status != expectedStatus) {
|
|
|
|
throw new IllegalStateException("expected status " + expectedStatus + " but was " + status);
|
|
|
|
throw new IllegalStateException("当前申请状态不允许此操作");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|