import kaz
This commit is contained in:
@ -132,13 +132,10 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
@RequestParam(required=false,name="file") MultipartFile file,
|
@RequestParam(required=false,name="file") MultipartFile file,
|
||||||
@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip
|
@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip
|
||||||
) {
|
) {
|
||||||
int cnt=0;
|
JSONObject json = new JSONObject();
|
||||||
|
int count=0;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
//TODO add user verification: that he is authorized and that he is an administrator!
|
|
||||||
//if(user.id==null || user.id.equals("null") || user.id.isBlank())
|
|
||||||
// return "Please log in!";
|
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
Class.forName("org.postgresql.Driver");
|
Class.forName("org.postgresql.Driver");
|
||||||
@ -147,16 +144,43 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalDate lastDate = null;
|
||||||
|
String sql= """
|
||||||
|
select to_char(max(date), 'YYYY-MM-DD') as date from integration.days_kz
|
||||||
|
""";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||||
|
List<String> data = new ArrayList<>();
|
||||||
|
for (String s : ret) {
|
||||||
|
JSONObject obj = new JSONObject(s);
|
||||||
|
if(!obj.isNull("date")) {
|
||||||
|
lastDate = LocalDate.parse(obj.getString("date"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(lastDate==null)
|
||||||
|
lastDate = LocalDate.parse("2025-07-01");
|
||||||
|
//lastDate = LocalDate.parse("2025-07-16");
|
||||||
|
|
||||||
|
//By number of day downloading data and write result of downloading to database, try or false, after repair need repeat download
|
||||||
|
while(lastDate.isBefore(LocalDate.now().minusDays(3))) {
|
||||||
|
lastDate = lastDate.plusDays(1);
|
||||||
|
|
||||||
|
String dateBegin = lastDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
|
String dateEnd = dateBegin;
|
||||||
|
|
||||||
|
System.out.println("date = " + dateEnd);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(1024);
|
StringBuilder sb = new StringBuilder(1024);
|
||||||
try
|
try {
|
||||||
{
|
//String strURL = "http://91.185.13.233:98/get_fito?start_date="+dateBegin+"&end_date="+dateEnd;
|
||||||
String strURL="http://91.185.13.233:98/get_fito";
|
String strURL = "http://95.56.225.145:98/get_fito?start_date="+dateBegin+"&end_date="+dateEnd;
|
||||||
|
|
||||||
URL url = new URL(strURL);
|
URL url = new URL(strURL);
|
||||||
HttpURLConnection hConn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection hConn = (HttpURLConnection) url.openConnection();
|
||||||
hConn.setRequestMethod("GET");
|
hConn.setRequestMethod("GET");
|
||||||
hConn.setRequestProperty("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEyMyIsInVzZXJuYW1lIjoiQ0NBTE0iLCJyb2xlIjoidXNlciIsImlhdCI6MTcwNjc4NjQ0Nn0.bypDbAZYjbQu8hWrb6MnnAZ80AbO4ZifP3inEnpbabI");
|
hConn.setRequestProperty("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEyMyIsInVzZXJuYW1lIjoiQ0NBTE0iLCJyb2xlIjoidXNlciIsImlhdCI6MTcwNjc4NjQ0Nn0.bypDbAZYjbQu8hWrb6MnnAZ80AbO4ZifP3inEnpbabI");
|
||||||
|
|
||||||
hConn.setConnectTimeout(60000); // 60 сек
|
hConn.setConnectTimeout(60000); // 60 sec
|
||||||
|
|
||||||
hConn.connect();
|
hConn.connect();
|
||||||
int responseCode = hConn.getResponseCode();
|
int responseCode = hConn.getResponseCode();
|
||||||
@ -166,48 +190,56 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
int bytesRead;
|
int bytesRead;
|
||||||
char[] buffer = new char[BUFFER_SIZE];
|
char[] buffer = new char[BUFFER_SIZE];
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
sb.append(new String(buffer,0,bytesRead));
|
sb.append(new String(buffer, 0, bytesRead));
|
||||||
}
|
}
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
}catch (IOException e)
|
} catch (IOException e) {
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
String content=sb.toString();
|
String content = sb.toString();
|
||||||
|
|
||||||
|
//int year = 2025;
|
||||||
|
|
||||||
|
|
||||||
int year=2025;
|
if (content == null || content.isEmpty()) {
|
||||||
|
|
||||||
|
|
||||||
if(content==null || content.isEmpty()) {
|
|
||||||
System.out.println("Content is null");
|
System.out.println("Content is null");
|
||||||
}else {
|
} else {
|
||||||
System.out.println("Start");
|
System.out.println("Start");
|
||||||
|
|
||||||
String sql="delete from main.frmlocust where country_id=5 and eid=0 and extract(year from date)="+String.valueOf(year);
|
//String sql = "delete from main.frmlocust where country_id=5 and eid=0 and extract(year from date)=" + String.valueOf(year);
|
||||||
try{
|
//try {
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
// PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
int cont = stmt.executeUpdate();
|
// int cont = stmt.executeUpdate();
|
||||||
System.out.println("cnt: " + String.valueOf(cont));
|
// System.out.println("cnt: " + String.valueOf(cont));
|
||||||
} catch (SQLException e) {
|
//} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
//}
|
||||||
|
|
||||||
//System.out.println(content);
|
//System.out.println(content);
|
||||||
//Iterate over the elements of the array.
|
//Iterate over the elements of the array.
|
||||||
JSONObject jsonObject= new JSONObject(content);
|
JSONObject jsonObject = new JSONObject(content);
|
||||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||||
for (Object o : jsonArray) {
|
for (Object o : jsonArray) {
|
||||||
JSONObject jsonObj = (JSONObject) o;
|
JSONObject jsonObj = (JSONObject) o;
|
||||||
|
|
||||||
|
FrmLocustModel locust = convertKAZJSONToLocustModel(jsonObj);
|
||||||
|
|
||||||
|
//I check if there is already such a record in the database, if not, I insert it, if there is, I update it
|
||||||
|
UpdateLocust updateLocust = new UpdateLocust(jdbcTemplate);
|
||||||
|
//if(updateLocust.update(locust))
|
||||||
|
// count++;
|
||||||
|
|
||||||
|
System.out.println( "count = " + count );
|
||||||
|
|
||||||
|
/*
|
||||||
//I don't miss other dates
|
//I don't miss other dates
|
||||||
ZonedDateTime dateTime = ZonedDateTime.parse(jsonObj.getString("examination_date"), DateTimeFormatter.ISO_ZONED_DATE_TIME);
|
ZonedDateTime dateTime = ZonedDateTime.parse(jsonObj.getString("examination_date"), DateTimeFormatter.ISO_ZONED_DATE_TIME);
|
||||||
if(dateTime.getYear()!=year)
|
if (dateTime.getYear() != year)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sql="""
|
sql = """
|
||||||
insert into main.frmlocust(
|
insert into main.frmlocust(
|
||||||
eid, --1
|
eid, --1
|
||||||
lat_center, --2
|
lat_center, --2
|
||||||
@ -251,195 +283,458 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
?, --19 adults CheckBox
|
?, --19 adults CheckBox
|
||||||
? --20 swarms CheckBox
|
? --20 swarms CheckBox
|
||||||
)""";
|
)""";
|
||||||
PreparedStatement stmt=null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
model.addAttribute("PreviewTable","Error prepare 2");
|
model.addAttribute("PreviewTable", "Error prepare 2");
|
||||||
return "json";
|
return "json";
|
||||||
}
|
}
|
||||||
|
|
||||||
String description="";
|
String description = "";
|
||||||
description += "city: "+jsonObj.getString("city")+"\n";
|
description += "city: " + jsonObj.getString("city") + "\n";
|
||||||
description += "message_type: "+jsonObj.getString("message_type")+"\n";
|
description += "message_type: " + jsonObj.getString("message_type") + "\n";
|
||||||
if(jsonObj.has("development_stage") && !jsonObj.isNull("development_stage"))
|
if (jsonObj.has("development_stage") && !jsonObj.isNull("development_stage"))
|
||||||
description += "stage: "+jsonObj.getString("development_stage")+"\n";
|
description += "stage: " + jsonObj.getString("development_stage") + "\n";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stmt.setLong(1, 0);
|
stmt.setLong(1, 0);
|
||||||
stmt.setDouble(2,jsonObj.getDouble("latitude"));
|
stmt.setDouble(2, jsonObj.getDouble("latitude"));
|
||||||
stmt.setDouble(3,jsonObj.getDouble("longitude"));
|
stmt.setDouble(3, jsonObj.getDouble("longitude"));
|
||||||
stmt.setDouble(4,jsonObj.getDouble("latitude"));
|
stmt.setDouble(4, jsonObj.getDouble("latitude"));
|
||||||
stmt.setDouble(5,jsonObj.getDouble("longitude"));
|
stmt.setDouble(5, jsonObj.getDouble("longitude"));
|
||||||
stmt.setString(6,jsonObj.getString("examination_date")); //2023-03-20T06:23:20.000Z
|
stmt.setString(6, jsonObj.getString("examination_date")); //2023-03-20T06:23:20.000Z
|
||||||
if(jsonObj.has("village") && !jsonObj.isNull("village"))
|
if (jsonObj.has("village") && !jsonObj.isNull("village"))
|
||||||
stmt.setString(7,jsonObj.getString("village"));
|
stmt.setString(7, jsonObj.getString("village"));
|
||||||
else
|
else
|
||||||
stmt.setNull(7, Types.VARCHAR);
|
stmt.setNull(7, Types.VARCHAR);
|
||||||
if(jsonObj.has("farm") && !jsonObj.isNull("farm"))
|
if (jsonObj.has("farm") && !jsonObj.isNull("farm"))
|
||||||
stmt.setString(8,jsonObj.getString("farm"));
|
stmt.setString(8, jsonObj.getString("farm"));
|
||||||
else
|
else
|
||||||
stmt.setNull(8, Types.VARCHAR);
|
stmt.setNull(8, Types.VARCHAR);
|
||||||
if(jsonObj.has("district") && !jsonObj.isNull("district"))
|
if (jsonObj.has("district") && !jsonObj.isNull("district"))
|
||||||
stmt.setString(9,jsonObj.getString("district"));
|
stmt.setString(9, jsonObj.getString("district"));
|
||||||
else
|
else
|
||||||
stmt.setNull(9, Types.VARCHAR);
|
stmt.setNull(9, Types.VARCHAR);
|
||||||
|
|
||||||
stmt.setInt(10,5); //country_id
|
stmt.setInt(10, 5); //country_id
|
||||||
|
|
||||||
|
|
||||||
int region_id=-1;
|
int region_id = -1;
|
||||||
switch (jsonObj.getString("region")) {
|
switch (jsonObj.getString("region")) {
|
||||||
case "Туркестанская": //5 false -215739 1691403679 5 "Түркістан облысы (Туркестанская область)"
|
case "Туркестанская": //5 false -215739 1691403679 5 "Түркістан облысы (Туркестанская область)"
|
||||||
region_id=5;
|
region_id = 5;
|
||||||
break;
|
break;
|
||||||
case "Жамбылская": //4 false -215722 1691403679 5 "Жамбыл облысы (Жамбылская область)"
|
case "Жамбылская": //4 false -215722 1691403679 5 "Жамбыл облысы (Жамбылская область)"
|
||||||
region_id=4;
|
region_id = 4;
|
||||||
break;
|
break;
|
||||||
case "Алматинская": //3 false -215718 1691403679 5 "Алматы облысы (Алматинская область)"
|
case "Алматинская": //3 false -215718 1691403679 5 "Алматы облысы (Алматинская область)"
|
||||||
region_id=3;
|
region_id = 3;
|
||||||
break;
|
break;
|
||||||
case "Карагандинская": //2 false -215776 1691403679 5 "Қарағанды облысы (Карагандинская область)"
|
case "Карагандинская": //2 false -215776 1691403679 5 "Қарағанды облысы (Карагандинская область)"
|
||||||
region_id=2;
|
region_id = 2;
|
||||||
break;
|
break;
|
||||||
case "Жетысу": //478 false -14312169 1691403679 5 "Жетісу облысы"
|
case "Жетысу": //478 false -14312169 1691403679 5 "Жетісу облысы"
|
||||||
region_id=478;
|
region_id = 478;
|
||||||
break;
|
break;
|
||||||
case "Кызылординская": //6 false -215727 1691403679 5 "Қызылорда облысы (Кызылординская область)"
|
case "Кызылординская": //6 false -215727 1691403679 5 "Қызылорда облысы (Кызылординская область)"
|
||||||
region_id=6;
|
region_id = 6;
|
||||||
break;
|
break;
|
||||||
case "Атырауская": //13 false -214834 1691403679 5 "Атырау облысы (Атырауская область)"
|
case "Атырауская": //13 false -214834 1691403679 5 "Атырау облысы (Атырауская область)"
|
||||||
region_id=13;
|
region_id = 13;
|
||||||
break;
|
break;
|
||||||
case "Западно-Казахстанская": //12 false -215441 1691403679 5 "Батыс Қазақстан облысы (Западно-Казахстанская область)"
|
case "Западно-Казахстанская": //12 false -215441 1691403679 5 "Батыс Қазақстан облысы (Западно-Казахстанская область)"
|
||||||
region_id=12;
|
region_id = 12;
|
||||||
break;
|
break;
|
||||||
case "Акмолинская": //10 false -215743 1691403679 5 "Ақмола облысы (Акмолинская область)"
|
case "Акмолинская": //10 false -215743 1691403679 5 "Ақмола облысы (Акмолинская область)"
|
||||||
region_id=10;
|
region_id = 10;
|
||||||
break;
|
break;
|
||||||
case "Восточно-Казахстанская": //1 false -215699 1691403679 5 "Шығыс Қазақстан облысы (Восточно-Казахстанская область)"
|
case "Восточно-Казахстанская": //1 false -215699 1691403679 5 "Шығыс Қазақстан облысы (Восточно-Казахстанская область)"
|
||||||
region_id=1;
|
region_id = 1;
|
||||||
break;
|
break;
|
||||||
case "Абай": //477 false -14243026 1691473439 5 "Абай облысы"
|
case "Абай": //477 false -14243026 1691473439 5 "Абай облысы"
|
||||||
region_id=477;
|
region_id = 477;
|
||||||
break;
|
break;
|
||||||
case "Костанайская": //8 false -1288730 1691403679 5 "Қостанай облысы (Костанайская область)"
|
case "Костанайская": //8 false -1288730 1691403679 5 "Қостанай облысы (Костанайская область)"
|
||||||
region_id=8;
|
region_id = 8;
|
||||||
break;
|
break;
|
||||||
case "Павлодарская": //11 false -215772 1691403679 5 "Павлодар облысы (Павлодарская область)"
|
case "Павлодарская": //11 false -215772 1691403679 5 "Павлодар облысы (Павлодарская область)"
|
||||||
region_id=11;
|
region_id = 11;
|
||||||
break;
|
break;
|
||||||
case "Северо-Казахстанская": //9 false -215760 1691403679 5 "Солтүстік Қазақстан облысы (Северо-Казахстанская область)"
|
case "Северо-Казахстанская": //9 false -215760 1691403679 5 "Солтүстік Қазақстан облысы (Северо-Казахстанская область)"
|
||||||
region_id=9;
|
region_id = 9;
|
||||||
break;
|
break;
|
||||||
case "Актюбинская": //7 false -215683 1691403679 5 "Ақтөбе облысы (Актюбинская область)"
|
case "Актюбинская": //7 false -215683 1691403679 5 "Ақтөбе облысы (Актюбинская область)"
|
||||||
region_id=7;
|
region_id = 7;
|
||||||
break;
|
break;
|
||||||
case "Мангистауская": //14 false -215686 1691403679 5 "Маңғыстау облысы (Мангистауская область)"
|
case "Мангистауская": //14 false -215686 1691403679 5 "Маңғыстау облысы (Мангистауская область)"
|
||||||
region_id=14;
|
region_id = 14;
|
||||||
break;
|
break;
|
||||||
case "Улытау": //479 false -14312737 1691462768 5 "Ұлытау облысы"
|
case "Улытау": //479 false -14312737 1691462768 5 "Ұлытау облысы"
|
||||||
region_id=14;
|
region_id = 14;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new CustomException(200, 10000, "Not find region: " + jsonObj.getString("region"), null, true);
|
throw new CustomException(200, 10000, "Not find region: " + jsonObj.getString("region"), null, true);
|
||||||
}
|
}
|
||||||
if(region_id==-1)
|
if (region_id == -1)
|
||||||
stmt.setInt(11,region_id); //region_id
|
stmt.setInt(11, region_id); //region_id
|
||||||
else
|
else
|
||||||
stmt.setNull(11, Types.INTEGER);
|
stmt.setNull(11, Types.INTEGER);
|
||||||
|
|
||||||
//Вид саранчи
|
//Вид саранчи
|
||||||
int locust_id=-1;
|
int locust_id = -1;
|
||||||
switch (jsonObj.getString("grasshopper_type")) {
|
switch (jsonObj.getString("grasshopper_type")) {
|
||||||
case "Мароккская саранча":
|
case "Мароккская саранча":
|
||||||
locust_id=2;
|
locust_id = 2;
|
||||||
break;
|
break;
|
||||||
case "Итальянский прус":
|
case "Итальянский прус":
|
||||||
locust_id=1;
|
locust_id = 1;
|
||||||
break;
|
break;
|
||||||
case "Азиатская саранча":
|
case "Азиатская саранча":
|
||||||
locust_id=3;
|
locust_id = 3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new CustomException(200, 10000, "Not grasshopper_type: " + jsonObj.getString("grasshopper_type"), null, true);
|
throw new CustomException(200, 10000, "Not grasshopper_type: " + jsonObj.getString("grasshopper_type"), null, true);
|
||||||
}
|
}
|
||||||
stmt.setInt(12,locust_id); //locust_id
|
stmt.setInt(12, locust_id); //locust_id
|
||||||
|
|
||||||
//Обследованно
|
//Обследованно
|
||||||
if(jsonObj.has("examination_area") && !jsonObj.isNull("examination_area"))
|
if (jsonObj.has("examination_area") && !jsonObj.isNull("examination_area"))
|
||||||
stmt.setDouble(13,Double.parseDouble(jsonObj.get("examination_area").toString()));
|
stmt.setDouble(13, Double.parseDouble(jsonObj.get("examination_area").toString()));
|
||||||
else
|
else
|
||||||
stmt.setNull(13, Types.DOUBLE);
|
stmt.setNull(13, Types.DOUBLE);
|
||||||
|
|
||||||
//Площадь заселения
|
//Площадь заселения
|
||||||
if(jsonObj.has("settlement_area") && !jsonObj.isNull("settlement_area"))
|
if (jsonObj.has("settlement_area") && !jsonObj.isNull("settlement_area"))
|
||||||
stmt.setDouble(14,Double.parseDouble(jsonObj.get("settlement_area").toString()));
|
stmt.setDouble(14, Double.parseDouble(jsonObj.get("settlement_area").toString()));
|
||||||
else
|
else
|
||||||
stmt.setNull(14, Types.DOUBLE);
|
stmt.setNull(14, Types.DOUBLE);
|
||||||
|
|
||||||
//Прочее описание
|
//Прочее описание
|
||||||
stmt.setString(15,description); //description
|
stmt.setString(15, description); //description
|
||||||
|
|
||||||
boolean eggs=false; // Яйца
|
boolean eggs = false; // Яйца
|
||||||
boolean hoppers=false; // Личинки
|
boolean hoppers = false; // Личинки
|
||||||
boolean bands=false; // Кулиги
|
boolean bands = false; // Кулиги
|
||||||
boolean adults=false; // Имаго
|
boolean adults = false; // Имаго
|
||||||
boolean swarms=false; // Стаи
|
boolean swarms = false; // Стаи
|
||||||
if(jsonObj.has("development_stage") && !jsonObj.isNull("development_stage")) {
|
if (jsonObj.has("development_stage") && !jsonObj.isNull("development_stage")) {
|
||||||
if (jsonObj.getString("development_stage").equals("Яйца")) eggs = true;
|
if (jsonObj.getString("development_stage").equals("Яйца")) eggs = true;
|
||||||
if (jsonObj.getString("development_stage").equals("Личинки") || jsonObj.getString("development_stage").equals("Заселенность личинками") || jsonObj.getString("development_stage").equals("Личинка")) hoppers = true;
|
if (jsonObj.getString("development_stage").equals("Личинки") || jsonObj.getString("development_stage").equals("Заселенность личинками") || jsonObj.getString("development_stage").equals("Личинка"))
|
||||||
|
hoppers = true;
|
||||||
if (jsonObj.getString("development_stage").equals("Кулиги")) bands = true;
|
if (jsonObj.getString("development_stage").equals("Кулиги")) bands = true;
|
||||||
if (jsonObj.getString("development_stage").equals("Имаго")) adults = true;
|
if (jsonObj.getString("development_stage").equals("Имаго")) adults = true;
|
||||||
if (jsonObj.getString("development_stage").equals("Стаи")) swarms = true;
|
if (jsonObj.getString("development_stage").equals("Стаи")) swarms = true;
|
||||||
}
|
}
|
||||||
if(eggs)
|
if (eggs)
|
||||||
stmt.setBoolean(16,true);
|
stmt.setBoolean(16, true);
|
||||||
else
|
else
|
||||||
stmt.setNull(16, Types.BOOLEAN);
|
stmt.setNull(16, Types.BOOLEAN);
|
||||||
if(hoppers)
|
if (hoppers)
|
||||||
stmt.setBoolean(17,true);
|
stmt.setBoolean(17, true);
|
||||||
else
|
else
|
||||||
stmt.setNull(17, Types.BOOLEAN);
|
stmt.setNull(17, Types.BOOLEAN);
|
||||||
if(bands)
|
if (bands)
|
||||||
stmt.setBoolean(18,true);
|
stmt.setBoolean(18, true);
|
||||||
else
|
else
|
||||||
stmt.setNull(18, Types.BOOLEAN);
|
stmt.setNull(18, Types.BOOLEAN);
|
||||||
if(adults)
|
if (adults)
|
||||||
stmt.setBoolean(19,true);
|
stmt.setBoolean(19, true);
|
||||||
else
|
else
|
||||||
stmt.setNull(19, Types.BOOLEAN);
|
stmt.setNull(19, Types.BOOLEAN);
|
||||||
if(swarms)
|
if (swarms)
|
||||||
stmt.setBoolean(20,true);
|
stmt.setBoolean(20, true);
|
||||||
else
|
else
|
||||||
stmt.setNull(20, Types.BOOLEAN);
|
stmt.setNull(20, Types.BOOLEAN);
|
||||||
|
|
||||||
if(region_id!=-1) {
|
if (region_id != -1) {
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
}else {
|
} else {
|
||||||
System.out.println("region: "+jsonObj.getString("region"));
|
System.out.println("region: " + jsonObj.getString("region"));
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
model.addAttribute("PreviewTable","Error set data");
|
model.addAttribute("PreviewTable", "Error set data");
|
||||||
return "json";
|
return "json";
|
||||||
}
|
}
|
||||||
cnt++;
|
cnt++;*/
|
||||||
}
|
}
|
||||||
System.out.println("Proc count = "+String.valueOf(cnt));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (CustomException e) {
|
} catch (CustomException e) {
|
||||||
if(e.isSaveToLog()) {
|
if(e.isSaveToLog()) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
|
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
json = e.getJson();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage(), ex);
|
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage(), ex);
|
||||||
|
json = Tools.createJSONError(10000,"Internal_Server_Error", (String)null, uuid);
|
||||||
}
|
}
|
||||||
return "Proc count = "+String.valueOf(cnt);
|
return json.toString();
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public FrmLocustModel convertKAZJSONToLocustModel(JSONObject obj) throws CustomException {
|
||||||
|
|
||||||
|
FrmLocustModel result = new FrmLocustModel();
|
||||||
|
|
||||||
|
result.company_uid = "f52a99a6-db5a-4d15-b29c-5a7989d548eb"; //Company: "Kazakhstan Locust"
|
||||||
|
//result.uid = obj.getString("uuid");
|
||||||
|
//result.eid = String.valueOf(obj.getInt("id")); //Internal identifier in the Uzbek database
|
||||||
|
|
||||||
|
//result.seq = obj.getLong("seq")*1000;
|
||||||
|
result.country_id = "5"; //Kazakhstan
|
||||||
|
result.country_uid = "3c7df90e-9632-4e71-8f36-c184751216df"; //Kazakhstan
|
||||||
|
|
||||||
|
/*
|
||||||
|
sql = """
|
||||||
|
insert into main.frmlocust(
|
||||||
|
eid, --1
|
||||||
|
lat_center, --2
|
||||||
|
lon_center, --3
|
||||||
|
lat1, --4
|
||||||
|
lon1, --5
|
||||||
|
date, --6
|
||||||
|
village, --7
|
||||||
|
terrain, --8
|
||||||
|
district, --9
|
||||||
|
country_id, --10
|
||||||
|
region_id, --11
|
||||||
|
locust_type_id, --12
|
||||||
|
bio_hectare, --13
|
||||||
|
locust_populated, --14
|
||||||
|
description, --15
|
||||||
|
eggs, --16
|
||||||
|
hoppers, --17
|
||||||
|
bands, --18
|
||||||
|
adults, --19
|
||||||
|
swarms --20
|
||||||
|
)values(
|
||||||
|
?, --1 eid
|
||||||
|
?, --2 lat_center
|
||||||
|
?, --3 lon_center
|
||||||
|
?, --4 lat1
|
||||||
|
?, --5 lon1
|
||||||
|
TO_TIMESTAMP(?, 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"'), --6 date
|
||||||
|
LEFT(?, 100), --7 village
|
||||||
|
LEFT(?, 100), --8 terrain
|
||||||
|
LEFT(?, 100), --9 district
|
||||||
|
?, --10 country_id
|
||||||
|
?, --11 region_id
|
||||||
|
?, --12 locust_type_id
|
||||||
|
?, --13 bio_hectare
|
||||||
|
?, --14 locust_populated
|
||||||
|
?, --15 description
|
||||||
|
?, --16 eggs CheckBox
|
||||||
|
?, --17 hoppers CheckBox
|
||||||
|
?, --18 bands CheckBox
|
||||||
|
?, --19 adults CheckBox
|
||||||
|
? --20 swarms CheckBox
|
||||||
|
)""";
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
result.eid = "0";
|
||||||
|
result.lat_center = String.valueOf(obj.getDouble("latitude"));
|
||||||
|
result.lon_center = String.valueOf(obj.getDouble("longitude"));
|
||||||
|
result.date = obj.getString("examination_date"); //2023-03-20T06:23:20.000Z
|
||||||
|
if (obj.has("village") && !obj.isNull("village"))
|
||||||
|
result.village = obj.getString("village");
|
||||||
|
if (obj.has("farm") && !obj.isNull("farm"))
|
||||||
|
result.terrain = obj.getString("farm");
|
||||||
|
if (obj.has("district") && !obj.isNull("district"))
|
||||||
|
result.district = obj.getString("district");
|
||||||
|
|
||||||
|
if(!obj.isNull("region") && !obj.optString("region","").isBlank()) {
|
||||||
|
switch (obj.optString("region",null).trim()) {
|
||||||
|
case "Туркестанская":
|
||||||
|
result.region_id = "5";
|
||||||
|
//result.region_uid = "8f4f586f-6159-4fbf-a627-2c8d637abb5e";
|
||||||
|
break;
|
||||||
|
case "Жамбылская":
|
||||||
|
result.region_id = "4";
|
||||||
|
//result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
|
||||||
|
break;
|
||||||
|
case "Алматинская":
|
||||||
|
result.region_id = "3";
|
||||||
|
//result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
|
||||||
|
break;
|
||||||
|
case "Карагандинская":
|
||||||
|
result.region_id = "2";
|
||||||
|
//result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
|
||||||
|
break;
|
||||||
|
case "Жетысу":
|
||||||
|
result.region_id = "478";
|
||||||
|
//result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
|
||||||
|
break;
|
||||||
|
case "Кызылординская":
|
||||||
|
result.region_id = "478";
|
||||||
|
//result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println(obj.optString("region",null));
|
||||||
|
throw new CustomException(200, 10000, "Not find region by region: " + obj.optString("region",null), null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!obj.isNull("region") && !obj.optString("region","").isBlank()) {
|
||||||
|
switch (obj.optString("region",null).trim()) {
|
||||||
|
case "Туркестанская":
|
||||||
|
result.region_id = "5";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Жамбылская":
|
||||||
|
result.region_id = "4";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Алматинская":
|
||||||
|
result.region_id = "3";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Карагандинская":
|
||||||
|
result.region_id = "2";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Жетысу":
|
||||||
|
result.region_id = "478";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Кызылординская":
|
||||||
|
result.region_id = "6";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Атырауская":
|
||||||
|
result.region_id = "13";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Западно-Казахстанская":
|
||||||
|
result.region_id = "12";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Акмолинская":
|
||||||
|
result.region_id = "10";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Восточно-Казахстанская":
|
||||||
|
result.region_id = "1";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Абай":
|
||||||
|
result.region_id = "477";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Костанайская":
|
||||||
|
result.region_id = "8";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Павлодарская":
|
||||||
|
result.region_id = "11";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Северо-Казахстанская":
|
||||||
|
result.region_id = "9";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Актюбинская":
|
||||||
|
result.region_id = "7";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Мангистауская":
|
||||||
|
result.region_id = "14";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
case "Улытау":
|
||||||
|
result.region_id = "479";
|
||||||
|
//result.region_uid = "";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println(obj.optString("region",null));
|
||||||
|
throw new CustomException(200, 10000, "Not find region by region: " + obj.optString("region",null), null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Вид саранчи
|
||||||
|
if(!obj.isNull("region") && !obj.optString("region","").isBlank()) {
|
||||||
|
switch (obj.getString("grasshopper_type")) {
|
||||||
|
case "Мароккская саранча":
|
||||||
|
result.locust_type_id = "2";
|
||||||
|
//result.locust_type_uid = "";
|
||||||
|
break;
|
||||||
|
case "Итальянский прус":
|
||||||
|
result.locust_type_id = "1";
|
||||||
|
//result.locust_type_uid = "";
|
||||||
|
break;
|
||||||
|
case "Азиатская саранча":
|
||||||
|
result.locust_type_id = "3";
|
||||||
|
//result.locust_type_uid = "";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println(obj.optString("grasshopper_type",null));
|
||||||
|
throw new CustomException(200, 10000, "Not find grasshopper_type: " + obj.optString("grasshopper_type",null), null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Обследованно
|
||||||
|
if (obj.has("examination_area") && !obj.isNull("examination_area"))
|
||||||
|
stmt.setDouble(13, Double.parseDouble(obj.get("examination_area").toString()));
|
||||||
|
else
|
||||||
|
stmt.setNull(13, Types.DOUBLE);
|
||||||
|
|
||||||
|
//Площадь заселения
|
||||||
|
if (obj.has("settlement_area") && !obj.isNull("settlement_area"))
|
||||||
|
stmt.setDouble(14, Double.parseDouble(obj.get("settlement_area").toString()));
|
||||||
|
else
|
||||||
|
stmt.setNull(14, Types.DOUBLE);
|
||||||
|
|
||||||
|
boolean eggs = false; // Яйца
|
||||||
|
boolean hoppers = false; // Личинки
|
||||||
|
boolean bands = false; // Кулиги
|
||||||
|
boolean adults = false; // Имаго
|
||||||
|
boolean swarms = false; // Стаи
|
||||||
|
if (obj.has("development_stage") && !obj.isNull("development_stage")) {
|
||||||
|
if (obj.getString("development_stage").equals("Яйца")) eggs = true;
|
||||||
|
if (obj.getString("development_stage").equals("Личинки") || obj.getString("development_stage").equals("Заселенность личинками") || obj.getString("development_stage").equals("Личинка"))
|
||||||
|
hoppers = true;
|
||||||
|
if (obj.getString("development_stage").equals("Кулиги")) bands = true;
|
||||||
|
if (obj.getString("development_stage").equals("Имаго")) adults = true;
|
||||||
|
if (obj.getString("development_stage").equals("Стаи")) swarms = true;
|
||||||
|
}
|
||||||
|
if (eggs)
|
||||||
|
result.eggs = "true";
|
||||||
|
//stmt.setBoolean(16, true);
|
||||||
|
|
||||||
|
if (hoppers)
|
||||||
|
result.hoppers = "true";
|
||||||
|
//stmt.setBoolean(17, true);
|
||||||
|
|
||||||
|
if (bands)
|
||||||
|
result.bands = "true";
|
||||||
|
//stmt.setBoolean(18, true);
|
||||||
|
|
||||||
|
if (adults)
|
||||||
|
result.adults = "true";
|
||||||
|
//stmt.setBoolean(19, true);
|
||||||
|
|
||||||
|
if (swarms)
|
||||||
|
result.swarms = "true";
|
||||||
|
//stmt.setBoolean(20, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
result.description = "";
|
||||||
|
result.description += "city: " + obj.getString("city") + "\n";
|
||||||
|
result.description += "message_type: " + obj.getString("message_type") + "\n";
|
||||||
|
if (obj.has("development_stage") && !obj.isNull("development_stage"))
|
||||||
|
result.description += "stage: " + obj.getString("development_stage") + "\n";
|
||||||
|
|
||||||
|
result.update();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Пример запроса: http://127.0.0.1:8081/AcceptJSON но в теле нужно поменять строку "Year y = Year.of(2024);" а также номер дня
|
* Пример запроса: http://127.0.0.1:8081/AcceptJSON но в теле нужно поменять строку "Year y = Year.of(2024);" а также номер дня
|
||||||
@ -1516,8 +1811,7 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
UpdateLocust updateLocust = new UpdateLocust(jdbcTemplate);
|
UpdateLocust updateLocust = new UpdateLocust(jdbcTemplate);
|
||||||
if(updateLocust.update(locust))
|
if(updateLocust.update(locust))
|
||||||
count++;
|
count++;
|
||||||
if(count==66)
|
|
||||||
System.out.println( "count = " + count );
|
|
||||||
System.out.println( "count = " + count );
|
System.out.println( "count = " + count );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user