From a6a83e5bd5375876e901f5dac017be457e70bfc4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E4=BD=B3=E6=AD=A3?= <2624533894@qq.com>
Date: Fri, 23 Oct 2026 18:21:04 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?=
=?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 9 +++
.../application/CorporateWalletService.java | 4 +-
.../application/RemoteWalletService.java | 4 +-
...CurrencyGenerationVerificationService.java | 14 +++--
.../CurrencyQuotaVerificationResult.java | 6 +-
.../CurrencyGenerationRequestMapper.java | 9 ++-
...yGenerationVerificationControllerTest.java | 60 ++++++++++++++-----
7 files changed, 78 insertions(+), 28 deletions(-)
diff --git a/pom.xml b/pom.xml
index 81c4036..ceacb85 100644
--- a/pom.xml
+++ b/pom.xml
@@ -145,6 +145,15 @@
maven-compiler-plugin
true
+ false
+ 768m
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 0
diff --git a/src/main/java/com/yau/digitalrmb/corporatewallet/application/CorporateWalletService.java b/src/main/java/com/yau/digitalrmb/corporatewallet/application/CorporateWalletService.java
index 36ee5f8..01e3c38 100644
--- a/src/main/java/com/yau/digitalrmb/corporatewallet/application/CorporateWalletService.java
+++ b/src/main/java/com/yau/digitalrmb/corporatewallet/application/CorporateWalletService.java
@@ -192,8 +192,8 @@ public class CorporateWalletService {
app.getWalletType(), "ACTIVATED", remoteActivated.getActivateTime(), "远程开立");
}
- // 钱包ID基于统一社会信用代码生成,确保同一企业无论通过哪个渠道开立,钱包ID都一致
- String walletId = "CORP_" + cryptography.sm3(app.getCreditCode());
+ // 钱包ID直接使用步骤一SM3摘要运算生成的摘要值
+ String walletId = app.getDigestValue();
String activateTime = app.getVerifyTime() != null ? app.getVerifyTime()
: LocalDateTime.now().format(TIMESTAMP_FORMAT);
diff --git a/src/main/java/com/yau/digitalrmb/corporatewallet/application/RemoteWalletService.java b/src/main/java/com/yau/digitalrmb/corporatewallet/application/RemoteWalletService.java
index fb53187..bd5c20f 100644
--- a/src/main/java/com/yau/digitalrmb/corporatewallet/application/RemoteWalletService.java
+++ b/src/main/java/com/yau/digitalrmb/corporatewallet/application/RemoteWalletService.java
@@ -325,8 +325,8 @@ public class RemoteWalletService {
app.getWalletType(), "ACTIVATED", corpActivated.getActivateTime(), "已验证", "临柜开立");
}
- // 钱包ID基于统一社会信用代码生成,确保同一企业无论通过哪个渠道开立,钱包ID都一致
- String walletId = "CORP_" + cryptography.sm3(app.getCreditCode());
+ // 钱包ID直接使用钱包SM3摘要运算生成的摘要值
+ String walletId = app.getWalletDigestValue();
String activateTime = app.getSignTime() != null ? app.getSignTime()
: LocalDateTime.now().format(TIMESTAMP_FORMAT);
diff --git a/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyGenerationVerificationService.java b/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyGenerationVerificationService.java
index e33f035..0de9a0e 100644
--- a/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyGenerationVerificationService.java
+++ b/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyGenerationVerificationService.java
@@ -104,21 +104,25 @@ public class CurrencyGenerationVerificationService {
@Transactional
public CurrencyQuotaVerificationResult verifyQuota(InstitutionKeySubject subject, String operator) {
- // 额度验证是每个用户独立的,使用当前用户的记录
+ // 额度按当前实训主体(用户+学校+班级)隔离,只统计该主体未逻辑删除的申请;
+ // 重新实训(InstitutionTrainingResetService.logicalDeleteRequests)会按同一维度逻辑删除申请,额度随之恢复
CurrencyGenerationVerification value = requireLatest(subject);
-
+
// 【幂等性检查】如果已经验证过,直接返回结果,不执行任何更新操作
if (value.getStatus().ordinal() >= CurrencyGenerationVerification.Status.QUOTA_VERIFIED.ordinal()) {
return new CurrencyQuotaVerificationResult(value);
}
-
- BigDecimal usedQuota = requestMapper.sumActiveAmount();
+
+ // 最新一次(本次)申请已随步骤二落库,不能计入已用额度:扣除当前验证记录的申请金额
+ BigDecimal usedQuota = requestMapper.sumActiveAmount(subject.getUserId(),
+ subject.getSchoolId(), subject.getClassId())
+ .subtract(value.getAmount()).max(BigDecimal.ZERO);
BigDecimal remainingQuota = TOTAL_QUOTA.subtract(usedQuota).max(BigDecimal.ZERO);
CurrencyGenerationVerification.Status expected = value.getStatus();
invoke(() -> value.verifyQuota(TOTAL_QUOTA, usedQuota, remainingQuota));
repository.update(value, expected, "VERIFY_QUOTA",
- "验证全系统50000元实训额度,累计已用额度包含本次申请金额", operator);
+ "验证当前主体50000元实训额度,已用额度不含本次申请金额", operator);
return new CurrencyQuotaVerificationResult(value);
}
diff --git a/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyQuotaVerificationResult.java b/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyQuotaVerificationResult.java
index d5ca819..a525f5f 100644
--- a/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyQuotaVerificationResult.java
+++ b/src/main/java/com/yau/digitalrmb/institutionidentity/application/CurrencyQuotaVerificationResult.java
@@ -9,11 +9,11 @@ import java.math.BigDecimal;
@ApiModel(description = "货币生成的步骤三额度验证结果")
@Schema(description = "货币生成的步骤三额度验证结果")
public class CurrencyQuotaVerificationResult {
- @Schema(description = "整个系统一次实训可申请的总额度", example = "50000.00")
+ @Schema(description = "当前实训主体(用户+学校+班级)一次实训可申请的总额度", example = "50000.00")
private final BigDecimal totalQuota;
- @Schema(description = "整个系统全部未逻辑删除申请累计占用额度,包含本次申请", example = "43589.85")
+ @Schema(description = "当前实训主体全部未逻辑删除申请累计占用额度,包含本次申请;其他主体的申请不计入", example = "1589.85")
private final BigDecimal usedQuota;
- @Schema(description = "本次申请计入后整个系统剩余额度,即总额度减已用额度", example = "6410.15")
+ @Schema(description = "本次申请计入后当前实训主体剩余额度,即总额度减已用额度", example = "48410.15")
private final BigDecimal remainingQuota;
@Schema(description = "当前货币生成的步骤二请求的本次申请金额", example = "1589.85")
private final BigDecimal currentAmount;
diff --git a/src/main/java/com/yau/digitalrmb/institutionidentity/infrastructure/CurrencyGenerationRequestMapper.java b/src/main/java/com/yau/digitalrmb/institutionidentity/infrastructure/CurrencyGenerationRequestMapper.java
index 852bc4b..7f73015 100644
--- a/src/main/java/com/yau/digitalrmb/institutionidentity/infrastructure/CurrencyGenerationRequestMapper.java
+++ b/src/main/java/com/yau/digitalrmb/institutionidentity/infrastructure/CurrencyGenerationRequestMapper.java
@@ -2,12 +2,17 @@ package com.yau.digitalrmb.institutionidentity.infrastructure;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
@Mapper
public interface CurrencyGenerationRequestMapper extends BaseMapper {
- @Select("SELECT COALESCE(SUM(amount), 0) FROM currency_generation_request WHERE deleted = FALSE")
- BigDecimal sumActiveAmount();
+ @Select("SELECT COALESCE(SUM(amount), 0) FROM currency_generation_request "
+ + "WHERE deleted = FALSE AND user_id = #{userId} "
+ + "AND school_id = #{schoolId} AND class_id = #{classId}")
+ BigDecimal sumActiveAmount(@Param("userId") String userId,
+ @Param("schoolId") long schoolId,
+ @Param("classId") long classId);
}
diff --git a/src/test/java/com/yau/digitalrmb/institutionidentity/CurrencyGenerationVerificationControllerTest.java b/src/test/java/com/yau/digitalrmb/institutionidentity/CurrencyGenerationVerificationControllerTest.java
index 39956c2..f77b6ef 100644
--- a/src/test/java/com/yau/digitalrmb/institutionidentity/CurrencyGenerationVerificationControllerTest.java
+++ b/src/test/java/com/yau/digitalrmb/institutionidentity/CurrencyGenerationVerificationControllerTest.java
@@ -3,6 +3,7 @@ package com.yau.digitalrmb.institutionidentity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeyService;
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.infrastructure.CurrencyGenerationRequestEntity;
import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestMapper;
@@ -51,6 +52,7 @@ class CurrencyGenerationVerificationControllerTest {
@Autowired private StuModuleScoreDetailsMapper scoreMapper;
@Autowired private InstitutionIdentityCryptography cryptography;
@Autowired private InstitutionKeyService keyService;
+ @Autowired private InstitutionTrainingResetService resetService;
private String authorization;
private String bankPublicKey;
@@ -127,8 +129,8 @@ class CurrencyGenerationVerificationControllerTest {
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
- .andExpect(jsonPath("$.data.usedQuota").value(1589.85))
- .andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
+ .andExpect(jsonPath("$.data.usedQuota").value(0.00))
+ .andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
.andExpect(jsonPath("$.data.currentAmount").value(1589.85))
.andExpect(jsonPath("$.data.quotaSufficient").value(true))
.andExpect(jsonPath("$.data.verificationId").doesNotExist())
@@ -136,8 +138,8 @@ class CurrencyGenerationVerificationControllerTest {
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
- .andExpect(jsonPath("$.data.usedQuota").value(1589.85))
- .andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
+ .andExpect(jsonPath("$.data.usedQuota").value(0.00))
+ .andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
mvc.perform(post(BASE_PATH + "/steps/calculate-digest").header("Authorization", authorization)
.contentType("application/json").content(digestStep(verificationId,
@@ -171,8 +173,8 @@ class CurrencyGenerationVerificationControllerTest {
mvc.perform(post(BASE_PATH + "/steps/verify-quota").header("Authorization", authorization))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.totalQuota").value(50000.00))
- .andExpect(jsonPath("$.data.usedQuota").value(1589.85))
- .andExpect(jsonPath("$.data.remainingQuota").value(48410.15))
+ .andExpect(jsonPath("$.data.usedQuota").value(0.00))
+ .andExpect(jsonPath("$.data.remainingQuota").value(50000.00))
.andExpect(jsonPath("$.data.quotaSufficient").value(true));
mvc.perform(post(BASE_PATH + "/steps/package-response").header("Authorization", authorization))
.andExpect(status().isOk())
@@ -199,7 +201,7 @@ class CurrencyGenerationVerificationControllerTest {
CurrencyGenerationVerificationEntity stored = verificationMapper.selectById(verificationId);
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.getAmount()).isEqualByComparingTo("1589.85");
assertThat(stored.getConfirmationMessage()).contains("CONFIRMED", "cbSignature", "confirmTime");
@@ -322,16 +324,46 @@ class CurrencyGenerationVerificationControllerTest {
}
@Test
- void globalQuotaCountsOtherSubjectsAndIgnoresDeletedRequests() {
- CurrencyGenerationRequestEntity active = quotaRequest("other-user", new BigDecimal("42000.00"), false);
- requestMapper.insert(active);
- CurrencyGenerationRequestEntity deleted = quotaRequest("deleted-user", new BigDecimal("7000.00"), true);
+ void quotaIsolatedToCurrentSubjectAndIgnoresDeletedRequests() {
+ // 其他用户/班级的活跃申请不计入当前实训主体额度
+ CurrencyGenerationRequestEntity other = quotaRequest("other-user", new BigDecimal("42000.00"), false, 9999L, 9999L);
+ requestMapper.insert(other);
+ // 当前主体但已逻辑删除的申请不计入(重新实训后额度恢复的机制)
+ CurrencyGenerationRequestEntity deleted = quotaRequest(USER_ID, new BigDecimal("7000.00"), true, SCHOOL_ID, CLASS_ID);
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();
CurrencyGenerationRequestEntity request = new CurrencyGenerationRequestEntity();
request.setIdentifierApplicationId(requestMapper.selectById(requestId).getIdentifierApplicationId());
@@ -340,7 +372,7 @@ class CurrencyGenerationVerificationControllerTest {
request.setDeliveryNodeCode("SYS_GLOBAL"); request.setRequestTimestamp("20260806210000");
request.setRequestOriginalText("quota"); request.setRequestDigest("A"); request.setBankSignature("B");
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.setDeleted(deleted);
return request;