package com.yau.digitalrmb.institutionidentity.application; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.yau.digitalrmb.institutionidentity.infrastructure.ControlSystemSignatureEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.ControlSystemSignatureMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.QuotaControlBitEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.QuotaControlBitMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestOperationLogEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationRequestOperationLogMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationVerificationEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationVerificationMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationVerificationOperationLogEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.CurrencyGenerationVerificationOperationLogMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierOperationLogEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierOperationLogMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierTrainingErrorEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierTrainingErrorMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.StandardCurrencyBatchEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.StandardCurrencyBatchMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.StandardCurrencyEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.StandardCurrencyMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.StuModuleScoreDetailsMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.TransactionInformationIdentifierEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.TransactionInformationIdentifierMapper; import com.yau.digitalrmb.institutionidentity.infrastructure.TransactionInformationIdentifierOperationLogEntity; import com.yau.digitalrmb.institutionidentity.infrastructure.TransactionInformationIdentifierOperationLogMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.stream.Collectors; @Service public class InstitutionTrainingResetService { @Resource private InstitutionIdentifierApplicationMapper applicationMapper; @Resource private InstitutionIdentifierOperationLogMapper applicationLogMapper; @Resource private InstitutionIdentifierTrainingErrorMapper errorMapper; @Resource private CurrencyGenerationRequestMapper requestMapper; @Resource private CurrencyGenerationRequestOperationLogMapper requestLogMapper; @Resource private CurrencyGenerationVerificationMapper verificationMapper; @Resource private CurrencyGenerationVerificationOperationLogMapper verificationLogMapper; @Resource private TransactionInformationIdentifierMapper transactionMapper; @Resource private TransactionInformationIdentifierOperationLogMapper transactionLogMapper; @Resource private ControlSystemSignatureMapper controlSignatureMapper; @Resource private QuotaControlBitMapper quotaControlBitMapper; @Resource private StandardCurrencyBatchMapper standardCurrencyBatchMapper; @Resource private StandardCurrencyMapper standardCurrencyMapper; @Resource private StuModuleScoreDetailsMapper scoreMapper; @Transactional public InstitutionTrainingResetResult reset(InstitutionKeySubject subject) { List applicationIds = applicationMapper.selectList( new LambdaQueryWrapper() .select(InstitutionIdentifierApplicationEntity::getId) .eq(InstitutionIdentifierApplicationEntity::getUserId, subject.getUserId()) .eq(InstitutionIdentifierApplicationEntity::getSchoolId, subject.getSchoolId()) .eq(InstitutionIdentifierApplicationEntity::getClassId, subject.getClassId())) .stream().map(InstitutionIdentifierApplicationEntity::getId).collect(Collectors.toList()); List requestIds = requestMapper.selectList(new LambdaQueryWrapper() .select(CurrencyGenerationRequestEntity::getId) .eq(CurrencyGenerationRequestEntity::getUserId, subject.getUserId()) .eq(CurrencyGenerationRequestEntity::getSchoolId, subject.getSchoolId()) .eq(CurrencyGenerationRequestEntity::getClassId, subject.getClassId())) .stream().map(CurrencyGenerationRequestEntity::getId).collect(Collectors.toList()); List verificationIds = verificationMapper.selectList( new LambdaQueryWrapper() .select(CurrencyGenerationVerificationEntity::getId) .eq(CurrencyGenerationVerificationEntity::getUserId, subject.getUserId()) .eq(CurrencyGenerationVerificationEntity::getSchoolId, subject.getSchoolId()) .eq(CurrencyGenerationVerificationEntity::getClassId, subject.getClassId())) .stream().map(CurrencyGenerationVerificationEntity::getId).collect(Collectors.toList()); List transactionIds = transactionMapper.selectList( new LambdaQueryWrapper() .select(TransactionInformationIdentifierEntity::getId) .eq(TransactionInformationIdentifierEntity::getUserId, subject.getUserId()) .eq(TransactionInformationIdentifierEntity::getSchoolId, subject.getSchoolId()) .eq(TransactionInformationIdentifierEntity::getClassId, subject.getClassId())) .stream().map(TransactionInformationIdentifierEntity::getId).collect(Collectors.toList()); int count = 0; count += logicalDeleteStandardCurrencies(subject); count += logicalDeleteStandardCurrencyBatches(subject); count += logicalDeleteQuotaControlBits(subject); count += logicalDeleteControlSignatures(subject); count += logicalDeleteTransactionLogs(transactionIds); count += logicalDeleteTransactions(subject); count += logicalDeleteVerificationLogs(verificationIds); count += logicalDeleteVerifications(subject); count += logicalDeleteRequestLogs(requestIds); count += logicalDeleteRequests(subject); count += logicalDeleteErrors(applicationIds); count += logicalDeleteApplicationLogs(applicationIds); count += logicalDeleteApplications(subject); count += logicalDeleteScore(subject.getUserId()); return new InstitutionTrainingResetResult(count); } private int logicalDeleteStandardCurrencies(InstitutionKeySubject s) { List batchIds = standardCurrencyBatchMapper.selectList( new LambdaQueryWrapper() .select(StandardCurrencyBatchEntity::getId) .eq(StandardCurrencyBatchEntity::getUserId, s.getUserId()) .eq(StandardCurrencyBatchEntity::getSchoolId, s.getSchoolId()) .eq(StandardCurrencyBatchEntity::getClassId, s.getClassId())) .stream().map(StandardCurrencyBatchEntity::getId).collect(Collectors.toList()); if (batchIds.isEmpty()) return 0; return standardCurrencyMapper.update(null, new LambdaUpdateWrapper() .in(StandardCurrencyEntity::getBatchId, batchIds) .set(StandardCurrencyEntity::getDeleted, true)); } private int logicalDeleteStandardCurrencyBatches(InstitutionKeySubject s) { return standardCurrencyBatchMapper.update(null, new LambdaUpdateWrapper() .eq(StandardCurrencyBatchEntity::getUserId, s.getUserId()) .eq(StandardCurrencyBatchEntity::getSchoolId, s.getSchoolId()) .eq(StandardCurrencyBatchEntity::getClassId, s.getClassId()) .set(StandardCurrencyBatchEntity::getDeleted, true)); } private int logicalDeleteQuotaControlBits(InstitutionKeySubject s) { return quotaControlBitMapper.update(null, new LambdaUpdateWrapper() .eq(QuotaControlBitEntity::getUserId, s.getUserId()) .eq(QuotaControlBitEntity::getSchoolId, s.getSchoolId()) .eq(QuotaControlBitEntity::getClassId, s.getClassId()) .set(QuotaControlBitEntity::getDeleted, true)); } private int logicalDeleteControlSignatures(InstitutionKeySubject s) { return controlSignatureMapper.update(null, new LambdaUpdateWrapper() .eq(ControlSystemSignatureEntity::getUserId, s.getUserId()) .eq(ControlSystemSignatureEntity::getSchoolId, s.getSchoolId()) .eq(ControlSystemSignatureEntity::getClassId, s.getClassId()) .set(ControlSystemSignatureEntity::getDeleted, true)); } private int logicalDeleteTransactionLogs(List ids) { if (ids.isEmpty()) return 0; return transactionLogMapper.update(null, new LambdaUpdateWrapper() .in(TransactionInformationIdentifierOperationLogEntity::getTransactionIdentifierId, ids) .set(TransactionInformationIdentifierOperationLogEntity::getDeleted, true)); } private int logicalDeleteTransactions(InstitutionKeySubject s) { return transactionMapper.update(null, new LambdaUpdateWrapper() .eq(TransactionInformationIdentifierEntity::getUserId, s.getUserId()) .eq(TransactionInformationIdentifierEntity::getSchoolId, s.getSchoolId()) .eq(TransactionInformationIdentifierEntity::getClassId, s.getClassId()) .set(TransactionInformationIdentifierEntity::getDeleted, true)); } private int logicalDeleteVerificationLogs(List ids) { if (ids.isEmpty()) return 0; return verificationLogMapper.update(null, new LambdaUpdateWrapper() .in(CurrencyGenerationVerificationOperationLogEntity::getVerificationId, ids) .set(CurrencyGenerationVerificationOperationLogEntity::getDeleted, true)); } private int logicalDeleteVerifications(InstitutionKeySubject s) { return verificationMapper.update(null, new LambdaUpdateWrapper() .eq(CurrencyGenerationVerificationEntity::getUserId, s.getUserId()) .eq(CurrencyGenerationVerificationEntity::getSchoolId, s.getSchoolId()) .eq(CurrencyGenerationVerificationEntity::getClassId, s.getClassId()) .set(CurrencyGenerationVerificationEntity::getDeleted, true)); } private int logicalDeleteRequestLogs(List ids) { if (ids.isEmpty()) return 0; return requestLogMapper.update(null, new LambdaUpdateWrapper() .in(CurrencyGenerationRequestOperationLogEntity::getRequestId, ids) .set(CurrencyGenerationRequestOperationLogEntity::getDeleted, true)); } private int logicalDeleteRequests(InstitutionKeySubject s) { return requestMapper.update(null, new LambdaUpdateWrapper() .eq(CurrencyGenerationRequestEntity::getUserId, s.getUserId()) .eq(CurrencyGenerationRequestEntity::getSchoolId, s.getSchoolId()) .eq(CurrencyGenerationRequestEntity::getClassId, s.getClassId()) .set(CurrencyGenerationRequestEntity::getDeleted, true)); } private int logicalDeleteErrors(List ids) { if (ids.isEmpty()) return 0; return errorMapper.update(null, new LambdaUpdateWrapper() .in(InstitutionIdentifierTrainingErrorEntity::getApplicationId, ids) .set(InstitutionIdentifierTrainingErrorEntity::getDeleted, true)); } private int logicalDeleteApplicationLogs(List ids) { if (ids.isEmpty()) return 0; return applicationLogMapper.update(null, new LambdaUpdateWrapper() .in(InstitutionIdentifierOperationLogEntity::getApplicationId, ids) .set(InstitutionIdentifierOperationLogEntity::getDeleted, true)); } private int logicalDeleteApplications(InstitutionKeySubject s) { return applicationMapper.update(null, new LambdaUpdateWrapper() .eq(InstitutionIdentifierApplicationEntity::getUserId, s.getUserId()) .eq(InstitutionIdentifierApplicationEntity::getSchoolId, s.getSchoolId()) .eq(InstitutionIdentifierApplicationEntity::getClassId, s.getClassId()) .set(InstitutionIdentifierApplicationEntity::getDeleted, true)); } private int logicalDeleteScore(String userId) { return scoreMapper.update(null, new LambdaUpdateWrapper() .eq(StuModuleScoreDetailsEntity::getUserId, userId) .eq(StuModuleScoreDetailsEntity::getMoudule, InstitutionTrainingScoreService.MODULE_NAME) .set(StuModuleScoreDetailsEntity::getDeleted, true)); } }