";
}
- row += "| " + String.valueOf(cntO+cntV) + " | " + locust.eid + " | " + locust.lat + " | " + locust.lon + " | " + locust.region + " = " + locust.region_id + " | " + locust.district + " = " + locust.district_id + " | " + locust.terrain + " | " + locust.village + " | " + locust.locust + " = " + locust.locust_id + " | " + locust.phase + " = " + locust.locust_have + " | " + locust.evp + " | " + locust.size + " = " + locust.drawPolygon + " | " + locust.date + " | ";
+ row += "" + String.valueOf(cntO+cntV) + " | " + locust.eid + " | " + locust.lat + " | " + locust.lon + " | " + regionName + " = " + locust.region_id + " | " + locust.district + " = " + locust.district_id + " | " + locust.terrain + " | " + locust.village + " | " + locust.locust + " = " + locust.locust_type_id + " | " + locust.phase + " = " + locust.locust_have + " | " + locust.evp + " | " + locust.size + " = " + locust.drawPolygon + " | " + locust.date + " | ";
row += "
\n";
//Если записи не существует то вставляем если существует то обновляем
@@ -1160,7 +1183,7 @@ public class AcceptJSON implements ServletContextAware {
}
try {
- stmt.setInt(1, locust.eid);
+ stmt.setLong(1, locust.eid);
stmt.setDouble(2, locust.lat);
stmt.setDouble(3, locust.lon);
stmt.setInt(4, 7);
@@ -1170,7 +1193,7 @@ public class AcceptJSON implements ServletContextAware {
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_id));
+ stmt.setInt(11, Integer.parseInt(locust.locust_type_id));
if (locust.imago_density != null)
stmt.setFloat(12, Float.parseFloat(locust.imago_density));
else
@@ -1373,978 +1396,945 @@ public class AcceptJSON implements ServletContextAware {
return "json";
}
//---------------------------------------------------------------------------
+ //https://127.0.0.1:8081/AcceptJSON_UZB
@ResponseBody
- @RequestMapping(value = "/AcceptJSON_UZB", method = { RequestMethod.GET, RequestMethod.POST })
+ @RequestMapping(value = "/AcceptJSON_UZB", method = { RequestMethod.GET, RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
public String acceptUZB(@ModelAttribute User user) {
+ JSONObject json = new JSONObject();
+ try{
+ json.put("error_code",0);
+ json.put("error_message","");
- Connection conn = null;
- try {
- Class.forName("org.postgresql.Driver");
- conn = DriverManager.getConnection(db_url, db_login, db_password);
- } catch (Exception ex) {
- ex.printStackTrace();
- return "{\"error_code\":10000}";
- }
+ String sql;
- //Set UTC time
- Statement stm=null;
- try {
- stm = conn.createStatement();
- try {
- stm.execute("SET timezone TO 'UTC';");
- } catch( SQLException ex ) {
- ex.printStackTrace();
- }
- stm.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
-
-
- String sqlData="";
- String table="";
- }
- row += "| " + String.valueOf(cntO+cntV) + " | " + locust.eid + " | " + locust.lat + " | " + locust.lon + " | " + locust.region + " = " + locust.region_id + " | " + locust.district + " = " + locust.district_id + " | " + locust.terrain + " | " + locust.village + " | " + locust.locust + " = " + locust.locust_id + " | " + locust.phase + " = " + locust.locust_have + " | " + locust.evp + " | " + locust.size + " = " + locust.drawPolygon + " | " + locust.date + " | ";
- row += "
\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_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;
- }
- System.out.println("Обработка = "+String.valueOf(cntO));
- System.out.println("Вредители = "+String.valueOf(cntV));
-
-
- 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";
- }
- }
- }
- //model.addAttribute("PreviewTable",table);
- //model.addAttribute("PreviewGEOJSON",json);
- //model.addAttribute("PreviewSQL",sqlData);
-
- return "json";
+ return json.toString();
}
//---------------------------------------------------------------------------
public static BufferedImage toBufferedImage(Image img)
@@ -2382,49 +2372,563 @@ public class AcceptJSON implements ServletContextAware {
return result;
}
//---------------------------------------------------------------------------
- class Locust{
- int eid; //Внешний идентификатор
- String phytoType; //Вредители либо обработка
-
- double lon;
- double lat;
- String region; //Область
- String region_id;
-
- String district; //Район
- String district_id;
-
- String terrain=""; //Название месности
-
- String village; //Хозяйство или местность
-
- String locust; //Вид саранчи
- String locust_id; //Вид саранчи
-
- String phase=null; //Фаза саранчи
- String locust_have; //id Фазы саранчи
- String evp; //ЭФП
- String drawPolygon="null"; //Область обследования GeoGSON
- String size; //Заселённая площадь (polygonArea Площадь контура зоны распространения, в случае если специалист указал его)
- String date; //Дата
-
- String description="";
-
+ public FrmLocustModel convertUZBJSONToLocustModel(JSONObject obj) throws CustomException {
- String eggs_capsules_density=null; //Плотность яиц
- String kuliguli_density=null; //Плотность кулиг на м²
- String imago_density=null; //Плотность имаго (/м²)*
- String larva_density=null; //Плотность личинок
-
- String bio_hectare=null; //Обследованная площадь
- String bio_biotope_id=null; //Тип тиотопа
-
- //Ниже то что относиться только к обработке
- String insecticide_name=null;
- String insecticide_active_substance=null;
- String insecticide_dose=null;
- String spray_platform=null;
-
+ FrmLocustModel result = new FrmLocustModel();
+
+ result.company_uid = "dc271f2e-1a4b-4987-96ec-7afd91350684"; //Компания: "Узбекистан саранча"
+ result.eid = obj.getInt("id");
+ result.seq = obj.getLong("seq")*1000;
+ result.country_id = 10; //Uzbekistan
+ result.country_uid = "05592f5a-1c8b-4d87-a47f-67697cc12c49"; //Uzbekistan
+
+ if(!obj.isNull("region_name")) {
+ switch (obj.getString("region_name")) {
+ case "Sirdaryo viloyati":
+ result.region_id = "31";
+ result.region_uid = "8f4f586f-6159-4fbf-a627-2c8d637abb5e";
+ break;
+ case "Toshkent shahri":
+ result.region_id = "156";
+ result.region_uid = "1ed7b6f3-47a8-4128-ae0a-c160f5c3af08";
+ break;
+ case "Toshkent viloyati":
+ result.region_id = "157";
+ result.region_uid = "c8fccdc4-256a-4699-ab09-16c51351bf28";
+ break;
+ case "Surxondaryo viloyati":
+ result.region_id = "30";
+ result.region_uid = "369c296d-5ff5-4570-88ad-0e94ccf9cb7c";
+ break;
+ case "Jizzax viloyati":
+ result.region_id = "25";
+ result.region_uid = "a7185680-7afc-47f1-954e-3d0f8b296592";
+ break;
+ case "Республики Каракалпакстан":
+ result.region_id = "22";
+ result.region_uid = "421ce759-b571-454e-b390-a73bee9b8b2c";
+ break;
+ case "Xorazm viloyati":
+ result.region_id = "34";
+ result.region_uid = "8bc74ac4-ce06-4317-9982-b1492c72edb7";
+ break;
+ case "Andijon viloyati":
+ result.region_id = "23";
+ result.region_uid = "a045faa8-eb12-40db-be30-be6e41e59bb2";
+ break;
+ case "Fargʻona viloyati":
+ result.region_id = "33";
+ result.region_uid = "e97ac81d-dab5-4496-9e0f-0c5508972539";
+ break;
+ case "Namangan viloyati":
+ result.region_id = "28";
+ result.region_uid = "e931af2e-0035-4149-b3b9-00895e4e1453";
+ break;
+ case "Buxoro viloyati":
+ result.region_id = "24";
+ result.region_uid = "0caf3854-48ad-40ed-9602-302c28b1a5b8";
+ break;
+ case "Navoiy viloyati":
+ result.region_id = "27";
+ result.region_uid = "ef244a76-8e7c-4e16-ad80-058b740fa6ca";
+ break;
+ case "Qashqadaryo viloyati":
+ result.region_id = "158";
+ result.region_uid = "cf9a0a6e-18fa-41a0-bd9d-39c5fd1260c1";
+ break;
+ case "Samarqand viloyati":
+ result.region_id = "29";
+ result.region_uid = "2a6adb56-19a7-4f28-9a00-87559db91db9";
+ break;
+ default:
+ System.out.println(obj.getString("region_name"));
+ throw new CustomException(10000, "Not find region by region_name: " + obj.getString("region_name"), null, true);
+ }
+ }
+ result.district = obj.getString("town_name");
+ result.date = obj.getString("date");
+
+ result.bio_hectare = obj.getString("surveyed_area");
+ if (!obj.isNull("point")) {
+ result.lon = obj.getJSONObject("point").getJSONArray("coordinates").getDouble(0);
+ result.lat = obj.getJSONObject("point").getJSONArray("coordinates").getDouble(1);
+ }
+
+ //Биотоп
+ if(!obj.isNull("biotope_type")) {
+ switch (obj.getString("biotope_type")) {
+ case "CIT степь","CIT steppe":
+ result.bio_biotope_id = "1";
+ result.bio_biotope_uid = "e6fa860a-ca2f-4cd7-8cfc-b97d86d2cd2d";
+ break;
+ case "CIT залежь","CIT fallow":
+ result.bio_biotope_id = "2";
+ result.bio_biotope_uid = "54dca7f3-80c3-4437-b523-c022f3f22104";
+ break;
+ case "CIT посевы","CIT crops":
+ result.bio_biotope_id = "3";
+ result.bio_biotope_uid = "ef2b054a-1b06-4c81-8c34-d5185b1ac468";
+ break;
+ case "CIT пастбища","CIT pastures":
+ result.bio_biotope_id = "11";
+ result.bio_biotope_uid = "1c04ef99-ebdd-4920-880d-d9f615576e36";
+ break;
+ case "CIT холмы, горы","CIT hills, mountains":
+ result.bio_biotope_id = "19";
+ result.bio_biotope_uid = "e076bc30-7a47-4f69-b3c2-154328341c8e";
+ break;
+ case "DMA равнины","DMA flatlands":
+ result.bio_biotope_id = "4";
+ result.bio_biotope_uid = "8b815530-4b12-43af-89b6-31736f331b2d";
+ break;
+ case "DMA посевы","DMA crops":
+ result.bio_biotope_id = "6";
+ result.bio_biotope_uid = "54fcd2da-3130-4a69-a5ff-b048d863a9a5";
+ break;
+ case "DMA пастбища","DMA pastures":
+ result.bio_biotope_id = "13";
+ result.bio_biotope_uid = "4082f926-3f36-4782-b656-5484340a30b5";
+ break;
+ case "DMA холмы, горы","DMA hills, mountains":
+ result.bio_biotope_id = "14";
+ result.bio_biotope_uid = "e4596123-d6c3-4525-a9a5-ee2270767894";
+ break;
+ case "LMI низкие сухие тростники","LMI low dry reeds":
+ result.bio_biotope_id = "7";
+ result.bio_biotope_uid = "4ca678e5-d9d8-4941-85c0-51010fb212d3";
+ break;
+ case "LMI высокие влажные тростники","LMI high wet reeds":
+ result.bio_biotope_id = "8";
+ result.bio_biotope_uid = "ccc53f69-ce5f-4eb4-8158-85146c591b69";
+ break;
+ case "LMI другое","LMI others":
+ result.bio_biotope_id = "10";
+ result.bio_biotope_uid = "f91b4f3e-16e1-45af-bbb0-5ff474273da3";
+ break;
+ case "Другие саранчовые на посевах","Other locust crops":
+ result.bio_biotope_id = "15";
+ result.bio_biotope_uid = "8fee003a-b3b4-462e-b76e-a7b89d439647";
+ break;
+ case "Другие саранчовые на равнине","Other locust flatlands":
+ result.bio_biotope_id = "16";
+ result.bio_biotope_uid = "692123dd-6c02-4c96-a075-ce94789eeabe";
+ break;
+ case "Другие саранчовые на холмах","Other locust hills":
+ result.bio_biotope_id = "17";
+ result.bio_biotope_uid = "c82f2609-b50a-4ca4-babc-ae3426f22b81";
+ break;
+ case "Другое","Other locust":
+ result.bio_biotope_id = "18";
+ result.bio_biotope_uid = "e99a8868-2582-41e8-9c01-bef5fca8f0d1";
+ break;
+ default:
+ throw new CustomException(10000, "Not find biotopee: " + obj.getString("biotope_type"), null, true);
+ }
+ }
+
+ //растительность
+ if(!obj.isNull("vegetation")) {
+ switch (obj.getString("vegetation")) {
+ case "Plant absent":
+ result.bio_greenery_id = "8";
+ result.bio_greenery_uid = "5621f2f2-56e8-486f-abc0-7eba996b6724";
+ break;
+ case "Plant dry":
+ result.bio_greenery_id = "7";
+ result.bio_greenery_uid = "04ba0a4a-0557-490f-a08b-0db51a83cf7c";
+ break;
+ case "Желтеющая трава": //Plant drying
+ result.bio_greenery_id = "6";
+ result.bio_greenery_uid = "99381409-ad1a-4ac8-95df-415ccb1334e1";
+ break;
+ case "Plant green":
+ result.bio_greenery_id = "5";
+ result.bio_greenery_uid = "8fab82b8-8924-458d-b3f1-90a18ed75f9b";
+ break;
+ case "Plant greening":
+ result.bio_greenery_id = "4";
+ result.bio_greenery_uid = "682993e1-3e5b-4aa0-9f11-c2a30a9c5908";
+ break;
+ default:
+ throw new CustomException(10000, "Not find vegetation: " + obj.getString("vegetation"), null, true);
+ }
+ }
+
+ //Густота растительного покрова
+ if(!obj.isNull("vegetation_cover")) {
+ switch (obj.getString("vegetation_cover")) {
+ case "Sparse": //Sparse
+ result.bio_greenery_cover_id = "8";
+ result.bio_greenery_cover_uid = "c70a145b-cfe4-4ad9-9ef8-814c9e3a1fac";
+ break;
+ case "Medium": //Medium
+ result.bio_greenery_cover_id = "9";
+ result.bio_greenery_cover_uid = "d66bdde4-72a7-497f-b5e8-3174aebd7165";
+ break;
+ case "Густая": //Dense
+ result.bio_greenery_cover_id = "10";
+ result.bio_greenery_cover_uid = "4c12085b-4f42-4ba2-9236-465d5c5d0690";
+ break;
+ case "Absent": //Absent
+ result.bio_greenery_cover_id = "0";
+ result.bio_greenery_cover_uid = "f712fe9a-2e42-44b9-b3dc-a7a1dc4767e8";
+ break;
+ default:
+ throw new CustomException(10000, "Not find vegetation_cover: " + obj.getString("vegetation_cover"), null, true);
+ }
+ }
+
+ result.bio_temperature = obj.getString("air_temperature");
+ if(result.bio_temperature.isEmpty()) result.bio_temperature = null;
+
+ result.bio_wind = obj.getString("wind_speed");
+ if(result.bio_wind.isEmpty()) result.bio_wind = null;
+
+ //Вид саранчи
+ if(!obj.isNull("subject_name")) {
+ switch (obj.getString("subject_name")) {
+ case "Мароккская саранча":
+ result.locust_type_id = "2";
+ break;
+ case "Итальянский прус":
+ result.locust_type_id = "1";
+ break;
+ case "Азиатская саранча":
+ result.locust_type_id = "3";
+ break;
+ default:
+ throw new CustomException(10000, "Not find vegetation_cover: " + obj.getString("vegetation_cover"), null, true);
+ }
+ }
+
+ //Area infested (ha)
+ result.locust_populated = obj.getString("infested_area");
+
+ result.eggs_capsules_area = obj.getString("eggs_bed_area");
+ result.eggs_capsules_density = obj.getString("eggs_pods_density_from_m2");
+ result.eggs_capsules_density_to = obj.getString("eggs_pods_density_to_m2");
+ result.eggs_capsules = obj.getString("eggs_average_number_egg_pod");
+ result.eggs_live = obj.getString("eggs_viable");
+ if(!obj.isNull("eggs_natural_enemies")) {
+ switch (obj.getString("eggs_natural_enemies")) {
+ case "not", "Нет":
+ result.eggs_enemies_id = "5";
+ result.eggs_enemies_uid = "52580c53-3d13-4b93-b84e-fcf9cbd50e01";
+ break;
+ case "Other", "Другое":
+ result.eggs_enemies_id = "4";
+ result.eggs_enemies_uid = "d13c793f-f65e-4a34-9307-940289cd4265";
+ break;
+ case "Larvae of beetles", "Личинки жуков":
+ result.eggs_enemies_id = "3";
+ result.eggs_enemies_uid = "76cf72d8-8ac5-44de-98f3-a7221d2c7985";
+ break;
+ case "Larvae of flies", "Личинки мух":
+ result.eggs_enemies_id = "2";
+ result.eggs_enemies_uid = "e2e573a3-9859-46f9-99e6-f97d7fc37ea2";
+ break;
+ case "Fungal diseases", "Грибные заболевания":
+ result.eggs_enemies_id = "1";
+ result.eggs_enemies_uid = "d0cf06f4-6e1f-4da2-b836-45dfdef5da98";
+ break;
+ default:
+ throw new CustomException(10000, "Not find eggs_natural_enemies: " + obj.getString("eggs_natural_enemies"), null, true);
+ }
+ }
+
+ result.larva_born = null; // not used
+ if(!obj.isNull("hoppers_hatching")){
+ switch (obj.getString("hoppers_hatching")) {
+ case "Beginning","Начало":
+ result.larva_born_id="1";
+ result.larva_born_uid="392db9f2-bfaa-44e0-8ca3-bb3cf1ff937a";
+ break;
+ case "Mass","Массовое":
+ result.larva_born_id="2";
+ result.larva_born_uid="3210fcfb-3885-4b0e-92c7-3c6f6a0b7134";
+ break;
+ default:
+ throw new CustomException(10000, "Not find hoppers_hatching: " + obj.getString("hoppers_hatching"),null,true);
+ }
+ }
+
+ //Hopper stages
+ if(!obj.isNull("hoppers_stages")){
+ switch (obj.getString("hoppers_stages")) {
+ case "Early","Младшие":
+ result.larva_age_id="1";
+ result.larva_age_uid="becdbc31-094e-48bb-aef0-93f88abff12d";
+ break;
+ case "Early & Mid","Младшие и средние":
+ result.larva_age_id="5";
+ result.larva_age_uid="7d4f7ed7-bcd1-4063-b42e-e82eb570ba56";
+ break;
+ case "Middle","Средние":
+ result.larva_age_id="2";
+ result.larva_age_uid="69339c47-f4d2-4c71-a594-b021acaccfab";
+ break;
+ case "Late","Старшие":
+ result.larva_age_id="3";
+ result.larva_age_uid="6f95d125-e328-47c2-8793-d67979378f5f";
+ break;
+ case "Mixed","Смешанные возраста":
+ result.larva_age_id="6";
+ result.larva_age_uid="5acd65b3-e32f-4984-83ad-dfba2b7f0205";
+ break;
+ default:
+ throw new CustomException(10000, "Not find hoppers_hatching: " + obj.getString("hoppers_hatching"),null,true);
+ }
+ }
+
+ //Appearance
+ if(!obj.isNull("hoppers_appearance")){
+ switch (obj.getString("hoppers_appearance")) {
+ case "Solitary","Одиночная":
+ result.larva_age_id="1";
+ result.larva_age_uid="30fa1f49-166e-4a17-9cd8-d611b36844f8";
+ break;
+ case "Transiens","Переходная":
+ result.larva_age_id="2";
+ result.larva_age_uid="a0146c08-17b4-4384-8764-b7541c106d10";
+ break;
+ case "Gregarious","Стадная":
+ result.larva_age_id="3";
+ result.larva_age_uid="683cdba3-2f4c-4e61-b667-936c524136b4";
+ break;
+ default:
+ throw new CustomException(10000, "Not find hoppers_hatching: " + obj.getString("hoppers_hatching"),null,true);
+ }
+ }
+
+ //Spatial distribution
+ if(!obj.isNull("hoppers_spatial_distribution")){
+ switch (obj.getString("hoppers_spatial_distribution")) {
+ case "Isolated","Одиночные":
+ result.larva_behavior_id="1";
+ result.larva_behavior_uid="64a7a8f5-b44d-4fd7-b78c-3c0837f57b99";
+ break;
+ case "Scattered","Разреженные":
+ result.larva_behavior_id="2";
+ result.larva_behavior_uid="14f64f3a-f35c-416d-a955-5896f55c7e41";
+ break;
+ case "Groups","Группы":
+ result.larva_behavior_id="3";
+ result.larva_behavior_uid="bc8c7de0-0e79-4b40-8260-a74787e19902";
+ break;
+ default:
+ throw new CustomException(10000, "Not find hoppers_spatial_distribution: " + obj.getString("hoppers_spatial_distribution"),null,true);
+ }
+ }
+ result.larva_density = obj.getString("hoppers_density_from_m2"); //Hopper density numeric,
+ result.larva_density_to = obj.getString("hoppers_density_to_m2"); //Hopper density to numeric,
+
+ result.kuliguli_density = obj.getString("bands_density_from_m2");
+ result.kuliguli_density_to = obj.getString("bands_density_to_m2");
+ result.kuliguli_size = obj.getString("bands_sizes_m2");
+ result.kuliguli_count = obj.getString("bands_number_in_ha");
+ if(!obj.isNull("bands_behaviour")){
+ switch (obj.getString("bands_behaviour")) {
+ case "Marching","Миграция":
+ result.kuliguli_action_id="1";
+ result.kuliguli_action_uid="4399f28c-b1ed-44f6-8af5-351cd944d408";
+ break;
+ case "Feeding","Питание":
+ result.kuliguli_action_id="2";
+ result.kuliguli_action_uid="49cd15e0-8a55-4a8f-8a2a-3872f770f248";
+ break;
+ case "Decreased activity","Понижение активности":
+ result.kuliguli_action_id="3";
+ result.kuliguli_action_uid="0fca9acd-9447-4653-9ca7-7dcac7cb495e";
+ break;
+ case "Stupor","Оцепенение":
+ result.kuliguli_action_id="4";
+ result.kuliguli_action_uid="63bb9eba-c4ad-4e2d-a1cd-ada1695abac5";
+ break;
+ case "Molting","Линька":
+ result.kuliguli_action_id="5";
+ result.kuliguli_action_uid="65bf377f-040b-4b5f-8dca-581e1d5d679f";
+ break;
+ default:
+ throw new CustomException(10000, "Not find bands_behaviour: " + obj.getString("bands_behaviour"),null,true);
+ }
+ }
+ if(!obj.isNull("bands_stages")){
+ switch (obj.getString("bands_stages")) {
+ case "Early","Младшие":
+ result.kuliguli_age_id="1";
+ result.kuliguli_age_uid="becdbc31-094e-48bb-aef0-93f88abff12d";
+ break;
+ case "Middle","средние":
+ result.kuliguli_age_id="2";
+ result.kuliguli_age_uid="69339c47-f4d2-4c71-a594-b021acaccfab";
+ break;
+ case "Late","Старшие":
+ result.kuliguli_age_id="3";
+ result.kuliguli_age_uid="6f95d125-e328-47c2-8793-d67979378f5f";
+ break;
+ case "Early & Mid","Младшие и средние":
+ result.kuliguli_age_id="5";
+ result.kuliguli_age_uid="7d4f7ed7-bcd1-4063-b42e-e82eb570ba56";
+ break;
+ case "Mixed","Смешанные возраста":
+ result.kuliguli_age_id="6";
+ result.kuliguli_age_uid="5acd65b3-e32f-4984-83ad-dfba2b7f0205";
+ break;
+ default:
+ throw new CustomException(10000, "Not find bands_behaviour: " + obj.getString("bands_behaviour"),null,true);
+ }
+ }
+
+ //Adults (Имаго)
+ if(!obj.isNull("adults_fledging")){
+ switch (obj.getString("adults_fledging")) {
+ case "Beginning","Начало":
+ result.imago_wing_id="7";
+ result.imago_wing_uid="312bf2ac-dbdb-40be-b716-7f02f751a65e";
+ break;
+ case "Mass","Массовое":
+ result.imago_wing_id="6";
+ result.imago_wing_uid="97d5a02c-c3ed-4627-ae14-4f92d6eb2945";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_fledging: " + obj.getString("adults_fledging"),null,true);
+ }
+ }
+ if(!obj.isNull("adults_maturity")){ //Половозрелость (да, нет)
+ switch (obj.getString("adults_maturity").toLowerCase()) {
+ case "yes","да":
+ result.imago_maturity="true";
+ break;
+ case "no","нет":
+ result.imago_maturity="false";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_maturity: " + obj.getString("adults_maturity"),null,true);
+ }
+ }
+ if(!obj.isNull("bands_stages")){ // Bands stages
+ switch (obj.getString("bands_stages")) {
+ case "Solitary","Стадная":
+ result.imago_phase_id="4";
+ result.imago_phase_uid="a1325ab8-15f5-406a-be8d-d6ba78b18d11";
+ break;
+ case "Transiens","Одиночная":
+ result.imago_phase_id="5";
+ result.imago_phase_uid="454ad32d-e513-4cda-90eb-e3fcac9bd41c";
+ break;
+ case "Gregarious","Переходная":
+ result.imago_phase_id="6";
+ result.imago_phase_uid="5a7cacb9-c0f5-48e1-aa8c-c354565bf2f1";
+ break;
+ default:
+ throw new CustomException(10000, "Not find bands_stages: " + obj.getString("bands_stages"),null,true);
+ }
+ }
+
+ if(!obj.isNull("adults_spatial_distribution")){ // Bands stages
+ switch (obj.getString("adults_spatial_distribution")) {
+ case "Isolated","Одиночные":
+ result.imago_action_id="1";
+ result.imago_action_uid="c0b25ce8-7454-459a-9a54-b459eea1573a";
+ break;
+ case "Scattered","Разреженные":
+ result.imago_action_id="2";
+ result.imago_action_uid="ccf21065-0548-46da-a123-fc93be1298b3";
+ break;
+ case "Groups","Группы":
+ result.imago_action_id="3";
+ result.imago_action_uid="c120254b-cbb9-415a-8e41-fc4bb0ffe983";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_spatial_distribution: " + obj.getString("adults_spatial_distribution"),null,true);
+ }
+ }
+ result.imago_density = obj.getString("adults_density_m2");
+ result.imago_density_ga = obj.getString("adults_density_ha");
+ if(!obj.isNull("adults_roosting")){ //Половозрелость (да, нет)
+ switch (obj.getString("adults_roosting").toLowerCase()) {
+ case "yes","да":
+ result.imago_feeding="true";
+ break;
+ case "no","нет":
+ result.imago_feeding="false";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_roosting: " + obj.getString("adults_roosting"),null,true);
+ }
+ }
+
+ if(!obj.isNull("adults_copulation")){ // Спаривание
+ switch (obj.getString("adults_copulation").toLowerCase()) {
+ case "yes","да":
+ result.imago_copulation = "true";
+ break;
+ case "no","нет":
+ result.imago_copulation = "false";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_copulation: " + obj.getString("adults_copulation"),null,true);
+ }
+ }
+ //result.imago_laying = obj.getString("adults_laying");
+ if(!obj.isNull("adults_laying")){ // Яйцекладка
+ switch (obj.getString("adults_laying").toLowerCase()) {
+ case "yes","да":
+ result.imago_laying="true";
+ break;
+ case "no","нет":
+ result.imago_laying="false";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_laying: " + obj.getString("adults_laying"),null,true);
+ }
+ }
+ //result.imago_flying = obj.getString("adults_flying");
+ if(!obj.isNull("adults_flying")){ // Полёты
+ switch (obj.getString("adults_flying").toLowerCase()) {
+ case "yes","да":
+ result.imago_flying="true";
+ break;
+ case "no","нет":
+ result.imago_flying="false";
+ break;
+ default:
+ throw new CustomException(10000, "Not find adults_flying: " + obj.getString("adults_flying"),null,true);
+ }
+ }
+
+ result.swarm_maturity = obj.getString("swarms_maturity"); // boolean,
+ result.swarm_density_id = obj.getString("swarms_density"); // integer,
+ result.swarm_size = obj.getString("swarms_size"); // double precision,
+ result.swarm_count = obj.getString("swarms_count"); // double precision,
+ //result.swarm_copulation = obj.getString(""); // boolean,
+ //result.swarm_laying = obj.getString(""); // boolean,
+ result.swarm_flying_direction_id = obj.getString("swarms_flying_direction"); // integer,
+ if(obj.getString("swarms_height")!=null) {
+ switch (obj.getString("swarms_height")) {
+ case "Low height", "Низкая":
+ result.swarm_height_id = "1";
+ result.swarm_height_uid = "0d60a2d7-d732-4199-b966-bd72870a07cc";
+ break;
+ case "Middle height", "Средние":
+ result.swarm_height_id = "2";
+ result.swarm_height_uid = "1f28d742-b121-4a52-a193-39c3cb6695e0";
+ break;
+ case "High height", "Высокая":
+ result.swarm_height_id = "3";
+ result.swarm_height_uid = "305d3224-ac2e-4abe-8adc-058373f20127";
+ break;
+ default:
+ throw new CustomException(10000, "Not find swarms_height: " + obj.getString("swarms_height"), null, true);
+ }
+ }
+ result.description = obj.getString("description");
+ //"status":2 не знаю что за поле
+
+ result.update();
+ return result;
}
+
+
}
diff --git a/src/main/java/org/ccalm/main/UpdateLocust.java b/src/main/java/org/ccalm/main/UpdateLocust.java
new file mode 100644
index 0000000..220eee1
--- /dev/null
+++ b/src/main/java/org/ccalm/main/UpdateLocust.java
@@ -0,0 +1,413 @@
+package org.ccalm.main;
+
+import org.ccalm.main.models.FrmLocustModel;
+import org.json.JSONObject;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import tools.DBTools;
+
+import java.sql.Types;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+public class UpdateLocust {
+
+ private final NamedParameterJdbcTemplate jdbcTemplate;
+
+ UpdateLocust(NamedParameterJdbcTemplate jdbcTemplate){
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ public boolean update(FrmLocustModel locust){
+
+ String sql;
+ boolean exists=false; //Is there a record.
+
+ //Если данные пришли из внешнего источника то проверяем по ID компании и eid
+ if(locust.eid!=null && locust.uid==null) {
+ sql = """
+ select uid from main.frmlocust where eid=:eid and company_uid=CAST(:company_uid AS uuid)
+ """;
+ MapSqlParameterSource parameters = new MapSqlParameterSource();
+ parameters.addValue("eid", locust.eid, Types.BIGINT);
+ parameters.addValue("company_uid", locust.company_uid, Types.VARCHAR);
+ List