From ab9be4afc25627efce79a555ab3373de8037e493 Mon Sep 17 00:00:00 2001 From: chenyuan Date: Wed, 23 Sep 2026 00:37:19 +0800 Subject: [PATCH] fix: allow users to reset wallet runtime --- .../shared/wallet/WalletRuntimeResetController.java | 13 +++---------- .../shared/wallet/WalletRuntimeResetTest.java | 8 +++----- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetController.java b/src/main/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetController.java index ce10d8a..958cae7 100644 --- a/src/main/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetController.java +++ b/src/main/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetController.java @@ -1,11 +1,8 @@ package com.yau.digitalrmb.shared.wallet; -import com.yau.digitalrmb.identity.domain.UserRole; import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject; import com.yau.digitalrmb.security.context.AuthContextHolder; import com.yau.digitalrmb.security.context.JwtUser; -import com.yau.digitalrmb.shared.api.ErrorCode; -import com.yau.digitalrmb.shared.exception.BusinessException; import com.yau.digitalrmb.shared.api.ApiResponse; import com.yau.digitalrmb.shared.web.TraceIdFilter; import io.swagger.v3.oas.annotations.Operation; @@ -19,23 +16,19 @@ import javax.annotation.Resource; @RestController @RequestMapping("/api/v1/wallet-runtime") -@Tag(name = "钱包运行数据-彻底重开", description = "清空兑换/支付历史并重建模块三投影(教师/管理员专用)") +@Tag(name = "钱包运行数据重置", description = "清空当前用户兑换/支付历史并重建模块三投影") public class WalletRuntimeResetController { @Resource private WalletRuntimeResetService resetService; @PostMapping("/reset") - @Operation(summary = "彻底重开兑换与支付实验", + @Operation(summary = "重新开始兑换与支付实验", description = "删除当前用户的全部兑换/支付订单与流水(含已确权完成的),把涉及币串回退到商业银行库," + "并清空模块三投影出的共享钱包/银行账户/证书/合约/绑定与实验attempt," + - "随后立即按最新模块三结果重新投影,模块四/五可直接重新开始。仅教师和管理员可调用。") + "随后立即按最新模块三结果重新投影,模块四/五可直接重新开始。仅影响当前登录用户。") public ApiResponse reset() { JwtUser jwtUser = AuthContextHolder.get(); - Integer roleId = jwtUser.getRoleId(); - if (roleId == null || (roleId != UserRole.ADMIN.getId() && roleId != UserRole.TEACHER.getId())) { - throw new BusinessException(ErrorCode.FORBIDDEN, "仅教师或管理员可以彻底重开兑换与支付实验"); - } return ApiResponse.success(resetService.reset(InstitutionKeySubject.from(jwtUser)), traceId()); } diff --git a/src/test/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetTest.java b/src/test/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetTest.java index cc8eb95..b216b79 100644 --- a/src/test/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetTest.java +++ b/src/test/java/com/yau/digitalrmb/shared/wallet/WalletRuntimeResetTest.java @@ -105,7 +105,7 @@ class WalletRuntimeResetTest { } @Test - void teacherResetRollsBackCompletedExchangeAndReprojectsFreshModuleThree() throws Exception { + void userResetRollsBackCompletedExchangeAndReprojectsFreshModuleThree() throws Exception { String context = mockMvc.perform(get("/api/v1/exchanges/context").with(role(4))) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); String walletId = JsonPath.read(context, "$.data.walletId"); @@ -131,7 +131,7 @@ class WalletRuntimeResetTest { .andExpect(status().isOk()) .andExpect(jsonPath("$.data.bankCardNumber").value("6216610100001234567")); - mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(3))) + mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(4))) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.deletedExchangeOrderCount").value(1)) .andExpect(jsonPath("$.data.restoredCoinCount").value(2)) @@ -170,10 +170,8 @@ class WalletRuntimeResetTest { } @Test - void studentRoleCannotReset() throws Exception { + void studentCanResetOwnRuntime() throws Exception { mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(4))) - .andExpect(status().isForbidden()); - mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(1))) .andExpect(status().isOk()); }