Added zipping response
This commit is contained in:
parent
61f2420ca4
commit
a1f4b86f99
1 changed files with 49 additions and 9 deletions
|
|
@ -16,12 +16,17 @@ import ru.nbch.credit_tracker.model.IUserPackageData;
|
||||||
import ru.nbch.credit_tracker.model.SignalKafkaEvent;
|
import ru.nbch.credit_tracker.model.SignalKafkaEvent;
|
||||||
import ru.nbch.credit_tracker.model.UserPackageLegalData;
|
import ru.nbch.credit_tracker.model.UserPackageLegalData;
|
||||||
import ru.nbch.credit_tracker.model.UserPackagePhoneData;
|
import ru.nbch.credit_tracker.model.UserPackagePhoneData;
|
||||||
|
import ru.nbch.credit_tracker.utils.CTUtil;
|
||||||
|
import ru.nbch.credit_tracker.utils.CtFileUtils;
|
||||||
|
import ru.nbch.credit_tracker.utils.ZipUtils;
|
||||||
import ru.nbch.credit_tracker.utils.error.ExceptionUtils;
|
import ru.nbch.credit_tracker.utils.error.ExceptionUtils;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
@ -90,10 +95,16 @@ public class SignalKafkaEventWriterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String commonMembercode = userPackageData.getUserId().substring(0, 6);
|
||||||
|
|
||||||
Path folder = Path.of(config.getLoadDir(),
|
Path folder = Path.of(config.getLoadDir(),
|
||||||
"tmp", userPackageData.getUserId(), userPackageData.getPackageName());
|
"tmp", commonMembercode, userPackageData.getPackageName());
|
||||||
Files.createDirectories(folder);
|
Files.createDirectories(folder);
|
||||||
Path tmpFilePathWithExt = folder.resolve(userPackageData.getUserId() + "_" + userPackageData.getPackageName() + ".xml");
|
Path tmpFilePathWithExt = folder.resolve(
|
||||||
|
String.format("%s_%s.xml",
|
||||||
|
commonMembercode,
|
||||||
|
userPackageData.getPackageName())
|
||||||
|
);
|
||||||
|
|
||||||
boolean exists = tmpFilePathWithExt.toFile().exists();
|
boolean exists = tmpFilePathWithExt.toFile().exists();
|
||||||
|
|
||||||
|
|
@ -120,13 +131,10 @@ public class SignalKafkaEventWriterService {
|
||||||
private void rotate() {
|
private void rotate() {
|
||||||
List<UserPackage> userPackages = userPackageMapper.findAllPackagesByStatus(Status.ON_MONITORING.name());
|
List<UserPackage> userPackages = userPackageMapper.findAllPackagesByStatus(Status.ON_MONITORING.name());
|
||||||
for (UserPackage userPackage : userPackages) {
|
for (UserPackage userPackage : userPackages) {
|
||||||
Path tmpFilePath = Path.of(config.getLoadDir(),
|
try {
|
||||||
"tmp", userPackage.getUserId(), userPackage.getPackageName())
|
movedAndZip(userPackage);
|
||||||
.resolve(userPackage.getUserId() + "_" + userPackage.getPackageName() + ".xml");
|
} catch (IOException e) {
|
||||||
|
log.error("Error while rotating user package {}", userPackage.getPackageName(), e);
|
||||||
if (tmpFilePath.toFile().exists()) {
|
|
||||||
writeEnd(tmpFilePath);
|
|
||||||
// TODO дописать, переименовать с timestamp, зазиповать и выложить в папку
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO update signals_user_packages
|
// TODO update signals_user_packages
|
||||||
|
|
@ -148,6 +156,38 @@ public class SignalKafkaEventWriterService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void movedAndZip(UserPackage userPackage) throws IOException {
|
||||||
|
String commonMembercode = userPackage.getUserId().substring(0, 6);
|
||||||
|
Path tmpFilePath = Path.of(config.getLoadDir(),
|
||||||
|
"tmp", commonMembercode, userPackage.getPackageName())
|
||||||
|
.resolve(String.format("%s_%s.xml",
|
||||||
|
commonMembercode,
|
||||||
|
userPackage.getPackageName()));
|
||||||
|
|
||||||
|
if (tmpFilePath.toFile().exists()) {
|
||||||
|
writeEnd(tmpFilePath);
|
||||||
|
|
||||||
|
|
||||||
|
Path rootReportPath = Path.of(config.getLoadDir(), commonMembercode);
|
||||||
|
if (!Files.exists(rootReportPath)) {
|
||||||
|
Files.createDirectories(rootReportPath);
|
||||||
|
}
|
||||||
|
LocalDateTime newReportDate = LocalDateTime.now();
|
||||||
|
Path responsePath = rootReportPath.resolve(
|
||||||
|
String.format("%s_%s_%s.xml",
|
||||||
|
commonMembercode,
|
||||||
|
userPackage.getPackageName(),
|
||||||
|
newReportDate.format(CTUtil.responseReportDateTimeFormatter))
|
||||||
|
);
|
||||||
|
|
||||||
|
Files.move(tmpFilePath, responsePath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
Path zipFile = ZipUtils.zipFile(responsePath);
|
||||||
|
log.info("New report file by path: {}", zipFile);
|
||||||
|
CtFileUtils.deleteQuietly(responsePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void writeNpPart(Path filePath, SignalKafkaEvent event) {
|
private void writeNpPart(Path filePath, SignalKafkaEvent event) {
|
||||||
UserPackagePhoneData packagePhoneData = event.getUserPackagePhoneData();
|
UserPackagePhoneData packagePhoneData = event.getUserPackagePhoneData();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue