fix(issuance): 校验申请金额不超过建议补充额

chore/issuance-comments-zh
chenyuan 3 weeks ago
parent 32c5cae953
commit 72b771b409

@ -91,6 +91,7 @@ public class CommercialBankIssuanceApplicationService {
@Transactional @Transactional
public IssuanceRequestView create(CreateIssuanceRequestCommand command, IssuanceAuditActor auditActor) { public IssuanceRequestView create(CreateIssuanceRequestCommand command, IssuanceAuditActor auditActor) {
try { try {
requireAmountWithinSuggestedSupplement(command.getTotalAmount());
UUID id = UUID.randomUUID(); UUID id = UUID.randomUUID();
IssuanceRequest request = IssuanceRequest.create(new IssuanceApplicationId(id), requestNo(id), IssuanceRequest request = IssuanceRequest.create(new IssuanceApplicationId(id), requestNo(id),
command.getBankCode(), command.getOrganizationId(), command.getTotalAmount(), command.getCurrency(), command.getBankCode(), command.getOrganizationId(), command.getTotalAmount(), command.getCurrency(),
@ -110,6 +111,7 @@ public class CommercialBankIssuanceApplicationService {
public IssuanceRequestView update(UUID id, UpdateIssuanceRequestCommand command, IssuanceAuditActor auditActor) { public IssuanceRequestView update(UUID id, UpdateIssuanceRequestCommand command, IssuanceAuditActor auditActor) {
try { try {
IssuanceRequest request = requireOwnedRequestForUpdate(id, auditActor); IssuanceRequest request = requireOwnedRequestForUpdate(id, auditActor);
requireAmountWithinSuggestedSupplement(command.getTotalAmount());
request.updateDraft(command.getTotalAmount(), command.getCurrency(), command.getDenominations()); request.updateDraft(command.getTotalAmount(), command.getCurrency(), command.getDenominations());
repository.save(request, auditActor(auditActor)); repository.save(request, auditActor(auditActor));
return IssuanceRequestView.from(request); return IssuanceRequestView.from(request);
@ -237,6 +239,19 @@ public class CommercialBankIssuanceApplicationService {
inventory.getWarningThreshold(), inventory.getSuggestedSupplementAmount()); inventory.getWarningThreshold(), inventory.getSuggestedSupplementAmount());
} }
private void requireAmountWithinSuggestedSupplement(BigDecimal requestedAmount) {
if (requestedAmount == null) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "申请发行金额不能为空");
}
IssuanceBankInventory inventory = repository.findBuiltInInventory().orElseThrow(() ->
new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "发行库存配置不存在"));
if (requestedAmount.compareTo(inventory.getSuggestedSupplementAmount()) > 0) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR,
"申请发行金额不得超过建议补充金额 "
+ inventory.getSuggestedSupplementAmount().setScale(2).toPlainString() + " 元");
}
}
private IssuanceRequest requireRequest(UUID id) { private IssuanceRequest requireRequest(UUID id) {
if (id == null) { if (id == null) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "发行申请标识不能为空"); throw new BusinessException(ErrorCode.VALIDATION_ERROR, "发行申请标识不能为空");

@ -135,9 +135,33 @@ class CommercialBankIssuanceApplicationServiceTest {
.isEqualTo(ErrorCode.UNAUTHORIZED); .isEqualTo(ErrorCode.UNAUTHORIZED);
} }
@Test
void acceptsAmountBelowSuggestedSupplementWhenDenominationsMatch() {
IssuanceRequestView created = service.create(createCommand(new BigDecimal("40000.00"), 300), "tzs001");
assertThat(created.getTotalAmount()).isEqualByComparingTo("40000.00");
}
@Test
void rejectsAmountAboveSuggestedSupplement() {
assertThatThrownBy(() -> service.create(
createCommand(new BigDecimal("50100.00"), 401), "tzs001"))
.isInstanceOf(BusinessException.class)
.satisfies(exception -> {
BusinessException businessException = (BusinessException) exception;
assertThat(businessException.getErrorCode()).isEqualTo(ErrorCode.VALIDATION_ERROR);
assertThat(businessException.getMessage())
.isEqualTo("申请发行金额不得超过建议补充金额 50000.00 元");
});
}
private CreateIssuanceRequestCommand createCommand() { private CreateIssuanceRequestCommand createCommand() {
return new CreateIssuanceRequestCommand("BKCHCNBJ00001", "ORG_3A4B5C6D7E8F", new BigDecimal("50000.00"), return createCommand(new BigDecimal("50000.00"), 400);
"DC", Arrays.asList(new DenominationItem(100, 400), new DenominationItem(50, 100), }
private CreateIssuanceRequestCommand createCommand(BigDecimal totalAmount, int hundredQuantity) {
return new CreateIssuanceRequestCommand("BKCHCNBJ00001", "ORG_3A4B5C6D7E8F", totalAmount,
"DC", Arrays.asList(new DenominationItem(100, hundredQuantity), new DenominationItem(50, 100),
new DenominationItem(20, 200), new DenominationItem(10, 50), new DenominationItem(5, 80), new DenominationItem(20, 200), new DenominationItem(10, 50), new DenominationItem(5, 80),
new DenominationItem(1, 100), new DenominationItem(new BigDecimal("0.5"), 0), new DenominationItem(1, 100), new DenominationItem(new BigDecimal("0.5"), 0),
new DenominationItem(new BigDecimal("0.2"), 0), new DenominationItem(new BigDecimal("0.1"), 0), new DenominationItem(new BigDecimal("0.2"), 0), new DenominationItem(new BigDecimal("0.1"), 0),
@ -159,7 +183,8 @@ class CommercialBankIssuanceApplicationServiceTest {
@Override @Override
public Optional<IssuanceBankInventory> findBuiltInInventory() { public Optional<IssuanceBankInventory> findBuiltInInventory() {
return Optional.empty(); return Optional.of(new IssuanceBankInventory("BKCHCNBJ00001", new BigDecimal("49960000.00"),
new BigDecimal("50000000.00"), new BigDecimal("50000.00")));
} }
} }

Loading…
Cancel
Save