|
|
|
@ -3,6 +3,7 @@ package com.yau.digitalrmb.institutionidentity;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeyService;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeyService;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
|
|
|
|
|
|
|
|
import com.yau.digitalrmb.institutionidentity.application.InstitutionTrainingResetService;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.domain.InstitutionIdentityCryptography;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.domain.InstitutionIdentityCryptography;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestEntity;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestEntity;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestMapper;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestMapper;
|
|
|
|
@ -51,6 +52,7 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
@Autowired private StuModuleScoreDetailsMapper scoreMapper;
|
|
|
|
@Autowired private StuModuleScoreDetailsMapper scoreMapper;
|
|
|
|
@Autowired private InstitutionIdentityCryptography cryptography;
|
|
|
|
@Autowired private InstitutionIdentityCryptography cryptography;
|
|
|
|
@Autowired private InstitutionKeyService keyService;
|
|
|
|
@Autowired private InstitutionKeyService keyService;
|
|
|
|
|
|
|
|
@Autowired private InstitutionTrainingResetService resetService;
|
|
|
|
|
|
|
|
|
|
|
|
private String authorization;
|
|
|
|
private String authorization;
|
|
|
|
private String bankPublicKey;
|
|
|
|
private String bankPublicKey;
|
|
|
|
@ -127,8 +129,8 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(1589.85))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(0.00))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.currentAmount").value(1589.85))
|
|
|
|
.andExpect(jsonPath("$.data.currentAmount").value(1589.85))
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true))
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true))
|
|
|
|
.andExpect(jsonPath("$.data.verificationId").doesNotExist())
|
|
|
|
.andExpect(jsonPath("$.data.verificationId").doesNotExist())
|
|
|
|
@ -136,8 +138,8 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(1589.85))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(0.00))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/calculate-digest").header("Authorization", authorization)
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/calculate-digest").header("Authorization", authorization)
|
|
|
|
.contentType("application/json").content(digestStep(verificationId,
|
|
|
|
.contentType("application/json").content(digestStep(verificationId,
|
|
|
|
@ -171,8 +173,8 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(1589.85))
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(0.00))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/package-response").header("Authorization", authorization))
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/package-response").header("Authorization", authorization))
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
@ -199,7 +201,7 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
|
|
|
|
|
|
|
|
CurrencyGenerationVerificationEntity stored = verificationMapper.selectById(verificationId);
|
|
|
|
CurrencyGenerationVerificationEntity stored = verificationMapper.selectById(verificationId);
|
|
|
|
assertThat(stored.getTotalQuota()).isEqualByComparingTo("50000.00");
|
|
|
|
assertThat(stored.getTotalQuota()).isEqualByComparingTo("50000.00");
|
|
|
|
assertThat(stored.getUsedQuota()).isEqualByComparingTo("1589.85");
|
|
|
|
assertThat(stored.getUsedQuota()).isEqualByComparingTo("0.00");
|
|
|
|
assertThat(stored.getRemainingQuota()).isEqualByComparingTo("48410.15");
|
|
|
|
assertThat(stored.getRemainingQuota()).isEqualByComparingTo("48410.15");
|
|
|
|
assertThat(stored.getAmount()).isEqualByComparingTo("1589.85");
|
|
|
|
assertThat(stored.getAmount()).isEqualByComparingTo("1589.85");
|
|
|
|
assertThat(stored.getConfirmationMessage()).contains("CONFIRMED", "cbSignature", "confirmTime");
|
|
|
|
assertThat(stored.getConfirmationMessage()).contains("CONFIRMED", "cbSignature", "confirmTime");
|
|
|
|
@ -322,16 +324,46 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void globalQuotaCountsOtherSubjectsAndIgnoresDeletedRequests() {
|
|
|
|
void quotaIsolatedToCurrentSubjectAndIgnoresDeletedRequests() {
|
|
|
|
CurrencyGenerationRequestEntity active = quotaRequest("other-user", new BigDecimal("42000.00"), false);
|
|
|
|
// 其他用户/班级的活跃申请不计入当前实训主体额度
|
|
|
|
requestMapper.insert(active);
|
|
|
|
CurrencyGenerationRequestEntity other = quotaRequest("other-user", new BigDecimal("42000.00"), false, 9999L, 9999L);
|
|
|
|
CurrencyGenerationRequestEntity deleted = quotaRequest("deleted-user", new BigDecimal("7000.00"), true);
|
|
|
|
requestMapper.insert(other);
|
|
|
|
|
|
|
|
// 当前主体但已逻辑删除的申请不计入(重新实训后额度恢复的机制)
|
|
|
|
|
|
|
|
CurrencyGenerationRequestEntity deleted = quotaRequest(USER_ID, new BigDecimal("7000.00"), true, SCHOOL_ID, CLASS_ID);
|
|
|
|
requestMapper.insert(deleted);
|
|
|
|
requestMapper.insert(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(requestMapper.sumActiveAmount()).isEqualByComparingTo("43589.85");
|
|
|
|
// 仅 setUp 中当前主体的 1589.85 计入
|
|
|
|
|
|
|
|
assertThat(requestMapper.sumActiveAmount(USER_ID, SCHOOL_ID, CLASS_ID)).isEqualByComparingTo("1589.85");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private CurrencyGenerationRequestEntity quotaRequest(String userId, BigDecimal amount, boolean deleted) {
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void quotaVerificationIgnoresOtherSubjectsRequests() throws Exception {
|
|
|
|
|
|
|
|
// 其他用户/班级的大额活跃申请,不应影响当前主体的额度校验
|
|
|
|
|
|
|
|
CurrencyGenerationRequestEntity other = quotaRequest("other-user", new BigDecimal("49000.00"), false, 9999L, 9999L);
|
|
|
|
|
|
|
|
requestMapper.insert(other);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/receive").header("Authorization", authorization)
|
|
|
|
|
|
|
|
.contentType("application/json").content("{\"requestId\":" + requestId + "}"))
|
|
|
|
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
|
|
|
|
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
|
|
|
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
|
|
|
.andExpect(jsonPath("$.data.usedQuota").value(0.00))
|
|
|
|
|
|
|
|
.andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
|
|
|
|
|
|
|
|
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void resetRestoresQuotaForCurrentSubject() {
|
|
|
|
|
|
|
|
// setUp 中当前主体已有一条 1589.85 的活跃申请
|
|
|
|
|
|
|
|
assertThat(requestMapper.sumActiveAmount(USER_ID, SCHOOL_ID, CLASS_ID)).isEqualByComparingTo("1589.85");
|
|
|
|
|
|
|
|
// 重新实训:按当前实训主体(用户+学校+班级)逻辑删除其所有申请
|
|
|
|
|
|
|
|
resetService.reset(new InstitutionKeySubject(USER_ID, SCHOOL_ID, CLASS_ID));
|
|
|
|
|
|
|
|
// 额度恢复为 0
|
|
|
|
|
|
|
|
assertThat(requestMapper.sumActiveAmount(USER_ID, SCHOOL_ID, CLASS_ID)).isEqualByComparingTo("0.00");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CurrencyGenerationRequestEntity quotaRequest(String userId, BigDecimal amount, boolean deleted,
|
|
|
|
|
|
|
|
long schoolId, long classId) {
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
CurrencyGenerationRequestEntity request = new CurrencyGenerationRequestEntity();
|
|
|
|
CurrencyGenerationRequestEntity request = new CurrencyGenerationRequestEntity();
|
|
|
|
request.setIdentifierApplicationId(requestMapper.selectById(requestId).getIdentifierApplicationId());
|
|
|
|
request.setIdentifierApplicationId(requestMapper.selectById(requestId).getIdentifierApplicationId());
|
|
|
|
@ -340,7 +372,7 @@ class CurrencyGenerationVerificationControllerTest {
|
|
|
|
request.setDeliveryNodeCode("SYS_GLOBAL"); request.setRequestTimestamp("20260806210000");
|
|
|
|
request.setDeliveryNodeCode("SYS_GLOBAL"); request.setRequestTimestamp("20260806210000");
|
|
|
|
request.setRequestOriginalText("quota"); request.setRequestDigest("A"); request.setBankSignature("B");
|
|
|
|
request.setRequestOriginalText("quota"); request.setRequestDigest("A"); request.setBankSignature("B");
|
|
|
|
request.setSigningKeyId(InstitutionKeyService.BANK_SECOND_KEY); request.setRequestMessage("{}");
|
|
|
|
request.setSigningKeyId(InstitutionKeyService.BANK_SECOND_KEY); request.setRequestMessage("{}");
|
|
|
|
request.setStatus("RECEIVED"); request.setUserId(userId); request.setSchoolId(9999L); request.setClassId(9999L);
|
|
|
|
request.setStatus("RECEIVED"); request.setUserId(userId); request.setSchoolId(schoolId); request.setClassId(classId);
|
|
|
|
request.setCreatedAt(now); request.setUpdatedAt(now); request.setCreatedBy(userId); request.setUpdatedBy(userId);
|
|
|
|
request.setCreatedAt(now); request.setUpdatedAt(now); request.setCreatedBy(userId); request.setUpdatedBy(userId);
|
|
|
|
request.setDeleted(deleted);
|
|
|
|
request.setDeleted(deleted);
|
|
|
|
return request;
|
|
|
|
return request;
|
|
|
|
|