You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
digital-rmb-backend/src/main/java/com/yau/digitalrmb/institutionidentity/application/InstitutionTrainingResetSer...

217 lines
14 KiB
Java

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<Long> applicationIds = applicationMapper.selectList(
new LambdaQueryWrapper<InstitutionIdentifierApplicationEntity>()
.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<Long> requestIds = requestMapper.selectList(new LambdaQueryWrapper<CurrencyGenerationRequestEntity>()
.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<Long> verificationIds = verificationMapper.selectList(
new LambdaQueryWrapper<CurrencyGenerationVerificationEntity>()
.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<Long> transactionIds = transactionMapper.selectList(
new LambdaQueryWrapper<TransactionInformationIdentifierEntity>()
.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<Long> batchIds = standardCurrencyBatchMapper.selectList(
new LambdaQueryWrapper<StandardCurrencyBatchEntity>()
.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<StandardCurrencyEntity>()
.in(StandardCurrencyEntity::getBatchId, batchIds)
.set(StandardCurrencyEntity::getDeleted, true));
}
private int logicalDeleteStandardCurrencyBatches(InstitutionKeySubject s) {
return standardCurrencyBatchMapper.update(null, new LambdaUpdateWrapper<StandardCurrencyBatchEntity>()
.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<QuotaControlBitEntity>()
.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<ControlSystemSignatureEntity>()
.eq(ControlSystemSignatureEntity::getUserId, s.getUserId())
.eq(ControlSystemSignatureEntity::getSchoolId, s.getSchoolId())
.eq(ControlSystemSignatureEntity::getClassId, s.getClassId())
.set(ControlSystemSignatureEntity::getDeleted, true));
}
private int logicalDeleteTransactionLogs(List<Long> ids) {
if (ids.isEmpty()) return 0;
return transactionLogMapper.update(null, new LambdaUpdateWrapper<TransactionInformationIdentifierOperationLogEntity>()
.in(TransactionInformationIdentifierOperationLogEntity::getTransactionIdentifierId, ids)
.set(TransactionInformationIdentifierOperationLogEntity::getDeleted, true));
}
private int logicalDeleteTransactions(InstitutionKeySubject s) {
return transactionMapper.update(null, new LambdaUpdateWrapper<TransactionInformationIdentifierEntity>()
.eq(TransactionInformationIdentifierEntity::getUserId, s.getUserId())
.eq(TransactionInformationIdentifierEntity::getSchoolId, s.getSchoolId())
.eq(TransactionInformationIdentifierEntity::getClassId, s.getClassId())
.set(TransactionInformationIdentifierEntity::getDeleted, true));
}
private int logicalDeleteVerificationLogs(List<Long> ids) {
if (ids.isEmpty()) return 0;
return verificationLogMapper.update(null, new LambdaUpdateWrapper<CurrencyGenerationVerificationOperationLogEntity>()
.in(CurrencyGenerationVerificationOperationLogEntity::getVerificationId, ids)
.set(CurrencyGenerationVerificationOperationLogEntity::getDeleted, true));
}
private int logicalDeleteVerifications(InstitutionKeySubject s) {
return verificationMapper.update(null, new LambdaUpdateWrapper<CurrencyGenerationVerificationEntity>()
.eq(CurrencyGenerationVerificationEntity::getUserId, s.getUserId())
.eq(CurrencyGenerationVerificationEntity::getSchoolId, s.getSchoolId())
.eq(CurrencyGenerationVerificationEntity::getClassId, s.getClassId())
.set(CurrencyGenerationVerificationEntity::getDeleted, true));
}
private int logicalDeleteRequestLogs(List<Long> ids) {
if (ids.isEmpty()) return 0;
return requestLogMapper.update(null, new LambdaUpdateWrapper<CurrencyGenerationRequestOperationLogEntity>()
.in(CurrencyGenerationRequestOperationLogEntity::getRequestId, ids)
.set(CurrencyGenerationRequestOperationLogEntity::getDeleted, true));
}
private int logicalDeleteRequests(InstitutionKeySubject s) {
return requestMapper.update(null, new LambdaUpdateWrapper<CurrencyGenerationRequestEntity>()
.eq(CurrencyGenerationRequestEntity::getUserId, s.getUserId())
.eq(CurrencyGenerationRequestEntity::getSchoolId, s.getSchoolId())
.eq(CurrencyGenerationRequestEntity::getClassId, s.getClassId())
.set(CurrencyGenerationRequestEntity::getDeleted, true));
}
private int logicalDeleteErrors(List<Long> ids) {
if (ids.isEmpty()) return 0;
return errorMapper.update(null, new LambdaUpdateWrapper<InstitutionIdentifierTrainingErrorEntity>()
.in(InstitutionIdentifierTrainingErrorEntity::getApplicationId, ids)
.set(InstitutionIdentifierTrainingErrorEntity::getDeleted, true));
}
private int logicalDeleteApplicationLogs(List<Long> ids) {
if (ids.isEmpty()) return 0;
return applicationLogMapper.update(null, new LambdaUpdateWrapper<InstitutionIdentifierOperationLogEntity>()
.in(InstitutionIdentifierOperationLogEntity::getApplicationId, ids)
.set(InstitutionIdentifierOperationLogEntity::getDeleted, true));
}
private int logicalDeleteApplications(InstitutionKeySubject s) {
return applicationMapper.update(null, new LambdaUpdateWrapper<InstitutionIdentifierApplicationEntity>()
.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<StuModuleScoreDetailsEntity>()
.eq(StuModuleScoreDetailsEntity::getUserId, userId)
.eq(StuModuleScoreDetailsEntity::getMoudule, InstitutionTrainingScoreService.MODULE_NAME)
.set(StuModuleScoreDetailsEntity::getDeleted, true));
}
}