AstralSession: история сертификатов как List
This commit is contained in:
@@ -7,12 +7,17 @@ package ru.dmitriymx.astralcheckreport;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.dmitriymx.astralcheckreport.objects.*;
|
||||
import ru.dmitriymx.tools.browser.Browser;
|
||||
import ru.dmitriymx.tools.browser.SimpleBrowser;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AstralSession {
|
||||
private Logger logger = LoggerFactory.getLogger(AstralSession.class.getSimpleName());
|
||||
private Browser browser = new SimpleBrowser();
|
||||
@@ -71,12 +76,15 @@ public class AstralSession {
|
||||
return gson.fromJson(jsonObj.get("d").getAsString(), Organization.class);
|
||||
}
|
||||
|
||||
public JsonObject historyCert(int productId) {
|
||||
public List<Cert> historyCert(int productId) {
|
||||
String postData = "{\"productId\":" + productId + "}";
|
||||
String jsonStr = browser.post("http://reg.astralnalog.ru/AbonentModule.aspx/GetCertificatesHistory", postData);
|
||||
|
||||
JsonObject jsonObj = str2jsonObj(jsonStr);
|
||||
return str2jsonObj(jsonObj.get("d").getAsString());
|
||||
jsonObj = str2jsonObj(jsonObj.get("d").getAsString());
|
||||
|
||||
Type listType = new TypeToken<ArrayList<Cert>>(){}.getType();
|
||||
return gson.fromJson(jsonObj.get("rows"), listType);
|
||||
}
|
||||
|
||||
private JsonObject str2jsonObj(String jsonStr) {
|
||||
|
||||
@@ -8,4 +8,5 @@ import java.util.Date;
|
||||
|
||||
public class Cert {
|
||||
public Date startCertDate;
|
||||
public Date endCertDate;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,19 @@ public class CertDeserialize implements JsonDeserializer<Cert> {
|
||||
Cert cert = new Cert();
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
String dateStr = jsonObject.get("startCertDate").getAsString().substring(0, 10);
|
||||
String dateStr = null;
|
||||
String dateStrEnd = null;
|
||||
if (jsonObject.has("startCertDate")) {
|
||||
dateStr = jsonObject.get("startCertDate").getAsString().substring(0, 10);
|
||||
} else if (jsonObject.has("cell")) {
|
||||
dateStr = jsonObject.get("cell").getAsJsonArray().get(1).getAsString();
|
||||
dateStrEnd = jsonObject.get("cell").getAsJsonArray().get(1).getAsString();
|
||||
}
|
||||
|
||||
try {
|
||||
cert.startCertDate = sdf.parse(dateStr);
|
||||
if (dateStrEnd != null)
|
||||
cert.endCertDate = sdf.parse(dateStrEnd);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.dmitriymx.astralcheckreport.AstralSession;
|
||||
import ru.dmitriymx.astralcheckreport.ExcelDataRow;
|
||||
import ru.dmitriymx.astralcheckreport.Main;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Cert;
|
||||
import ru.dmitriymx.astralcheckreport.objects.LeftObject;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Organization;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractTarifProcessor {
|
||||
private static LeftObject astralNalogPlugin = new LeftObject(15);
|
||||
private Logger logger = LoggerFactory.getLogger(AbstractTarifProcessor.class);
|
||||
@@ -41,5 +45,16 @@ public abstract class AbstractTarifProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
protected int countActiveCert(List<Cert> historyCert) {
|
||||
int result = 0;
|
||||
for (Cert cert : historyCert) {
|
||||
if (cert.endCertDate.after(Main.currentDate)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract void process0(AstralSession astral, Organization organization, ExcelDataRow data);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import ru.dmitriymx.astralcheckreport.objects.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/** Тариф: Акция 3 месяца */
|
||||
public class Akcia3MountTarifProcessor extends AbstractTarifProcessor {
|
||||
@@ -41,7 +42,7 @@ public class Akcia3MountTarifProcessor extends AbstractTarifProcessor {
|
||||
// Сертификатов должно быть:
|
||||
// - либо один
|
||||
// - либо соответствовать формуле "1 + доп.сертификаты"
|
||||
JsonObject historyCert = astral.historyCert(product.id);
|
||||
List<Cert> historyCert = astral.historyCert(product.id);
|
||||
int totalActiveCerts = countActiveCert(historyCert);
|
||||
if (totalActiveCerts > 1) {
|
||||
if (totalActiveCerts != (1 + data.getAddonCert())) {
|
||||
@@ -68,25 +69,4 @@ public class Akcia3MountTarifProcessor extends AbstractTarifProcessor {
|
||||
logger.trace("Тариф игнорируется: \"{}\"", tarif.name);
|
||||
}
|
||||
}
|
||||
|
||||
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 = Main.sdf.parse(jsonObject.get("cell").getAsJsonArray().get(2).getAsString());
|
||||
} catch (ParseException e) {
|
||||
logger.error("Ошибка при форматировании даты");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (endDate.after(Main.currentDate)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ import org.slf4j.LoggerFactory;
|
||||
import ru.dmitriymx.astralcheckreport.AstralSession;
|
||||
import ru.dmitriymx.astralcheckreport.ExcelDataRow;
|
||||
import ru.dmitriymx.astralcheckreport.Main;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Cert;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Organization;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Product;
|
||||
import ru.dmitriymx.astralcheckreport.objects.Tarif;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/** Тариф: (пустое значение) */
|
||||
public class EmptyTarifProcessor extends AbstractTarifProcessor {
|
||||
@@ -28,7 +30,7 @@ public class EmptyTarifProcessor extends AbstractTarifProcessor {
|
||||
protected void process0(AstralSession astral, Organization organization, ExcelDataRow data) {
|
||||
// Step I: Проверяем
|
||||
Product product = organization.products.get(0);
|
||||
JsonObject historyCert = astral.historyCert(product.id);
|
||||
List<Cert> historyCert = astral.historyCert(product.id);
|
||||
int totalActiveCerts = countActiveCert(historyCert);
|
||||
if (totalActiveCerts < 1 + data.getAddonCert()) {
|
||||
logger.warn("({}/{}): Странно... Сертификатов меньше чем надо", organization.inn, organization.kpp);
|
||||
@@ -39,41 +41,10 @@ public class EmptyTarifProcessor extends AbstractTarifProcessor {
|
||||
}
|
||||
|
||||
Tarif tarif = product.contractTariffs.get(0);
|
||||
JsonArray certArr = historyCert.get("rows").getAsJsonArray();
|
||||
for (JsonElement element : certArr) {
|
||||
JsonObject jsonObject = element.getAsJsonObject();
|
||||
Date certDate;
|
||||
try {
|
||||
certDate = Main.sdf.parse(jsonObject.get("cell").getAsJsonArray().get(1).getAsString());
|
||||
} catch (ParseException e) {
|
||||
logger.error("({}/{}): Ошибка при форматировании даты", organization.inn, organization.kpp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (certDate.before(tarif.date_initialDate)) {
|
||||
for (Cert cert : historyCert) {
|
||||
if (cert.startCertDate.before(tarif.date_initialDate)) {
|
||||
logger.error("({}/{}): Ошибка: сертификат выдан раньше тарифа!", organization.inn, organization.kpp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = Main.sdf.parse(jsonObject.get("cell").getAsJsonArray().get(2).getAsString());
|
||||
} catch (ParseException e) {
|
||||
logger.error("Ошибка при форматировании даты");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (endDate.after(Main.currentDate)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user