0

fix: Правильный подсчет сертификатов

Считаются только действующие
This commit is contained in:
2016-06-04 17:15:29 +03:00
parent 01ffd93228
commit 517a5fc433

View File

@@ -26,6 +26,7 @@ public class Main implements Runnable {
private Properties properties = new Properties();
public static long sleepThread = 100;
private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
private static Date currentDate = new Date(System.currentTimeMillis());
public static void main(String[] args) {
new Main().start();
@@ -150,9 +151,9 @@ public class Main implements Runnable {
// - либо один
// - либо соответствовать формуле "1 + доп.сертификаты"
JsonObject historyCert = astral.historyCert(product.id);
int totalCert = historyCert.get("records").getAsInt();
if (totalCert > 1) {
if (totalCert != (1 + data.getAddonCert())) {
int totalActiveCerts = countActiveCert(historyCert);
if (totalActiveCerts > 1) {
if (totalActiveCerts != (1 + data.getAddonCert())) {
logger.error("({}/{}): Ошибка количества сертификатов!", organization.inn, organization.kpp);
}
}
@@ -287,11 +288,11 @@ public class Main implements Runnable {
// Step I: Проверяем
Product product = organization.products.get(0);
JsonObject historyCert = astral.historyCert(product.id);
int totalCert = historyCert.get("records").getAsInt();
if (totalCert < 1 + data.getAddonCert()) {
int totalActiveCerts = countActiveCert(historyCert);
if (totalActiveCerts < 1 + data.getAddonCert()) {
logger.warn("({}/{}): Странно... Сертификатов меньше чем надо", organization.inn, organization.kpp);
}
else if (totalCert > 1 + data.getAddonCert()) {
else if (totalActiveCerts > 1 + data.getAddonCert()) {
logger.error("({}/{}): Ошибка: сертификатов больше чем нужно!", organization.inn, organization.kpp);
return;
}
@@ -399,4 +400,25 @@ public class Main implements Runnable {
return boolFNS && boolFSS && boolRosstat && boolPFR && boolRosalco && boolRPN;
}
private int countActiveCert(JsonObject historyCert) {
JsonArray rows = historyCert.get("rows").getAsJsonArray();
int result = 0;
for (JsonElement element : rows) {
JsonObject jsonObject = element.getAsJsonObject();
Date endDate;
try {
endDate = sdf.parse(jsonObject.get("cell").getAsJsonArray().get(2).getAsString());
} catch (ParseException e) {
logger.error("Ошибка при форматировании даты");
return 0;
}
if (endDate.after(currentDate)) {
result++;
}
}
return result;
}
}