LP: Added restore logic

This commit is contained in:
Mikhail Trofimov 2026-07-04 18:33:48 +03:00
parent d84763b754
commit 5d09e25e87
3 changed files with 66 additions and 25 deletions

View file

@ -14,4 +14,6 @@ public interface LegalsFidMapMapper {
List<SignalLegalFidMap> findFullLegalFidMap(@Param("packageId") Long packageId,
@Param("limit") int limit,
@Param("offset") int offset);
Long deleteByPackageId(@Param("packageId") Long id);
}

View file

@ -6,11 +6,10 @@ import org.springframework.stereotype.Service;
import ru.nbch.credit_tracker.config.settings.CreditTrackerSettings;
import ru.nbch.credit_tracker.entities.app.UserPackage;
import ru.nbch.credit_tracker.enums.Status;
import ru.nbch.credit_tracker.mapper.signal.LegalsFidMapMapper;
import ru.nbch.credit_tracker.mapper.signal.PackagesRecordsMapper;
import ru.nbch.credit_tracker.mapper.signal.UserPackageMapper;
import ru.nbch.credit_tracker.service.task.NpPipelinePackageFabric;
import ru.nbch.credit_tracker.service.task.NpPipelinePackageOrchestrator;
import ru.nbch.credit_tracker.service.task.SetupParam;
import ru.nbch.credit_tracker.service.task.*;
import ru.nbch.credit_tracker.service.task.impl.PipelineMode;
import ru.nbch.credit_tracker.service.task.impl.Saver;
import ru.nbch.credit_tracker.utils.CTUtil;
@ -31,21 +30,30 @@ public class StartupRestoreService {
private final UserPackageMapper userPackageMapper;
private final PackagesRecordsMapper phoneFidMapMapper;
private final LegalsFidMapMapper legalsFidMapMapper;
private final NpPipelinePackageFabric npPipelinePackageManager;
private final NpPipelinePackageOrchestrator pipelineOrchestrator;
private final NpPipelinePackageOrchestrator npPipelineOrchestrator;
private final LpPipelinePackageFabric lpPipelinePackageManager;
private final LpPipelinePackageOrchestrator lpPipelineOrchestrator;
private final CreditTrackerSettings creditTrackerSettings;
private final Saver saver;
public StartupRestoreService(UserPackageMapper userPackageMapper,
PackagesRecordsMapper phoneFidMapMapper,
LegalsFidMapMapper legalsFidMapMapper,
NpPipelinePackageFabric npPipelinePackageManager,
NpPipelinePackageOrchestrator pipelineOrchestrator,
NpPipelinePackageOrchestrator npPipelineOrchestrator,
LpPipelinePackageFabric lpPipelinePackageManager,
LpPipelinePackageOrchestrator lpPipelineOrchestrator,
CreditTrackerSettings creditTrackerSettings,
Saver saver) {
this.userPackageMapper = userPackageMapper;
this.phoneFidMapMapper = phoneFidMapMapper;
this.legalsFidMapMapper = legalsFidMapMapper;
this.npPipelinePackageManager = npPipelinePackageManager;
this.pipelineOrchestrator = pipelineOrchestrator;
this.npPipelineOrchestrator = npPipelineOrchestrator;
this.lpPipelinePackageManager = lpPipelinePackageManager;
this.lpPipelineOrchestrator = lpPipelineOrchestrator;
this.creditTrackerSettings = creditTrackerSettings;
this.saver = saver;
}
@ -53,25 +61,40 @@ public class StartupRestoreService {
public void run() {
acceptedRestore();
processingRestore();
// TODO LP
}
private void acceptedRestore() {
List<UserPackage> packages = userPackageMapper.findAllPackagesByStatus(Status.ACCEPTED.name());
log.debug("Found {} packages in status ACCEPTED", packages.size());
for (UserPackage userPackage : packages) {
if (userPackage.getSubjectType() == 1) {
try {
Long count = phoneFidMapMapper.deleteByPackageId(userPackage.getId());
log.trace("Deleted {} rows", count);
log.trace("Deleted {} np rows", count);
Path xmlReqPath = CTUtil.workingPathToReqByPackage(creditTrackerSettings.getLoadDir(), userPackage);
log.debug("Try to read and build pipeline for packageId {}; req xml path: {}", userPackage.getId(), xmlReqPath);
Pipeline pipeline = npPipelinePackageManager.build(new SetupParam(userPackage.getId(), 1, PipelineMode.DEFAULT));
pipelineOrchestrator.startOrDelay(
npPipelineOrchestrator.startOrDelay(
() -> saver.readAndSaveNpPackage(userPackage.getId(), xmlReqPath),
pipeline, userPackage.getId()
);
} catch (Exception e) {
log.error("Error build default pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
log.error("Error build default np pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
}
} else {
try {
Long count = legalsFidMapMapper.deleteByPackageId(userPackage.getId());
log.trace("Deleted {} lp rows", count);
Path xmlReqPath = CTUtil.workingPathToReqByPackage(creditTrackerSettings.getLoadDir(), userPackage);
log.debug("Try to read and build lp pipeline for packageId {}; req xml path: {}", userPackage.getId(), xmlReqPath);
Pipeline pipeline = lpPipelinePackageManager.build(new SetupParam(userPackage.getId(), 2, PipelineMode.DEFAULT));
lpPipelineOrchestrator.startOrDelay(
() -> saver.readAndSaveNpPackage(userPackage.getId(), xmlReqPath),
pipeline, userPackage.getId()
);
} catch (Exception e) {
log.error("Error build default lp pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
}
}
}
}
@ -80,12 +103,22 @@ public class StartupRestoreService {
List<UserPackage> packages = userPackageMapper.findAllPackagesByStatus(Status.PROCESSING.name(), Status.PROCESSING_REPEATED.name());
log.debug("Found {} packages in status PROCESSING", packages.size());
for (UserPackage userPackage : packages) {
if (userPackage.getSubjectType() == 1) {
try {
log.debug("Build pipeline for packageId {}", userPackage.getId());
log.debug("Build np pipeline for packageId {}", userPackage.getId());
Pipeline pipeline = npPipelinePackageManager.build(new SetupParam(userPackage.getId(), 1, PipelineMode.DEFAULT));
pipelineOrchestrator.startOrDelay(pipeline, userPackage.getId());
npPipelineOrchestrator.startOrDelay(pipeline, userPackage.getId());
} catch (Exception e) {
log.error("Error build restore pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
log.error("Error build restore np pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
}
} else {
try {
log.debug("Build lp pipeline for packageId {}", userPackage.getId());
Pipeline pipeline = lpPipelinePackageManager.build(new SetupParam(userPackage.getId(), 2, PipelineMode.DEFAULT));
lpPipelineOrchestrator.startOrDelay(pipeline, userPackage.getId());
} catch (Exception e) {
log.error("Error build restore lp pipeline for packageId {}: {}", userPackage.getId(), ExceptionUtils.getStackTrace(e));
}
}
}
}

View file

@ -49,4 +49,10 @@
LIMIT #{limit} OFFSET #{offset}
</select>
<delete id="deleteByPackageId" parameterType="long">
DELETE
FROM signals_legal_fid_map
WHERE package_id = #{packageId}
</delete>
</mapper>