feat(module6): add innovation training reset

chore/issuance-comments-zh
chenyuan 4 weeks ago
parent 5af0e857b8
commit 2dd9c817be

@ -0,0 +1,21 @@
package com.yau.digitalrmb.corporatewallet.application;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
@Getter
@Schema(description = "模块六创新应用场景重新实训结果")
public class CorporateInnovationTrainingResetResult {
@Schema(description = "是否重置成功")
private final boolean reset;
@Schema(description = "逻辑删除的业务记录总数")
private final int deletedRecordCount;
@Schema(description = "处理说明")
private final String message;
public CorporateInnovationTrainingResetResult(int deletedRecordCount) {
this.reset = true;
this.deletedRecordCount = deletedRecordCount;
this.message = "数字人民币创新应用场景步骤数据已逻辑删除,可从模块六第一步重新开始";
}
}

@ -0,0 +1,70 @@
package com.yau.digitalrmb.corporatewallet.application;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yau.digitalrmb.corporatewallet.infrastructure.CorporateWalletApplicationEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.CorporateWalletApplicationMapper;
import com.yau.digitalrmb.corporatewallet.infrastructure.RemoteWalletApplicationEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.RemoteWalletApplicationMapper;
import com.yau.digitalrmb.corporatewallet.infrastructure.SalaryBatchEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.SalaryBatchMapper;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsEntity;
import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsMapper;
import com.yau.digitalrmb.progress.application.UserStepProgressNewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
public class CorporateInnovationTrainingResetService {
private static final String TRAINING_ID = "innovation-scene";
@Resource private CorporateWalletApplicationMapper corporateWalletMapper;
@Resource private RemoteWalletApplicationMapper remoteWalletMapper;
@Resource private SalaryBatchMapper salaryBatchMapper;
@Resource private StuModuleScoreDetailsMapper scoreDetailsMapper;
@Resource private UserStepProgressNewService stepProgressService;
@Transactional
public CorporateInnovationTrainingResetResult reset(InstitutionKeySubject subject) {
int count = 0;
count += logicalDeleteCorporateWalletApplications(subject);
count += logicalDeleteRemoteWalletApplications(subject);
count += logicalDeleteSalaryBatches(subject);
count += logicalDeleteScore(subject.getUserId());
stepProgressService.reset(subject.getUserId(), TRAINING_ID);
return new CorporateInnovationTrainingResetResult(count);
}
private int logicalDeleteCorporateWalletApplications(InstitutionKeySubject subject) {
return corporateWalletMapper.update(null, new LambdaUpdateWrapper<CorporateWalletApplicationEntity>()
.eq(CorporateWalletApplicationEntity::getUserId, subject.getUserId())
.eq(CorporateWalletApplicationEntity::getSchoolId, subject.getSchoolId())
.eq(CorporateWalletApplicationEntity::getClassId, subject.getClassId())
.set(CorporateWalletApplicationEntity::getDeleted, true));
}
private int logicalDeleteRemoteWalletApplications(InstitutionKeySubject subject) {
return remoteWalletMapper.update(null, new LambdaUpdateWrapper<RemoteWalletApplicationEntity>()
.eq(RemoteWalletApplicationEntity::getUserId, subject.getUserId())
.eq(RemoteWalletApplicationEntity::getSchoolId, subject.getSchoolId())
.eq(RemoteWalletApplicationEntity::getClassId, subject.getClassId())
.set(RemoteWalletApplicationEntity::getDeleted, true));
}
private int logicalDeleteSalaryBatches(InstitutionKeySubject subject) {
return salaryBatchMapper.update(null, new LambdaUpdateWrapper<SalaryBatchEntity>()
.eq(SalaryBatchEntity::getUserId, subject.getUserId())
.eq(SalaryBatchEntity::getSchoolId, subject.getSchoolId())
.eq(SalaryBatchEntity::getClassId, subject.getClassId())
.set(SalaryBatchEntity::getDeleted, true));
}
private int logicalDeleteScore(String userId) {
return scoreDetailsMapper.update(null, new LambdaUpdateWrapper<StuModuleScoreDetailsEntity>()
.eq(StuModuleScoreDetailsEntity::getUserId, userId)
.eq(StuModuleScoreDetailsEntity::getMoudule, SalaryScoreService.MODULE_NAME)
.set(StuModuleScoreDetailsEntity::getDeleted, true));
}
}

@ -0,0 +1,35 @@
package com.yau.digitalrmb.corporatewallet.interfaces.rest;
import com.yau.digitalrmb.corporatewallet.application.CorporateInnovationTrainingResetResult;
import com.yau.digitalrmb.corporatewallet.application.CorporateInnovationTrainingResetService;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
import com.yau.digitalrmb.security.context.AuthContextHolder;
import com.yau.digitalrmb.shared.api.ApiResponse;
import com.yau.digitalrmb.shared.web.TraceIdFilter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.MDC;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/api/v1/corporate-wallet/training")
@Tag(name = "模块六:数字人民币创新应用场景实验管理")
public class CorporateInnovationTrainingResetController {
@Resource private CorporateInnovationTrainingResetService resetService;
@PostMapping("/reset")
@Operation(summary = "重新开始数字人民币创新应用场景实验",
description = "逻辑删除当前主体的对公钱包申请、工资批次、模块六成绩和步骤进度;保留模块六密钥,可从模块六第一步重新开始。")
public ApiResponse<CorporateInnovationTrainingResetResult> reset() {
return ApiResponse.success(resetService.reset(
InstitutionKeySubject.from(AuthContextHolder.get())), traceId());
}
private String traceId() {
return MDC.get(TraceIdFilter.MDC_KEY);
}
}

@ -0,0 +1,62 @@
package com.yau.digitalrmb.corporatewallet.application;
import com.yau.digitalrmb.corporatewallet.infrastructure.CorporateWalletApplicationMapper;
import com.yau.digitalrmb.corporatewallet.infrastructure.CorporateWalletApplicationEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.RemoteWalletApplicationEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.RemoteWalletApplicationMapper;
import com.yau.digitalrmb.corporatewallet.infrastructure.SalaryBatchEntity;
import com.yau.digitalrmb.corporatewallet.infrastructure.SalaryBatchMapper;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsMapper;
import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsEntity;
import com.yau.digitalrmb.progress.application.UserStepProgressNewService;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class CorporateInnovationTrainingResetServiceTest {
private static final InstitutionKeySubject SUBJECT =
new InstitutionKeySubject("reset-user", 1001L, 2001L);
@Mock private CorporateWalletApplicationMapper corporateWalletMapper;
@Mock private RemoteWalletApplicationMapper remoteWalletMapper;
@Mock private SalaryBatchMapper salaryBatchMapper;
@Mock private StuModuleScoreDetailsMapper scoreDetailsMapper;
@Mock private UserStepProgressNewService stepProgressService;
@InjectMocks private CorporateInnovationTrainingResetService service;
@BeforeAll
static void initializeMybatisLambdaMetadata() {
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
TableInfoHelper.initTableInfo(assistant, CorporateWalletApplicationEntity.class);
TableInfoHelper.initTableInfo(assistant, RemoteWalletApplicationEntity.class);
TableInfoHelper.initTableInfo(assistant, SalaryBatchEntity.class);
TableInfoHelper.initTableInfo(assistant, StuModuleScoreDetailsEntity.class);
}
@Test
void resetsModuleSixBusinessDataScoreAndNavigationProgress() {
when(corporateWalletMapper.update(any(), any())).thenReturn(2);
when(remoteWalletMapper.update(any(), any())).thenReturn(3);
when(salaryBatchMapper.update(any(), any())).thenReturn(4);
when(scoreDetailsMapper.update(any(), any())).thenReturn(1);
CorporateInnovationTrainingResetResult result = service.reset(SUBJECT);
assertThat(result.isReset()).isTrue();
assertThat(result.getDeletedRecordCount()).isEqualTo(10);
verify(stepProgressService).reset("reset-user", "innovation-scene");
}
}
Loading…
Cancel
Save