стандарт
This commit is contained in:
@@ -7,19 +7,22 @@ package ru.dmitriymx.astralcheckreport;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.Organization;
|
import org.slf4j.Logger;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.Tarif;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.TarifDeserialize;
|
import ru.dmitriymx.astralcheckreport.objects.*;
|
||||||
import ru.dmitriymx.tools.browser.Browser;
|
import ru.dmitriymx.tools.browser.Browser;
|
||||||
import ru.dmitriymx.tools.browser.SimpleBrowser;
|
import ru.dmitriymx.tools.browser.SimpleBrowser;
|
||||||
|
|
||||||
class AstralSession {
|
class AstralSession {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(AstralSession.class.getSimpleName());
|
||||||
private Browser browser = new SimpleBrowser();
|
private Browser browser = new SimpleBrowser();
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
AstralSession(String login, String password) {
|
AstralSession(String login, String password) {
|
||||||
gson = new GsonBuilder()
|
gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(Tarif.class, new TarifDeserialize())
|
.registerTypeAdapter(Tarif.class, new TarifDeserialize())
|
||||||
|
.registerTypeAdapter(Cert.class, new CertDeserialize())
|
||||||
|
.registerTypeAdapter(Organization.class, new OrganizationDeserialize())
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
String postData =
|
String postData =
|
||||||
@@ -47,6 +50,11 @@ class AstralSession {
|
|||||||
|
|
||||||
JsonObject jsonObj = str2jsonObj(jsonStr);
|
JsonObject jsonObj = str2jsonObj(jsonStr);
|
||||||
jsonObj = str2jsonObj(jsonObj.get("d").getAsString());
|
jsonObj = str2jsonObj(jsonObj.get("d").getAsString());
|
||||||
|
int count = jsonObj.get("rows").getAsJsonArray().size();
|
||||||
|
if (count == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
int id = jsonObj.get("rows").getAsJsonArray().get(0).getAsJsonObject().get("id").getAsInt();
|
int id = jsonObj.get("rows").getAsJsonArray().get(0).getAsJsonObject().get("id").getAsInt();
|
||||||
|
|
||||||
postData = "{\"abonentId\":\""+ id +"\"}";
|
postData = "{\"abonentId\":\""+ id +"\"}";
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.google.gson.JsonObject;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.dmitriymx.astralcheckreport.objects.Cert;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.Organization;
|
import ru.dmitriymx.astralcheckreport.objects.Organization;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.Product;
|
import ru.dmitriymx.astralcheckreport.objects.Product;
|
||||||
import ru.dmitriymx.astralcheckreport.objects.Tarif;
|
import ru.dmitriymx.astralcheckreport.objects.Tarif;
|
||||||
@@ -21,6 +22,7 @@ public class Main implements Runnable {
|
|||||||
private Logger logger = LoggerFactory.getLogger(Main.class);
|
private Logger logger = LoggerFactory.getLogger(Main.class);
|
||||||
private ExcelReader excel;
|
private ExcelReader excel;
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
|
public static long sleepThread = 100;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Main().start();
|
new Main().start();
|
||||||
@@ -47,10 +49,12 @@ public class Main implements Runnable {
|
|||||||
|
|
||||||
ThreadGroup threadGroup = new ThreadGroup("Astral Clients");
|
ThreadGroup threadGroup = new ThreadGroup("Astral Clients");
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
int thredCount = Integer.parseInt(properties.getProperty("threads"));
|
||||||
|
sleepThread = Long.parseLong(properties.getProperty("sleep"));
|
||||||
|
for (int i = 0; i < thredCount; i++) {
|
||||||
Thread thread = new Thread(threadGroup, this, "ProcTH-"+(i+1));
|
Thread thread = new Thread(threadGroup, this, "ProcTH-"+(i+1));
|
||||||
thread.start();
|
thread.start();
|
||||||
safeSleep(200);
|
safeSleep(sleepThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (threadGroup.activeCount() > 0) {
|
while (threadGroup.activeCount() > 0) {
|
||||||
@@ -63,7 +67,7 @@ public class Main implements Runnable {
|
|||||||
return excel.getNextData();
|
return excel.getNextData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void safeSleep(long ms) {
|
public static void safeSleep(long ms) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(ms);
|
Thread.sleep(ms);
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
@@ -80,27 +84,44 @@ public class Main implements Runnable {
|
|||||||
|
|
||||||
ExcelDataRow data;
|
ExcelDataRow data;
|
||||||
while( !Thread.currentThread().isInterrupted() && ((data = nextData()) != null) ) {
|
while( !Thread.currentThread().isInterrupted() && ((data = nextData()) != null) ) {
|
||||||
if (!data.tarif.equalsIgnoreCase("Акция 3 месяца")) continue; //FIXME
|
if (!data.tarif.equalsIgnoreCase("Акция 3 месяца") &&
|
||||||
|
!data.tarif.equalsIgnoreCase("Группа компаний"))
|
||||||
|
continue; //FIXME
|
||||||
|
|
||||||
logger.info("Проверяю {} / {} ...", data.inn, data.kpp);
|
logger.info("Проверяю {} / {} ...", data.inn, data.kpp);
|
||||||
logger.debug("data = {}", data);
|
logger.debug("data = {}", data);
|
||||||
Organization organization = astral.getOrganization(data.inn, data.kpp);
|
Organization organization = astral.getOrganization(data.inn, data.kpp);
|
||||||
|
if (organization == null) {
|
||||||
|
logger.error("({}/{}): Организация не найдена!", data.inn, data.kpp);
|
||||||
|
safeSleep(sleepThread);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
logger.debug("result = {}", organization);
|
logger.debug("result = {}", organization);
|
||||||
|
|
||||||
if (data.tarif.equalsIgnoreCase("Акция 3 месяца")) {
|
if (data.tarif.equalsIgnoreCase("Акция 3 месяца")) {
|
||||||
tarif_Akcia3Mount(astral, organization, data);
|
tarif_Akcia3Mount(astral, organization, data);
|
||||||
}
|
}
|
||||||
|
else if (data.tarif.equalsIgnoreCase("Группа компаний")) {
|
||||||
|
tarif_GroupCompany(astral, organization, data);
|
||||||
|
}
|
||||||
|
|
||||||
safeSleep(200);
|
safeSleep(sleepThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Тариф: Акция 3 месяца
|
// Тариф: Акция 3 месяца
|
||||||
private void tarif_Akcia3Mount(AstralSession astral, Organization organization, ExcelDataRow data) {
|
private void tarif_Akcia3Mount(AstralSession astral, Organization organization, ExcelDataRow data) {
|
||||||
|
// Step 0: Количество доступных продуктов
|
||||||
|
if (organization.products.size() == 0) {
|
||||||
|
logger.warn("({}/{}): Нет доступных продуктов!", organization.inn, organization.kpp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Product product = organization.products.get(0);
|
Product product = organization.products.get(0);
|
||||||
Tarif tarif = product.contractTariffs.get(0);
|
Tarif tarif = product.contractTariffs.get(0);
|
||||||
|
|
||||||
if (tarif.name.equalsIgnoreCase("Промо (3 месяца бесплатно)")) {
|
if (tarif.name.equalsIgnoreCase("Промо (3 месяца бесплатно)")) {
|
||||||
// Step I - Проверяем разницу дат.
|
// Step I: Проверяем разницу дат.
|
||||||
// Разница должна быть 3 месяца
|
// Разница должна быть 3 месяца
|
||||||
int mountInit = Integer.parseInt(tarif.initialDate.substring(5, 7));
|
int mountInit = Integer.parseInt(tarif.initialDate.substring(5, 7));
|
||||||
int mountEnd = Integer.parseInt(tarif.endDate.substring(5, 7));
|
int mountEnd = Integer.parseInt(tarif.endDate.substring(5, 7));
|
||||||
@@ -109,7 +130,7 @@ public class Main implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step II - Проверка истории сертификатов
|
// Step II: Проверка истории сертификатов
|
||||||
// Сертификатов должно быть:
|
// Сертификатов должно быть:
|
||||||
// - либо один
|
// - либо один
|
||||||
// - либо соответствовать формуле "1 + доп.сертификаты"
|
// - либо соответствовать формуле "1 + доп.сертификаты"
|
||||||
@@ -120,12 +141,56 @@ public class Main implements Runnable {
|
|||||||
logger.error("({}/{}): Ошибка количества сертификатов!", organization.inn, organization.kpp);
|
logger.error("({}/{}): Ошибка количества сертификатов!", organization.inn, organization.kpp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step III: Проверяем разницу дат.
|
||||||
|
// Сертификат должен быть выдан в тот же день или позже, чем тариф
|
||||||
|
if (product.certs.size() > 1) {
|
||||||
|
logger.warn("({}/{}): Обнаружено более 1 сертификата!", organization.inn, organization.kpp);
|
||||||
|
}
|
||||||
|
Cert cert = product.certs.get(0);
|
||||||
|
|
||||||
|
long tarifDateLong = tarif.date_initialDate.getTime();
|
||||||
|
long certDateLong = cert.startCertDate.getTime();
|
||||||
|
|
||||||
|
if (certDateLong < tarifDateLong) {
|
||||||
|
logger.error("({}/{}): Ошибка: сертификат выдан раньше тарифа!", organization.inn, organization.kpp);
|
||||||
|
// return;
|
||||||
}
|
}
|
||||||
else if (tarif.name.equalsIgnoreCase("Cтандартный (годовое обслуживание)")) {
|
|
||||||
logger.warn("Логика тарифа не настроена: \"{}\"", tarif.name);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.trace("Тариф игнорируется: \"{}\"", tarif.name);
|
logger.trace("Тариф игнорируется: \"{}\"", tarif.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Тариф: Группа компаний
|
||||||
|
private void tarif_GroupCompany(AstralSession astral, Organization organization, ExcelDataRow data) {
|
||||||
|
// Step 0: Количество доступных продуктов
|
||||||
|
if (organization.products.size() == 0) {
|
||||||
|
logger.warn("({}/{}): Нет доступных продуктов!", organization.inn, organization.kpp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step I: Является ли данная компания Группой компаний
|
||||||
|
if (organization.companyGroupName == null || organization.companyGroupName.isEmpty()) {
|
||||||
|
logger.warn("({}/{}): Ошибка: не является Группой компаний", organization.inn, organization.kpp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step II: Проверяем разницу дат.
|
||||||
|
// Сертификат должен быть выдан в тот же день или позже, чем тариф
|
||||||
|
Product product = organization.products.get(0);
|
||||||
|
Tarif tarif = product.contractTariffs.get(0);
|
||||||
|
if (product.certs.size() > 1) {
|
||||||
|
logger.warn("({}/{}): Обнаружено более 1 сертификата!", organization.inn, organization.kpp);
|
||||||
|
}
|
||||||
|
Cert cert = product.certs.get(0);
|
||||||
|
|
||||||
|
long tarifDateLong = tarif.date_initialDate.getTime();
|
||||||
|
long certDateLong = cert.startCertDate.getTime();
|
||||||
|
|
||||||
|
if (certDateLong < tarifDateLong) {
|
||||||
|
logger.error("({}/{}): Ошибка: сертификат выдан раньше тарифа!", organization.inn, organization.kpp);
|
||||||
|
// return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016-05-28
|
||||||
|
*/
|
||||||
|
package ru.dmitriymx.astralcheckreport.objects;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Cert {
|
||||||
|
public Date startCertDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016-05-28
|
||||||
|
*/
|
||||||
|
package ru.dmitriymx.astralcheckreport.objects;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
public class CertDeserialize implements JsonDeserializer<Cert> {
|
||||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cert deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
|
Cert cert = new Cert();
|
||||||
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
|
String dateStr = jsonObject.get("startCertDate").getAsString().substring(0, 10);
|
||||||
|
try {
|
||||||
|
cert.startCertDate = sdf.parse(dateStr);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return cert;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,9 +7,10 @@ package ru.dmitriymx.astralcheckreport.objects;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Organization {
|
public class Organization {
|
||||||
private int id;
|
public int id;
|
||||||
public String inn, kpp;
|
public String inn, kpp;
|
||||||
public List<Product> products;
|
public List<Product> products;
|
||||||
|
public String companyGroupName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016-05-28
|
||||||
|
*/
|
||||||
|
package ru.dmitriymx.astralcheckreport.objects;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class OrganizationDeserialize implements JsonDeserializer<Organization> {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(OrganizationDeserialize.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Organization deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
|
Organization organization = new Organization();
|
||||||
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
|
organization.id = jsonObject.get("id").getAsInt();
|
||||||
|
organization.inn = jsonObject.get("inn").getAsString();
|
||||||
|
organization.kpp = jsonObject.get("kpp").getAsString();
|
||||||
|
organization.companyGroupName = jsonObject.get("companyGroupName").getAsString();
|
||||||
|
|
||||||
|
organization.products = new ArrayList<>();
|
||||||
|
JsonArray jsonArray = jsonObject.get("products").getAsJsonArray();
|
||||||
|
for (JsonElement element : jsonArray) {
|
||||||
|
jsonObject = element.getAsJsonObject();
|
||||||
|
if (!jsonObject.get("name").getAsString().equals("Астрал Отчет")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!jsonObject.get("statusName").getAsString().equals("Зарегистрировано")) {
|
||||||
|
logger.warn("({}/{}): не известный статус: \"{}\"", organization.inn, organization.kpp, jsonObject.get("statusName").getAsString());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
organization.products.add(jsonDeserializationContext.deserialize(jsonObject, Product.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return organization;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package ru.dmitriymx.astralcheckreport.objects;
|
package ru.dmitriymx.astralcheckreport.objects;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Product {
|
public class Product {
|
||||||
public int id;
|
public int id;
|
||||||
public String name;
|
public String name;
|
||||||
public List<Tarif> contractTariffs;
|
public List<Tarif> contractTariffs;
|
||||||
|
@SerializedName("people")
|
||||||
|
public List<Cert> certs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
*/
|
*/
|
||||||
package ru.dmitriymx.astralcheckreport.objects;
|
package ru.dmitriymx.astralcheckreport.objects;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class Tarif {
|
public class Tarif {
|
||||||
public String name, initialDate, endDate;
|
public String name, initialDate, endDate;
|
||||||
|
public Date date_initialDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ package ru.dmitriymx.astralcheckreport.objects;
|
|||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
public class TarifDeserialize implements JsonDeserializer<Tarif> {
|
public class TarifDeserialize implements JsonDeserializer<Tarif> {
|
||||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tarif deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public Tarif deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
Tarif tarif = new Tarif();
|
Tarif tarif = new Tarif();
|
||||||
@@ -16,6 +20,11 @@ public class TarifDeserialize implements JsonDeserializer<Tarif> {
|
|||||||
|
|
||||||
tarif.name = jsonObject.get("tariff").getAsJsonObject().get("name").getAsString();
|
tarif.name = jsonObject.get("tariff").getAsJsonObject().get("name").getAsString();
|
||||||
tarif.initialDate = jsonObject.get("initialDate").getAsString();
|
tarif.initialDate = jsonObject.get("initialDate").getAsString();
|
||||||
|
try {
|
||||||
|
tarif.date_initialDate = sdf.parse(tarif.initialDate);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
tarif.endDate = jsonObject.get("endDate").getAsString();
|
tarif.endDate = jsonObject.get("endDate").getAsString();
|
||||||
|
|
||||||
return tarif;
|
return tarif;
|
||||||
|
|||||||
Reference in New Issue
Block a user