feat:文件上传的功能开发

master
赵佳正 1 month ago
parent ae2e1f5d74
commit a6a83e5bd5

@ -145,6 +145,15 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<parameters>true</parameters> <parameters>true</parameters>
<fork>false</fork>
<maxmem>768m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>0</forkCount>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

@ -192,8 +192,8 @@ public class CorporateWalletService {
app.getWalletType(), "ACTIVATED", remoteActivated.getActivateTime(), "远程开立"); app.getWalletType(), "ACTIVATED", remoteActivated.getActivateTime(), "远程开立");
} }
// 钱包ID基于统一社会信用代码生成,确保同一企业无论通过哪个渠道开立,钱包ID都一致 // 钱包ID直接使用步骤一SM3摘要运算生成的摘要值
String walletId = "CORP_" + cryptography.sm3(app.getCreditCode()); String walletId = app.getDigestValue();
String activateTime = app.getVerifyTime() != null ? app.getVerifyTime() String activateTime = app.getVerifyTime() != null ? app.getVerifyTime()
: LocalDateTime.now().format(TIMESTAMP_FORMAT); : LocalDateTime.now().format(TIMESTAMP_FORMAT);

@ -325,8 +325,8 @@ public class RemoteWalletService {
app.getWalletType(), "ACTIVATED", corpActivated.getActivateTime(), "已验证", "临柜开立"); app.getWalletType(), "ACTIVATED", corpActivated.getActivateTime(), "已验证", "临柜开立");
} }
// 钱包ID基于统一社会信用代码生成,确保同一企业无论通过哪个渠道开立,钱包ID都一致 // 钱包ID直接使用钱包SM3摘要运算生成的摘要值
String walletId = "CORP_" + cryptography.sm3(app.getCreditCode()); String walletId = app.getWalletDigestValue();
String activateTime = app.getSignTime() != null ? app.getSignTime() String activateTime = app.getSignTime() != null ? app.getSignTime()
: LocalDateTime.now().format(TIMESTAMP_FORMAT); : LocalDateTime.now().format(TIMESTAMP_FORMAT);

@ -104,21 +104,25 @@ public class CurrencyGenerationVerificationService {
@Transactional @Transactional
public CurrencyQuotaVerificationResult verifyQuota(InstitutionKeySubject subject, String operator) { public CurrencyQuotaVerificationResult verifyQuota(InstitutionKeySubject subject, String operator) {
// 额度验证是每个用户独立的,使用当前用户的记录 // 额度按当前实训主体(用户+学校+班级)隔离,只统计该主体未逻辑删除的申请;
// 重新实训(InstitutionTrainingResetService.logicalDeleteRequests)会按同一维度逻辑删除申请,额度随之恢复
CurrencyGenerationVerification value = requireLatest(subject); CurrencyGenerationVerification value = requireLatest(subject);
// 【幂等性检查】如果已经验证过,直接返回结果,不执行任何更新操作 // 【幂等性检查】如果已经验证过,直接返回结果,不执行任何更新操作
if (value.getStatus().ordinal() >= CurrencyGenerationVerification.Status.QUOTA_VERIFIED.ordinal()) { if (value.getStatus().ordinal() >= CurrencyGenerationVerification.Status.QUOTA_VERIFIED.ordinal()) {
return new CurrencyQuotaVerificationResult(value); 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); BigDecimal remainingQuota = TOTAL_QUOTA.subtract(usedQuota).max(BigDecimal.ZERO);
CurrencyGenerationVerification.Status expected = value.getStatus(); CurrencyGenerationVerification.Status expected = value.getStatus();
invoke(() -> value.verifyQuota(TOTAL_QUOTA, usedQuota, remainingQuota)); invoke(() -> value.verifyQuota(TOTAL_QUOTA, usedQuota, remainingQuota));
repository.update(value, expected, "VERIFY_QUOTA", repository.update(value, expected, "VERIFY_QUOTA",
"验证全系统50000元实训额度,累计已用额度包含本次申请金额", operator); "验证当前主体50000元实训额度,已用额度不含本次申请金额", operator);
return new CurrencyQuotaVerificationResult(value); return new CurrencyQuotaVerificationResult(value);
} }

@ -9,11 +9,11 @@ import java.math.BigDecimal;
@ApiModel(description = "货币生成的步骤三额度验证结果") @ApiModel(description = "货币生成的步骤三额度验证结果")
@Schema(description = "货币生成的步骤三额度验证结果") @Schema(description = "货币生成的步骤三额度验证结果")
public class CurrencyQuotaVerificationResult { public class CurrencyQuotaVerificationResult {
@Schema(description = "整个系统一次实训可申请的总额度", example = "50000.00") @Schema(description = "当前实训主体(用户+学校+班级)一次实训可申请的总额度", example = "50000.00")
private final BigDecimal totalQuota; private final BigDecimal totalQuota;
@Schema(description = "整个系统全部未逻辑删除申请累计占用额度,包含本次申请", example = "43589.85") @Schema(description = "当前实训主体全部未逻辑删除申请累计占用额度,包含本次申请;其他主体的申请不计入", example = "1589.85")
private final BigDecimal usedQuota; private final BigDecimal usedQuota;
@Schema(description = "本次申请计入后整个系统剩余额度,即总额度减已用额度", example = "6410.15") @Schema(description = "本次申请计入后当前实训主体剩余额度,即总额度减已用额度", example = "48410.15")
private final BigDecimal remainingQuota; private final BigDecimal remainingQuota;
@Schema(description = "当前货币生成的步骤二请求的本次申请金额", example = "1589.85") @Schema(description = "当前货币生成的步骤二请求的本次申请金额", example = "1589.85")
private final BigDecimal currentAmount; private final BigDecimal currentAmount;

@ -2,12 +2,17 @@ package com.yau.digitalrmb.institutionidentity.infrastructure;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal; import java.math.BigDecimal;
@Mapper @Mapper
public interface CurrencyGenerationRequestMapper extends BaseMapper<CurrencyGenerationRequestEntity> { public interface CurrencyGenerationRequestMapper extends BaseMapper<CurrencyGenerationRequestEntity> {
@Select("SELECT COALESCE(SUM(amount), 0) FROM currency_generation_request WHERE deleted = FALSE") @Select("SELECT COALESCE(SUM(amount), 0) FROM currency_generation_request "
BigDecimal sumActiveAmount(); + "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);
} }

@ -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;

Loading…
Cancel
Save