feat: expose built-in currency demand data

master
chenyuan 4 weeks ago
parent 36b248dc9d
commit 79b1110c1f

@ -154,12 +154,9 @@ public class CommercialBankIssuanceApplicationService {
}
@Transactional(readOnly = true)
public CommercialBankInventoryView getInventory(String bankCode) {
if (bankCode == null) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "bank code must not be null");
}
IssuanceBankInventory inventory = repository.findInventoryByBankCode(bankCode).orElseThrow(() ->
new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "issuance bank inventory was not found: " + bankCode));
public CommercialBankInventoryView getInventory() {
IssuanceBankInventory inventory = repository.findBuiltInInventory().orElseThrow(() ->
new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "built-in issuance inventory was not found"));
return new CommercialBankInventoryView(inventory.getBankCode(), inventory.getCurrentBalance(),
inventory.getWarningThreshold(), inventory.getSuggestedSupplementAmount());
}

@ -15,5 +15,5 @@ public interface IssuanceRequestRepository {
Optional<IssuanceRequest> findById(IssuanceApplicationId id);
Optional<IssuanceBankInventory> findInventoryByBankCode(String bankCode);
Optional<IssuanceBankInventory> findBuiltInInventory();
}

@ -27,6 +27,7 @@ import java.util.UUID;
@Repository
public class MybatisIssuanceRequestRepository implements IssuanceRequestRepository {
private static final String BUILT_IN_INVENTORY_BANK_CODE = "BKCHCNBJ00001";
private final IssuanceRequestMapper requestMapper;
private final IssuanceRequestDenominationMapper denominationMapper;
private final IssuanceBankInventoryMapper inventoryMapper;
@ -98,8 +99,8 @@ public class MybatisIssuanceRequestRepository implements IssuanceRequestReposito
}
@Override
public Optional<IssuanceBankInventory> findInventoryByBankCode(String bankCode) {
IssuanceBankInventoryEntity inventory = inventoryMapper.selectById(bankCode);
public Optional<IssuanceBankInventory> findBuiltInInventory() {
IssuanceBankInventoryEntity inventory = inventoryMapper.selectById(BUILT_IN_INVENTORY_BANK_CODE);
if (inventory == null) {
return Optional.empty();
}

@ -28,7 +28,7 @@ public class CommercialBankIssuanceController {
private final CommercialBankIssuanceApplicationService service;
public CommercialBankIssuanceController(CommercialBankIssuanceApplicationService service){this.service=service;}
@GetMapping("/inventory") @Operation(summary="查询货币需求信息", description="商业银行端查询库存余额、预警阈值和建议补充金额")
public ApiResponse<CommercialBankInventoryView> inventory(@RequestParam String bankCode){return ok(service.getInventory(bankCode));}
public ApiResponse<CommercialBankInventoryView> inventory(){return ok(service.getInventory());}
@PostMapping("/requests") @Operation(summary="创建发行申请", description="商业银行端创建数字货币发行申请草稿")
public ApiResponse<IssuanceRequestView> create(@Valid @RequestBody CreateIssuanceRequest request,@AuthenticationPrincipal Jwt jwt){return ok(service.create(new CreateIssuanceRequestCommand(request.getBankCode(),request.getOrganizationId(),request.getTotalAmount(),request.getCurrency(),items(request.getDenominations())),actor(jwt)));}
@PutMapping("/requests/{id}") @Operation(summary="更新发行申请", description="商业银行端仅可更新草稿状态的发行申请")

@ -68,7 +68,7 @@ class CentralBankIssuanceQueryServiceTest {
}
@Override
public Optional<IssuanceBankInventory> findInventoryByBankCode(String bankCode) {
public Optional<IssuanceBankInventory> findBuiltInInventory() {
return Optional.empty();
}
}

@ -101,7 +101,7 @@ class CommercialBankIssuanceApplicationServiceTest {
}
@Override
public Optional<IssuanceBankInventory> findInventoryByBankCode(String bankCode) {
public Optional<IssuanceBankInventory> findBuiltInInventory() {
return Optional.empty();
}
}

@ -71,7 +71,7 @@ class MybatisIssuanceRequestRepositoryTest {
@Test
void readsSuggestedAmountAsThresholdMinusCurrentBalance() {
IssuanceBankInventory inventory = repository.findInventoryByBankCode("BKCHCNBJ00001")
IssuanceBankInventory inventory = repository.findBuiltInInventory()
.orElseThrow(() -> new AssertionError("seeded bank inventory was not found"));
assertThat(inventory.getCurrentBalance()).isEqualByComparingTo("49950000.00");
@ -79,21 +79,6 @@ class MybatisIssuanceRequestRepositoryTest {
assertThat(inventory.getSuggestedSupplementAmount()).isEqualByComparingTo("50000.00");
}
@Test
void clampsSuggestedAmountToZeroWhenBalanceExceedsThreshold() {
IssuanceBankInventoryEntity inventory = new IssuanceBankInventoryEntity();
inventory.setBankCode("BKCLAMP00001");
inventory.setCurrentBalance(new BigDecimal("60000000.00"));
inventory.setWarningThreshold(new BigDecimal("50000000.00"));
inventory.setUpdatedAt(java.time.LocalDateTime.now());
inventoryMapper.insert(inventory);
IssuanceBankInventory restored = repository.findInventoryByBankCode("BKCLAMP00001")
.orElseThrow(() -> new AssertionError("inventory was not restored"));
assertThat(restored.getSuggestedSupplementAmount()).isEqualByComparingTo("0.00");
}
@Test
void savingChangedDraftReplacesRatherThanAccumulatesDenominations() {
UUID id = UUID.randomUUID();

@ -52,6 +52,16 @@ class IssuanceControllerTest {
.andExpect(status().isOk()).andExpect(jsonPath("$.data.receiveStatus").value("RECEIVED"));
}
@Test
void readsBuiltInCurrencyDemandWithoutRequestParameters() throws Exception {
mockMvc.perform(get("/api/v1/commercial-banks/issuance/inventory")
.with(jwt().jwt(jwt -> jwt.subject("487").claim("preferred_username", "tzs001"))))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.currentBalance").value(49950000.00))
.andExpect(jsonPath("$.data.warningThreshold").value(50000000.00))
.andExpect(jsonPath("$.data.suggestedSupplementAmount").value(50000.00));
}
@Test
void swaggerDocumentsBothChineseIssuanceEnds() throws Exception {
String apiDocs = new String(mockMvc.perform(get("/v3/api-docs"))

Loading…
Cancel
Save