@ -1398,7 +1398,7 @@ public class AcceptJSON implements ServletContextAware {
return " json " ;
}
//---------------------------------------------------------------------------
//https://127.0.0.1:8081 /AcceptJSON_UZB
//https://127.0.0.1:8083 /AcceptJSON_UZB
@ResponseBody
@RequestMapping ( value = { " /AcceptJSON_UZB " , " /api/locust/v01/AcceptJSON_UZB " } , method = { RequestMethod . GET , RequestMethod . POST } , produces = MediaType . APPLICATION_JSON_VALUE )
public String acceptUZB ( @ModelAttribute User user ) {
@ -1425,9 +1425,11 @@ public class AcceptJSON implements ServletContextAware {
}
}
if ( lastDate = = null )
lastDate = LocalDate . parse ( " 2025-02-11 " ) ;
lastDate = LocalDate . parse ( " 2025-03-03 " ) ;
//lastDate = LocalDate.parse("2025-02-11");
//lastDate = LocalDate.parse("2024-10-01");
//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 ) ;
@ -1455,874 +1457,33 @@ public class AcceptJSON implements ServletContextAware {
throw new CustomException ( 200 , 10000 , " Error download data from: " + strURL , null , true ) ;
}
int count = 0 ;
if ( content ! = null & & ! content . isEmpty ( ) ) {
JSONArray jsonArray = new JSONArray ( content ) ;
for ( Object o : jsonArray ) {
JSONObject jsonObj = ( JSONObject ) o ;
FrmLocustModel locust = convertUZBJSONToLocustModel ( jsonObj ) ;
//Проверяю есть ли уже такая запись в базе данных
//
// locust.date = jsonObj.getString("date");
// String regionName="";
// if (!jsonObj.isNull("region_name"))
// regionName = jsonObj.getString("region_name");
//
// if (!jsonObj.isNull("town_name"))
// locust.district = jsonObj.getString("town_name");
//
// if (!jsonObj.isNull("point")) {
// locust.lon = jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(0);
// locust.lat = jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(1);
// }
//
// //Контур зоны распространения В О Polygon (geoJSON)
// locust.drawPolygon = null;
// if (!jsonObj.isNull("drawPolygon")) {
// locust.drawPolygon = jsonObj.getJSONObject("drawPolygon").toString();
// }
//
// //Площадь контура зоны распространения, в случае если специалист указал е г о
// locust.size = "null";
// if (!jsonObj.isNull("polygonArea"))
// locust.size = String.valueOf(jsonObj.getDouble("polygonArea"));
//
// //jsonObj.drawPolygon Краснодар
//
// if (locust.region.length() > 0) {
// //Выбираю ID области
// locust.region_id = "";
// //Statement stt = null;
// //ResultSet rs = null;
// try {
//
// stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
// String sql_query = "select id from main.countriesregions where name like '%" + locust.region + "%';";
// rs = stt.executeQuery(sql_query);
// if (rs != null) {
// try {
// if (rs.next()) {
// locust.region_id = rs.getString(1);
// }
// rs.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// }
// } catch (SQLException ex) {
// ex.printStackTrace();
// } finally {
// if (rs != null) try {
// rs.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// if (stt != null) try {
// stt.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// }
//
//
// /*if(locust.region_id.isEmpty()){
// if(locust.region.indexOf("В о р о не жс <D0B6> <D181> а я область")>=0) locust.region_id="110";
// if(locust.region.indexOf("К р а <D180> <D0B0> но да р с кий край")>=0) locust.region_id="164";
// if(locust.region.indexOf("А с тр а х а <D185> <D0B0> с ка я область")>=0) locust.region_id="68"; //dayOfYear: 97 at year: 2022 = 07.04.2022
// if(locust.region.indexOf("Астраханская о б ла с т<D181> <D182> ")>=0) locust.region_id="68"; // dayOfYear: 101 at year: 2022 = 11.04.2022
// }*/
//
// if (locust.region_id.length() > 0) {
// //Выбираю id региона (main.countriesdistricts)
// locust.district_id = "";
// stt = null;
// rs = null;
// try {
//
// if (locust.district.equals("Алапаевский район"))
// locust.district = "городской округ Алапаевское";
// if (locust.district.equals("Сухоложский район"))
// locust.district = "городской округ Сухой Лог";
// if (locust.district.equals("Талицкий район"))
// locust.district = "Талицкий городской округ";
// if (locust.district.equals("Артинский район"))
// locust.district = "Талицкий городской округ";
// if (locust.district.equals("Богдановичский район"))
// locust.district = "городской округ Богданович";
// if (locust.district.equals("Красноуфимский район"))
// locust.district = "Красноуфимский округ";
// if (locust.district.equals("Белоярский район")) locust.region_id = "210";
// if (locust.district.equals("Пышминский район"))
// locust.district = "Пышминский городской округ";
// if (locust.district.equals("Ирбитский район"))
// locust.district = "городской округ Ирбитское";
// if (locust.district.equals("Фрязино г .о .")) locust.district = "городской округ Фрязино";
// if (locust.district.equals("Коломенский г .о .")) locust.district = "Коломенский район";
// if (locust.district.equals("Протвино г .о ."))
// locust.district = "городской округ Протвино";
// if (locust.district.equals("Зарайск г .о .")) locust.district = "Зарайский район";
// if (locust.district.equals("Анапский район")) locust.district = "городской округ Анапа";
// if (locust.district.equals("Луховицы г .о .")) locust.district = "Луховицкий район";
// if (locust.district.equals("Дергачевский район"))
// locust.district = "Дергачёвский район";
// if (locust.district.equals("Чистоозерный район"))
// locust.district = "Чистоозёрный район";
// if (locust.district.equals("Сунжа город")) locust.district = "Сунженский район";
// if (locust.district.equals("Буденновский район"))
// locust.district = "Будённовский район";
// if (locust.district.equals("Новоселовский район")) {
// locust.district = "Новоселицкий район";
// locust.region_id = "168";
// }
// if (locust.district.equals("Тимашевский район")) locust.district = "Тимашёвский район";
// if (locust.district.equals("Славгородский район"))
// locust.district = "городской округ Славгород";
// if (locust.district.equals("Режевский район"))
// locust.district = "Режевской городской округ";
// if (locust.district.equals("Веселовский район")) locust.district = "Весёловский район";
// if (locust.district.equals("Карабулак город"))
// locust.district = "городской округ Карабулак";
// if (locust.district.equals("Пугачевский район")) locust.district = "Пугачёвский район";
// if (locust.district.equals("Кущевский район")) locust.district = "Кущёвский район";
// if (locust.district.equals("Репьевский район")) locust.district = "Репьёвский район";
// if (locust.district.equals("Калачевский район")) locust.district = "Калачёвский район";
// if (locust.district.equals("Гайский район"))
// locust.district = "Гайский городской округ";
// if (locust.district.equals("Новохоперский район"))
// locust.district = "Новохопёрский район";
// if (locust.district.equals("Федоровский район")) locust.district = "Фёдоровский район";
// if (locust.district.equals("Серебряные Пруды г .о ."))
// locust.district = "городской округ Серебряные Пруды";
// if (locust.district.equals("Минераловодский район"))
// locust.district = "Минераловодский городской округ";
// if (locust.district.equals("Рузский г .о .")) locust.district = "Рузский район";
// if (locust.district.equals("Воробьевский район"))
// locust.district = "Воробьёвский район";
// if (locust.district.equals("Ачитский район"))
// locust.district = "Ачитский городской округ";
// if (locust.district.equals("Грачевский район")) locust.district = "Грачёвский район";
// if (locust.district.equals("Уссурийский район"))
// locust.district = "Уссурийский городской округ";
// if (locust.district.equals("Сорочинский район"))
// locust.district = "Сорочинский городской округ";
// if (locust.district.equals("Ясненский район"))
// locust.district = "Ясненский городской округ";
//
// stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
// String sql_query = "select id from main.countriesdistricts where region_id=" + locust.region_id + " and name like '%" + locust.district + "%';";
// rs = stt.executeQuery(sql_query);
// if (rs != null) {
// try {
// if (rs.next()) {
// locust.district_id = rs.getString(1);
// }
// rs.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// }
// } catch (SQLException ex) {
// ex.printStackTrace();
// } finally {
// if (rs != null) try {
// rs.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// if (stt != null) try {
// stt.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// }
// }
// }
//
// String row = "";
//
// if (!jsonObj.isNull("subjectList")) {
// JSONArray jsonArraySub = jsonObj.getJSONArray("subjectList");
//
// for (Object o2 : jsonArraySub) {
// JSONObject jsonObjSub = (JSONObject) o2;
//
// locust.eid = jsonObjSub.getInt("id");
// locust.phytoType = jsonObjSub.getString("phytoType"); //"Вредители" или "Обработка"
// if (locust.phytoType.equals("Обработка")) {
// /*
// locust.insecticide_name = jsonObjSub.getString("nameSubject"); //Наименование действующего вещества
// if (!jsonObjSub.isNull("nameLatSubject"))
// locust.insecticide_active_substance = jsonObjSub.getString("nameLatSubject"); //Латинское наименование действующего вещества
// if (!jsonObjSub.isNull("protectionDoze"))
// locust.insecticide_dose = String.valueOf(jsonObjSub.getFloat("protectionDoze")); //Доза внесения препарата (л/г а )
//
// if (!jsonObjSub.isNull("agroTreatmentType")) {
// String agroTreatmentType = jsonObjSub.getString("agroTreatmentType"); //Тип обработки (Агротехнический, Авиационный, Наземный)
// if (agroTreatmentType != null && !agroTreatmentType.isEmpty()) {
// if (agroTreatmentType.equals("GROUND")) {
// locust.spray_platform = "3";
// } else if (agroTreatmentType.equals("AGROTECHNICAL")) {
// locust.spray_platform = "5";
// } else if (agroTreatmentType.equals("AVIATION")) {
// locust.spray_platform = "1";
// }
// }
// if (locust.spray_platform == null || locust.spray_platform.isEmpty()) {
// //model.addAttribute("PreviewTable", "Error spray_platform");
// return "json";
// }
// }
//
// //Т о что не знаю куда записывать записываю в description
// locust.description = "";
// if (!jsonObjSub.isNull("agroTreatmentPercentage"))
// locust.description += "Процент обработанной площади: " + String.valueOf(jsonObjSub.getFloat("agroTreatmentPercentage")) + "\n";
// if (!jsonObjSub.isNull("agroTreatmentPow"))
// locust.description += "Степень обработки: " + jsonObjSub.getString("agroTreatmentPow") + "\n";
//
// //Если записи не существует то вставляем если существует то обновляем
// boolean exists = false; //Is there a record.
// Statement st;
// try {
// st = conn.createStatement();
// //ResultSet rs=null;
// try {
// String sql = "select 1 from main.frmlocustdel where eid=" + String.valueOf(locust.eid);
// rs = st.executeQuery(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error select");
// return "json";
// }
// if (rs != null) {
// if (rs.next())
// exists = true;
// }
// st.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error select 2");
// return "json";
// }
//
// PreparedStatement stmt = null;
// String sql = "";
// if (exists) {
// System.out.println(String.valueOf(cntV)+") update main.frmlocustdel");
// sql = "update main.frmlocustdel set\n"
// + " eid=?,\n"
// + " lat_center=?,\n"
// + " lon_center=?,\n"
// + " country_id=?,\n"
// + " region_id=?,\n"
// + " area=?,\n"
// + " district=?,\n"
// + " date=TO_TIMESTAMP(?, 'DD.MM.YYYY HH24:MI'),\n"
// + " description=?,\n"
// + " geom=ST_SetSRID(ST_GeomFromGeoJSON(?),4326),\n"
//
// + " insecticide_name=?,\n"
// + " insecticide_active_substance=?,\n"
// + " insecticide_dose=?,\n"
// + " spray_platform=?\n"
// + " where eid='" + locust.eid + "'";
// try {
// stmt = conn.prepareStatement(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error prepare 1");
// return "json";
// }
// } else {
// System.out.println(String.valueOf(cntV)+") insert into main.frmlocustdel");
// sql = "insert into main.frmlocustdel(\n"
// + " eid,\n" //1
// + " lat_center,\n" //2
// + " lon_center,\n" //3
// + " country_id,\n" //4
// + " region_id,\n" //5
// + " area,\n" //6
// + " district,\n" //7
// + " date,\n" //8
// + " description,\n" //9
// + " geom,\n" //10
//
// + " insecticide_name,\n" //11
// + " insecticide_active_substance,\n" //12
// + " insecticide_dose,\n" //13
// + " spray_platform\n" //14
//
// + ")values(\n"
// + " ?,\n" //1 eid
// + " ?,\n" //2 lat1
// + " ?,\n" //3 lon1
// + " ?,\n" //4 country_id
// + " ?,\n" //5 region_id
// + " ?,\n" //6 district (area)
// + " ?,\n" //7 district (area)
// + " TO_TIMESTAMP(?, 'DD.MM.YYYY HH24:MI'),\n" //8 date
// + " ?,\n" //9 description
// + " ST_SetSRID(ST_GeomFromGeoJSON(?),4326),\n" //10 geom
//
// + " ?,\n" //11 insecticide_name
// + " ?,\n" //12 insecticide_active_substance
// + " ?,\n" //13 insecticide_dose
// + " ?\n" //14 spray_platform
// + ")";
// try {
// stmt = conn.prepareStatement(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error prepare 2");
// return "json";
// }
// }
//
// try {
// stmt.setInt(1, locust.eid);
// stmt.setDouble(2, locust.lat);
// stmt.setDouble(3, locust.lon);
// stmt.setInt(4, 7); //country_id
// stmt.setInt(5, Integer.parseInt(locust.region_id)); //region_id
// stmt.setString(6, locust.district); //Пишу в поле "area"
// stmt.setString(7, null);
// stmt.setString(8, locust.date); //27.04.2020 09:17
// stmt.setString(9, locust.description);
// stmt.setString(10, locust.drawPolygon);
//
// stmt.setString(11, locust.insecticide_name);
// stmt.setString(12, locust.insecticide_active_substance);
// if (locust.insecticide_dose == null || locust.insecticide_dose.isEmpty())
// stmt.setNull(13, Types.DOUBLE);
// else
// stmt.setDouble(13, Double.parseDouble(locust.insecticide_dose));
//
// if (locust.spray_platform == null || locust.spray_platform.isEmpty())
// stmt.setNull(14, Types.INTEGER);
// else
// stmt.setInt(14, Integer.parseInt(locust.spray_platform));
//
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error set data");
// return "json";
// }
//
// //Выпоняю запрос на свтавку либо обновление
// try {
// stmt.execute();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error execute frmlocustdel");
// return "json";
// }
// cntO++;
// */
// } else if (locust.phytoType.equals("Вредители")) {
// if (!jsonObjSub.isNull("nameSubject"))
// locust.locust = jsonObjSub.getString("nameSubject");
//
// //Вид саранчи
// locust.locust_type_id = "";
// if (locust.locust.equals("Короткокрылый зеленчук")) locust.locust_type_id = "4";
// if (locust.locust.equals("Среднерусская перелётная саранча")) locust.locust_type_id = "4";
// if (locust.locust.equals("Сибирская кобылка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка изменчивая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка пёстрая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка крестовая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка сибирская")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка голубокрылая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка бескрылая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка чернополосая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка трескучая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка египетская")) locust.locust_type_id = "4";
// if (locust.locust.equals("Трещотка ширококрылая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Бахчевая кобылка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Малая крестовичка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Конёк белополосый (белополосая кобылка)"))
// locust.locust_type_id = "4";
// if (locust.locust.equals("Конек обыкновенный")) locust.locust_type_id = "4";
// if (locust.locust.equals("Конек обыкновенный")) locust.locust_type_id = "4";
// if (locust.locust.equals("Кобылка темнокрылая")) locust.locust_type_id = "4";
// if (locust.locust.equals("Краснокрылая кобылка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Краснокрылая кобылка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Степная кобылка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Гребневка")) locust.locust_type_id = "4";
// if (locust.locust.equals("Азиатская перелётная саранча")) locust.locust_type_id = "3";
// if (locust.locust.equals("Итальянский прус")) locust.locust_type_id = "1";
// if (locust.locust.equals("Мароккская саранча, мароккская кобылка, марокканка"))
// locust.locust_type_id = "2";
//
// //фаза саранчи
// if (!jsonObjSub.isNull("phaseEvolutionName"))
// locust.phase = jsonObjSub.getString("phaseEvolutionName");
//
// locust.locust_have = "3";
// if (locust.phase != null) {
// if (locust.phase.equals("Кубышка")) locust.locust_have = "2"; //Кубышка = Яйца
// if (locust.phase.equals("Гусеница")) locust.locust_have = "3";
// if (locust.phase.equals("Личинка 2-г о возраста")) locust.locust_have = "3";
// if (locust.phase.equals("Личинка 3-г о возраста")) locust.locust_have = "3";
// if (locust.phase.equals("Личинка 4-г о возраста")) locust.locust_have = "3";
// if (locust.phase.equals("Личинка 5-г о возраста")) locust.locust_have = "3";
// if (locust.phase.equals("Имаго")) locust.locust_have = "5";
// }
// //Если эта анкета "Имаго" то записываем плотность имаго на m2
// if (locust.locust_have.equals("5")) {
// if (!jsonObjSub.isNull("subPestCount"))
// locust.imago_density = String.valueOf(jsonObjSub.getFloat("subPestCount"));
// }
// //Если эта анкета "Кубышка"="Яйца" то записываем плотность кулиг на m2
// if (locust.locust_have.equals("2")) {
// if (!jsonObjSub.isNull("subPestCount"))
// locust.eggs_capsules_density = String.valueOf(jsonObjSub.getFloat("subPestCount"));
// }
// //Если эта анкета "Кулиги" то записываем плотность кулиг на m2
// if (locust.locust_have.equals("4")) {
// if (!jsonObjSub.isNull("subPestCount"))
// locust.kuliguli_density = String.valueOf(jsonObjSub.getFloat("subPestCount"));
// }
// //Если эта анкета "Личинок" то записываем плотность личинок на m2
// if (locust.locust_have.equals("3")) {
// if (!jsonObjSub.isNull("subPestCount"))
// locust.larva_density = String.valueOf(jsonObjSub.getFloat("subPestCount"));
// }
//
// //Биотоп
// switch (jsonObjSub.getString("faoBiotopeName")) {
// case "CIT степь":
// locust.bio_biotope_id = "1";
// break;
// case "CIT залежь":
// locust.bio_biotope_id = "2";
// break;
// case "CIT посевы":
// locust.bio_biotope_id = "3";
// break;
// case "CIT пастбища":
// locust.bio_biotope_id = "11";
// break;
// case "CIT холмы, горы":
// locust.bio_biotope_id = "19";
// break;
// case "DMA равнины":
// locust.bio_biotope_id = "4";
// break;
// case "DMA посевы":
// locust.bio_biotope_id = "6";
// break;
// case "DMA пастбища":
// locust.bio_biotope_id = "13";
// break;
// case "DMA холмы, горы":
// locust.bio_biotope_id = "14";
// break;
// case "LMI низкие сухие тростники":
// locust.bio_biotope_id = "7";
// break;
// case "LMI высокие влажные тростники":
// locust.bio_biotope_id = "8";
// break;
// case "LMI другое":
// locust.bio_biotope_id = "10";
// break;
// case "Другие саранчовые на посевах":
// locust.bio_biotope_id = "15";
// break;
// case "Другие саранчовые на равнине":
// locust.bio_biotope_id = "16";
// break;
// case "Другие саранчовые на холмах":
// locust.bio_biotope_id = "17";
// break;
// case "Другое":
// locust.bio_biotope_id = "18";
// break;
// default:
// locust.bio_biotope_id = null;
// break;
// }
//
// //Если те виды что нам нужны
// if (locust.region == null || locust.region.isEmpty() || locust.lat == 0 || locust.lon == 0 || locust.locust.equals("Совка ипсилон") || locust.locust.equals("Восточный майский хрущ") || locust.locust.equals("Кукурузный стеблевой мотылек") || locust.locust.equals("Картофельная, или болотная совка, лиловатая яровая совка") || locust.locust.equals("Луговой мотылёк") || locust.locust.equals("Хлопковая совка") || locust.locust.equals("Стеблевой кукурузный мотылек") || locust.locust.equals("Восточная луговая совка") || locust.locust.equals("Коричневая щитовка") || locust.locust.equals("Продолговатая (чайная) подушечница") || locust.locust.equals("Яблоневая запятовидная щитовка") || locust.locust.equals("Виноградная филлоксера") || locust.locust.equals("Бахчевая коровка")) {
//
// } else {
//
// if (locust.locust_type_id.isEmpty()) {
// System.out.println("locust.locust = "+locust.locust);
// //model.addAttribute("PreviewTable", "locust.locust_type_id == 0 locust name = " + locust.locust);
// logger.error("Error, not find locust.locust = "+locust.locust);
// return "json";
// }
// if (locust.region_id.isEmpty()) {
// System.out.println("locust.region = "+locust.region);
// //model.addAttribute("PreviewTable", "locust.region_id == 0 region name = " + locust.region);
// logger.error("Error, not find locust.region = "+locust.region);
// return "json";
// }
//
// //Т е х полей что нет в анкете вствляю в комментарии
// try {
// locust.description = "";
//
// if (jsonObjSub.getBoolean("notFound"))
// locust.description += "Вредитель не обнаружен: " + jsonObjSub.getString("nameSubject") + "\n";
// else
// locust.description += "Вредитель обнаружен: " + jsonObjSub.getString("nameSubject") + "\n";
//
// if (!jsonObjSub.isNull("phaseEvolutionName"))
// locust.description += "Фаза: " + jsonObjSub.getString("phaseEvolutionName") + "\n"; //Так как фаза у росиян более подробная
// if (!jsonObjSub.isNull("subPestCount")) {
// locust.description += "Вредителей: " + jsonObjSub.getFloat("subPestCount");
// if (!jsonObjSub.isNull("unitName"))
// locust.description += " " + jsonObjSub.getString("unitName");
// locust.description += "\n";
// }
//
// if (!jsonObj.isNull("cropCurrentType"))
// locust.description += "Тип сева: " + jsonObj.getString("cropCurrentType") + "\n";
// if (!jsonObj.isNull("cropCurrentCulture"))
// locust.description += "Наименование культуры: " + jsonObj.getString("cropCurrentCulture") + "\n";
// if (!jsonObj.isNull("cropCurrentCultureSort"))
// locust.description += "Наименование сорта культуры: " + jsonObj.getString("cropCurrentCultureSort") + "\n";
// if (!jsonObj.isNull("cropCurrentGrowthPhase"))
// locust.description += "Фаза роста культуры: " + jsonObj.getString("cropCurrentGrowthPhase") + "\n";
// if (!jsonObj.isNull("cropFieldArea")) {
// locust.description += "Площадь поля: " + jsonObj.getFloat("cropFieldArea") + "\n";
// locust.bio_hectare = String.valueOf(jsonObj.getFloat("cropFieldArea"));
// }
//
//
// } catch (Exception ex) {
// ex.printStackTrace();
// }
//
// locust.terrain = "null"; //У росиян нет сельского округа
//
// row = "<tr>";
// if (locust.region_id == null || locust.region_id.isEmpty() || locust.district_id == null || locust.district_id.isEmpty() || locust.locust_type_id == null || locust.locust_type_id.isEmpty()) {
// row = "<tr style=\"background-color:red;\">";
// }
// row += "<td>" + String.valueOf(cntO+cntV) + "</td><td>" + locust.eid + "</td><td>" + locust.lat + "</td><td>" + locust.lon + "</td><td>" + locust.region + " = " + locust.region_id + "</td><td>" + locust.district + " = " + locust.district_id + "</td><td>" + locust.terrain + "</td><td>" + locust.village + "</td><td>" + locust.locust + " = " + locust.locust_type_id + "</td><td>" + locust.phase + " = " + locust.locust_have + "</td><td>" + locust.evp + "</td><td>" + locust.size + " = " + locust.drawPolygon + "</td><td>" + locust.date + "</td>";
// row += "</tr>\n";
//
// //Если записи не существует то вставляем если существует то обновляем
// boolean exists = false; //Is there a record.
// Statement st;
// try {
// st = conn.createStatement();
// //ResultSet rs=null;
// try {
// String sql = "select 1 from main.frmlocust where eid=" + String.valueOf(locust.eid);
// rs = st.executeQuery(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error select");
// return "json";
// }
// if (rs != null) {
// if (rs.next())
// exists = true;
// }
// st.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error select 2");
// return "json";
// }
//
// PreparedStatement stmt = null;
// String sql = "";
// if (exists) {
// System.out.println(String.valueOf(cntV)+") update main.frmlocust");
// sql = "update main.frmlocust set\n"
// + " eid=?,\n"
// + " lat_center=?,\n"
// + " lon_center=?,\n"
// + " country_id=?,\n"
// + " region_id=?,\n"
// + " area=?,\n"
// + " district=?,\n"
// + " date=TO_TIMESTAMP(?, 'DD.MM.YYYY HH24:MI'),\n"
// + " description=?,\n"
// + " geom=ST_SetSRID(ST_GeomFromGeoJSON(?),4326),\n"
// + " locust_type_id=?,\n"
// + " imago_density=?,\n"
// + " kuliguli_density=?,\n"
// + " larva_density=?,\n"
// + " bio_hectare=?\n,"
// + " eggs_capsules_density=?,\n"
// + " bio_biotope_id=?\n"
// + " where eid='" + locust.eid + "'";
// try {
// stmt = conn.prepareStatement(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error prepare 1");
// return "json";
// }
// } else {
// System.out.println(String.valueOf(cntV)+") insert into main.frmlocust");
// sql = "insert into main.frmlocust(\n"
// + " eid,\n" //1
// + " lat_center,\n" //2
// + " lon_center,\n" //3
// + " country_id,\n" //4
// + " region_id,\n" //5
// + " area,\n" //6
// + " district,\n" //7
// + " date,\n" //8
// + " description,\n" //9
// + " geom,\n" //10
// + " locust_type_id,\n" //11
// + " imago_density,\n" //12
// + " kuliguli_density,\n" //13
// + " larva_density,\n" //14
// + " bio_hectare,\n" //15
// + " eggs_capsules_density,\n" //16
// + " bio_biotope_id\n" //17
// + ")values(\n"
// + " ?,\n" //1 eid
// + " ?,\n" //2 lat1
// + " ?,\n" //3 lon1
// + " ?,\n" //4 country_id
// + " ?,\n" //5 region_id
// + " ?,\n" //6 district (area)
// + " ?,\n" //7 district (area)
// + " TO_TIMESTAMP(?, 'DD.MM.YYYY HH24:MI'),\n" //8 date
// + " ?,\n" //9 description
// + " ST_SetSRID(ST_GeomFromGeoJSON(?),4326),\n" //10 geom
// + " ?,\n" //11 locust_type_id
// + " ?,\n" //12 imago_density
// + " ?,\n" //13 kuliguli_density
// + " ?,\n" //14 larva_density
// + " ?,\n" //15
// + " ?,\n" //16
// + " ?\n" //17
// + ")";
// try {
// stmt = conn.prepareStatement(sql);
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error prepare 2");
// return "json";
// }
// }
//
// try {
// stmt.setInt(1, locust.eid);
// stmt.setDouble(2, locust.lat);
// stmt.setDouble(3, locust.lon);
// stmt.setInt(4, 7);
// stmt.setInt(5, Integer.parseInt(locust.region_id));
// stmt.setString(6, locust.district); //Пишу в поле "area"
// stmt.setString(7, null);
// stmt.setString(8, locust.date); //27.04.2020 09:17
// stmt.setString(9, locust.description);
// stmt.setString(10, locust.drawPolygon);
// stmt.setInt(11, Integer.parseInt(locust.locust_type_id));
// if (locust.imago_density != null)
// stmt.setFloat(12, Float.parseFloat(locust.imago_density));
// else
// stmt.setNull(12, Types.FLOAT);
// if (locust.kuliguli_density != null)
// stmt.setFloat(13, Float.parseFloat(locust.kuliguli_density));
// else
// stmt.setNull(13, Types.FLOAT);
// if (locust.larva_density != null)
// stmt.setFloat(14, Float.parseFloat(locust.larva_density));
// else
// stmt.setNull(14, Types.FLOAT);
// if (locust.bio_hectare != null)
// stmt.setFloat(15, Float.parseFloat(locust.bio_hectare));
// else
// stmt.setNull(15, Types.FLOAT);
// if (locust.eggs_capsules_density != null)
// stmt.setFloat(16, Float.parseFloat(locust.eggs_capsules_density));
// else
// stmt.setNull(16, Types.FLOAT);
// if (locust.bio_biotope_id != null)
// stmt.setFloat(17, Float.parseFloat(locust.bio_biotope_id));
// else
// stmt.setNull(17, Types.INTEGER);
//
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error set data");
// return "json";
// }
// //Выпоняю запрос на свтавку либо обновление
// try {
// stmt.execute();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error execute 0");
// return "json";
// }
// cntV++;
//
// //Скачиваю фотографию для анкеты
// sb = new StringBuilder();
// try {
// String strURL = "https://rscagex.ru/pmon/rest/getPhotosByParentId?token=QVOUE97HBSI6LBSGJGQZMP3KPSS1QK&parentId=" + locust.eid;
// URL url = new URL(strURL);
// HttpURLConnection hConn = (HttpURLConnection) url.openConnection();
// hConn.setRequestMethod("GET");
// //hConn.setRequestProperty("Range","bytes=" + posStart + "-" + posEnd);
// hConn.connect();
// int responseCode = hConn.getResponseCode();
// if (responseCode / 100 == 2) //Code 206 is "Partial Content"
// {
// InputStream inputStream = hConn.getInputStream();
// //FileOutputStream outputStream = new FileOutputStream(strFile);
// int bytesRead;
// byte[] buffer = new byte[BUFFER_SIZE];
// while ((bytesRead = inputStream.read(buffer)) != -1) {
// //outputStream.write(buffer, 0, bytesRead);
// sb.append(new String(buffer, 0, bytesRead));
// }
// //outputStream.close();
// inputStream.close();
// }
// hConn.disconnect();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// String base64 = sb.toString();
// if (base64.length() > 10) {
// //Так как мне присылаю неправильный jSOM то пытаюсь е г о поправить,.
// base64 = base64.replace("[", "[\"");
// base64 = base64.replace("]", "\"]");
// base64 = base64.replace(", ", "\",\"");
//
// String strFile = "O:\\temp\\CCALM\\ru_" + locust.eid;
// int pos = 0;
//
// JSONArray jsonArrayIMGS = new JSONArray(base64);
// for (Object oStr : jsonArrayIMGS) {
// String jsonObjIMG = (String) oStr;
// pos++;
// if (pos > 3) break;
//
// //try {
// // BufferedWriter writer = new BufferedWriter(new FileWriter(strFile));
// // writer.write(jsonObjIMG);
// // writer.close();
// //} catch (IOException e1) {
// // e1.printStackTrace();
// //}
//
// byte[] decodedString = null;
// try {
// decodedString = Base64.getDecoder().decode(jsonObjIMG);
// } catch (Exception e) {
// e.printStackTrace();
// //model.addAttribute("PreviewTable", "Error decode");
// return "json";
// }
//
// if (decodedString != null) {
// try {
// FileUtils.writeByteArrayToFile(new File(strFile + "_" + pos + ".jpg"), decodedString);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// decodedString = null;
//
// BufferedImage imageOnDisk = null;
// try {
// imageOnDisk = ImageIO.read(new File(strFile + "_" + pos + ".jpg"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// if (imageOnDisk != null) {
// Image img;
// BufferedImage buffered;
// if (imageOnDisk.getWidth() > imageOnDisk.getHeight()) {
// img = imageOnDisk.getScaledInstance(1024, 768, Image.SCALE_DEFAULT);
// buffered = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB);
// buffered.getGraphics().drawImage(img, 0, 0, null);
// } else {
// img = imageOnDisk.getScaledInstance(768, 1024, Image.SCALE_DEFAULT);
// buffered = new BufferedImage(768, 1024, BufferedImage.TYPE_INT_RGB);
// buffered.getGraphics().drawImage(img, 0, 0, null);
// }
// try {
// //BufferedImage bIMG = toBufferedImage(img);
// ImageIO.write(buffered, "jpg", new File(strFile + "_" + pos + ".jpg"));
// } catch (IOException ex) {
// ex.printStackTrace();
// }
// }
//
//
// if (pos > 3) {
// break;
// } else {
// sql = "";
// if (pos == 1) {
// sql = "update main.frmlocust set image_name1='ru_" + locust.eid + "_" + pos + ".jpg" + "' where eid=" + locust.eid;
// }
// if (pos == 2) {
// sql = "update main.frmlocust set image_name2='ru_" + locust.eid + "_" + pos + ".jpg" + "' where eid=" + locust.eid;
// }
// if (pos == 3) {
// sql = "update main.frmlocust set image_name3='ru_" + locust.eid + "_" + pos + ".jpg" + "' where eid=" + locust.eid;
// }
// if (sql.length() > 0) {
// try {
// st = conn.createStatement();
// st.execute(sql);
// st.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error update img");
// return "json";
// }
// }
// }
// }
// }
// }
//
// } //equals("Вредители")
//
// }
//
// }
//
// table += row;
//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 + + ;
if ( count = = 66 )
System . out . println ( " count = " + count ) ;
System . out . println ( " count = " + count ) ;
}
// System.out.println("Обработка = "+String.valueOf(cntO));
// System.out.println("Вредители = "+String.valueOf(cntV));
//
//
// table += "</table>";
//
// //json=json.substring(0,json.length()-1); //Удаляю последнюю запятую
// //json+="\n]}";
//
// //Сохраняю lastDate в базу данных
// try {
// Statement st = conn.createStatement();
// st.execute("insert into integration.days_ru(date,count)values('" + lastDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'," + String.valueOf(cntV+cntO) + ");");
// st.close();
// } catch (SQLException ex) {
// ex.printStackTrace();
// //model.addAttribute("PreviewTable", "Error update img");
// return "json";
// }
}
//Save last download date
String insertSql = """
insert into integration.days_uz (date, count) values (:date, :count)
""" ;
MapSqlParameterSource insertParams = new MapSqlParameterSource ( ) ;
insertParams . addValue ( " date " , lastDate , Types . DATE ) ;
insertParams . addValue ( " count " , count , Types . INTEGER ) ;
jdbcTemplate . update ( insertSql , insertParams ) ;
}
} catch ( CustomException e ) {
@ -2378,8 +1539,10 @@ public class AcceptJSON implements ServletContextAware {
FrmLocustModel result = new FrmLocustModel ( ) ;
result . company_uid = " dc271f2e-1a4b-4987-96ec-7afd91350684 " ; //Компания: "Узбекистан саранча "
result . e id = String . valueOf ( obj. getInt ( " id " ) ) ;
result . company_uid = " dc271f2e-1a4b-4987-96ec-7afd91350684 " ; //Company: "Uzbekistan Locust "
result . u id = obj . getString ( " uu id" ) ;
result . eid = String . valueOf ( obj . getInt ( " id " ) ) ; //Internal identifier in the Uzbek database
result . seq = obj . getLong ( " seq " ) * 1000 ;
result . country_id = " 10 " ; //Uzbekistan
result . country_uid = " 05592f5a-1c8b-4d87-a47f-67697cc12c49 " ; //Uzbekistan
@ -2582,9 +1745,30 @@ public class AcceptJSON implements ServletContextAware {
result . bio_temperature = obj . optString ( " air_temperature " , null ) ;
if ( result . bio_temperature ! = null & & result . bio_temperature . isEmpty ( ) ) result . bio_temperature = null ;
if ( result . bio_temperature ! = null & & result . bio_temperature . contains ( " .. " ) ) {
result . bio_temperature = result . bio_temperature . substring ( result . bio_temperature . indexOf ( " .. " ) + 2 ) ;
}
if ( result . bio_temperature ! = null ) {
try {
Double . parseDouble ( result . bio_temperature ) ;
} catch ( NumberFormatException e ) {
System . out . println ( " Double bio_temperature error " + result . bio_temperature ) ;
}
}
result . bio_wind = obj . optString ( " wind_speed " , null ) ;
if ( result . bio_wind ! = null & & result . bio_wind . contains ( " .. " ) ) {
result . bio_wind = result . bio_wind . substring ( result . bio_wind . indexOf ( " .. " ) + 2 ) ;
}
if ( result . bio_wind ! = null & & result . bio_wind . isEmpty ( ) ) result . bio_wind = null ;
if ( result . bio_wind ! = null ) {
try {
Double . parseDouble ( result . bio_wind ) ;
} catch ( NumberFormatException e ) {
System . out . println ( " Double bio_wind error " + result . bio_wind ) ;
}
}
//Вид саранчи
if ( ! obj . isNull ( " subject_name " ) & & ! obj . optString ( " subject_name " , " " ) . isBlank ( ) ) {
@ -2625,6 +1809,8 @@ public class AcceptJSON implements ServletContextAware {
result . eggs_capsules_density = obj . optString ( " eggs_pods_density_from_m2 " , null ) ;
result . eggs_capsules_density_to = obj . optString ( " eggs_pods_density_to_m2 " , null ) ;
result . eggs_capsules = obj . optString ( " eggs_average_number_egg_pod " , null ) ;
if ( result . eggs_capsules ! = null & & result . eggs_capsules . equals ( " . " ) ) result . eggs_capsules = " 0 " ;
result . eggs_live = obj . optString ( " eggs_viable " , null ) ;
if ( ! obj . isNull ( " eggs_natural_enemies " ) & & ! obj . optString ( " eggs_natural_enemies " , " " ) . isBlank ( ) ) {
switch ( obj . optString ( " eggs_natural_enemies " , null ) . replace ( " ' " , " " ) . trim ( ) ) {
@ -2889,7 +2075,27 @@ public class AcceptJSON implements ServletContextAware {
}
result . swarm_maturity = obj . optString ( " swarms_maturity " , null ) ; // boolean,
res ult . swarm_density_id = obj . optString ( " swarms_density " , null ) ; // integer,
if ( ! obj . isN ull ( " swarms _density" ) & & ! obj . optString ( " swarms_density " , " " ) . isBlank ( ) ) {
switch ( obj . optString ( " swarms_density " , null ) . replace ( " ' " , " " ) . trim ( ) ) {
case " Low density " , " Низкая " :
result . swarm_density_id = " 1 " ;
result . swarm_density_uid = " d64bdd10-bf56-43a7-96b5-b9d22f36c19a " ;
break ;
case " Middle density " , " Средние " , " Среднее " :
result . swarm_density_id = " 2 " ;
result . swarm_density_uid = " c0ec55a0-54fa-4df6-a683-a3690eafe464 " ;
break ;
case " High height " , " Высокая " :
result . swarm_density_id = " 3 " ;
result . swarm_density_uid = " accbb2e3-7b6e-4a7d-9b2b-2569b05c60ef " ;
break ;
default :
throw new CustomException ( 200 , 10000 , " Not find swarms_density: ( " + obj . optString ( " swarms_density " , null ) + " ) " , null , true ) ;
}
}
if ( ! obj . isNull ( " swarms_height " ) & & ! obj . optString ( " swarms_height " , " " ) . isBlank ( ) ) {
result . swarm_size = obj . optString ( " swarms_size " , null ) ; // double precision,
result . swarm_count = obj . optString ( " swarms_count " , null ) ; // double precision,
//result.swarm_copulation = obj.optString("",null); // boolean,