Import mod

This commit is contained in:
2025-07-15 07:40:21 +05:00
parent 914b2aae03
commit 686109361f
4 changed files with 1126 additions and 1077 deletions

View File

@ -10,9 +10,9 @@ spring:
application: application:
name: org-ccalm-main name: org-ccalm-main
datasource: datasource:
url: jdbc:postgresql://almaty.ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000 #url: jdbc:postgresql://almaty.ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
#url: jdbc:postgresql://ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000 #url: jdbc:postgresql://ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
#url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000 url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
username: postgres username: postgres
password: 309A86FF65A78FB428F4E38DFE35F730 password: 309A86FF65A78FB428F4E38DFE35F730
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver

View File

@ -37,7 +37,6 @@ import com.zaxxer.hikari.HikariDataSource;
import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContext;
import org.ccalm.main.models.FrmLocustModel; import org.ccalm.main.models.FrmLocustModel;
import org.ccalm.main.utils.CustomException; import org.ccalm.main.utils.CustomException;
import org.ccalm.main.utils.LTools;
import org.json.JSONObject; import org.json.JSONObject;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -61,6 +60,9 @@ import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import tctable.Tools;
import tools.DBTools;
import tools.User;
//import com.google.common.io.CharStreams; //import com.google.common.io.CharStreams;
@ -69,9 +71,9 @@ import org.w3c.dom.NodeList;
//import sun.nio.cs.StandardCharsets; //import sun.nio.cs.StandardCharsets;
//import kz.locust.CCALM.AcceptEXCEL.Locust; //import kz.locust.CCALM.AcceptEXCEL.Locust;
//import kz.locust.CCALM.AcceptEXCEL.Locust; //import kz.locust.CCALM.AcceptEXCEL.Locust;
import tctable.Tools; //import tctable.Tools;
import tools.DBTools; //import tools.DBTools;
import tools.User; //import tools.User;
@Controller @Controller
//@SessionAttributes( { "user" }) //Сесионный объект //@SessionAttributes( { "user" }) //Сесионный объект
@ -124,11 +126,18 @@ public class AcceptJSON implements ServletContextAware {
*/ */
@ResponseBody @ResponseBody
@RequestMapping(value = {"/AcceptJSON_KAZ", "/api/locust/v01/AcceptJSON_KAZ"}, method = { RequestMethod.GET, RequestMethod.POST }) @RequestMapping(value = {"/AcceptJSON_KAZ", "/api/locust/v01/AcceptJSON_KAZ"}, method = { RequestMethod.GET, RequestMethod.POST })
public String acceptJSON_KAZ(@ModelAttribute User user, Model model,@RequestParam(required=false,name="file") MultipartFile file,@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip) { public String acceptJSON_KAZ(
@ModelAttribute User user,
Model model,
@RequestParam(required=false,name="file") MultipartFile file,
@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip
) {
int cnt=0;
try{
//TODO add user verification: that he is authorized and that he is an administrator! //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()) //if(user.id==null || user.id.equals("null") || user.id.isBlank())
return "Please log in!"; // return "Please log in!";
Connection conn = null; Connection conn = null;
try { try {
@ -147,6 +156,8 @@ public class AcceptJSON implements ServletContextAware {
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.connect(); hConn.connect();
int responseCode = hConn.getResponseCode(); int responseCode = hConn.getResponseCode();
if (responseCode / 100 == 2) //Code 206 is "Partial Content" if (responseCode / 100 == 2) //Code 206 is "Partial Content"
@ -167,8 +178,8 @@ public class AcceptJSON implements ServletContextAware {
String content=sb.toString(); String content=sb.toString();
int year=2024; int year=2025;
int cnt=0;
if(content==null || content.isEmpty()) { if(content==null || content.isEmpty()) {
System.out.println("Content is null"); System.out.println("Content is null");
@ -418,6 +429,15 @@ public class AcceptJSON implements ServletContextAware {
} }
System.out.println("Proc count = "+String.valueOf(cnt)); System.out.println("Proc count = "+String.valueOf(cnt));
} }
} catch (CustomException e) {
if(e.isSaveToLog()) {
String uuid = UUID.randomUUID().toString();
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
}
} catch (Exception ex) {
String uuid = UUID.randomUUID().toString();
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage(), ex);
}
return "Proc count = "+String.valueOf(cnt); return "Proc count = "+String.valueOf(cnt);
} }
@ -431,13 +451,13 @@ public class AcceptJSON implements ServletContextAware {
*/ */
@RequestMapping(value = {"/AcceptJSON_RUS", "/api/locust/v01/AcceptJSON_RUS"}, method = { RequestMethod.GET, RequestMethod.POST }) @RequestMapping(value = {"/AcceptJSON_RUS", "/api/locust/v01/AcceptJSON_RUS"}, method = { RequestMethod.GET, RequestMethod.POST })
public String acceptCSV(@ModelAttribute User user, Model model,@RequestParam(required=false,name="file") MultipartFile file,@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip) { public String acceptCSV(@ModelAttribute User user, Model model,@RequestParam(required=false,name="file") MultipartFile file,@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip) {
try{
Connection conn = null; Connection conn = null;
try { try {
Class.forName("org.postgresql.Driver"); Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password); conn = DriverManager.getConnection(db_url, db_login, db_password);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
//Set UTC time //Set UTC time
@ -447,11 +467,11 @@ public class AcceptJSON implements ServletContextAware {
try { try {
stm.execute("SET timezone TO 'UTC';"); stm.execute("SET timezone TO 'UTC';");
} catch( SQLException ex ) { } catch( SQLException ex ) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
stm.close(); stm.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
@ -459,8 +479,29 @@ public class AcceptJSON implements ServletContextAware {
String table="<table border=\"1\">"; String table="<table border=\"1\">";
table+="<tr style=\"background-color: #e0e0e0;\"><th>№</th><th>Ext id</th><th>Latitude (Широта)</th><th>Longitude (Долгота)</th><th>Oblast (область)</th><th>District (Район)</th><th>Сельский округ</th><th>Хозяйство или местность</th><th>Вид саранчи</th><th>Фаза</th><th>ЭПВ</th><th>Заселено Га</th><th>Дата</th></tr>"; table+="<tr style=\"background-color: #e0e0e0;\"><th>№</th><th>Ext id</th><th>Latitude (Широта)</th><th>Longitude (Долгота)</th><th>Oblast (область)</th><th>District (Район)</th><th>Сельский округ</th><th>Хозяйство или местность</th><th>Вид саранчи</th><th>Фаза</th><th>ЭПВ</th><th>Заселено Га</th><th>Дата</th></tr>";
//I select the maximum date, check that it is less than the current minus 2 days and try to load it
LocalDate lastDate = null;
String sql= """
select to_char(max(date), 'YYYY-MM-DD') as date from integration.days_ru
""";
MapSqlParameterSource parameters = new MapSqlParameterSource();
//parameters.addValue("user_id", claims.getBody().get("user_id"));
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-04-01");
Statement stt = null;
ResultSet rs = null;
//Выбираю максимальную дату проверяю что она меньше текущей минус 2 дня и пытаюсь загрузить её //Выбираю максимальную дату проверяю что она меньше текущей минус 2 дня и пытаюсь загрузить её
LocalDate lastDate = null;// = LocalDate.parse("2018-05-05"); /*LocalDate lastDate = null;
Statement stt = null; Statement stt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
@ -475,16 +516,16 @@ public class AcceptJSON implements ServletContextAware {
} }
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
}finally { }finally {
if(rs!=null) try{rs.close();}catch(SQLException ex){ ex.printStackTrace(); } if(rs!=null) try{rs.close();}catch(SQLException ex){ ex.printStackTrace(); }
if(stt!=null) try{stt.close();}catch(SQLException ex){ ex.printStackTrace(); } if(stt!=null) try{stt.close();}catch(SQLException ex){ ex.printStackTrace(); }
} }
if(lastDate==null) lastDate = LocalDate.parse("2024-01-10"); if(lastDate==null) lastDate = LocalDate.parse("2025-04-01");*/
//By number of day downloading data and write result of downloading to database, try or false, after repair need repeat download //By number of day downloading data and write result of downloading to database, try or false, after repair need repeat download
@ -519,9 +560,9 @@ public class AcceptJSON implements ServletContextAware {
} }
hConn.disconnect(); hConn.disconnect();
} }
catch (IOException e) catch (IOException ex)
{ {
e.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
String content=sb.toString(); String content=sb.toString();
if(content!=null && !content.isEmpty()) { if(content!=null && !content.isEmpty()) {
@ -565,7 +606,7 @@ public class AcceptJSON implements ServletContextAware {
//jsonObj.drawPolygon Краснодар //jsonObj.drawPolygon Краснодар
if (regionName.isEmpty()) { if (!regionName.isEmpty()) {
//Выбираю ID области //Выбираю ID области
locust.region_id = ""; locust.region_id = "";
//Statement stt = null; //Statement stt = null;
@ -582,21 +623,21 @@ public class AcceptJSON implements ServletContextAware {
} }
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} finally { } finally {
if (rs != null) try { if (rs != null) try {
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
if (stt != null) try { if (stt != null) try {
stt.close(); stt.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
@ -683,6 +724,10 @@ public class AcceptJSON implements ServletContextAware {
locust.district = "Сорочинский городской округ"; locust.district = "Сорочинский городской округ";
if (locust.district.equals("Ясненский район")) if (locust.district.equals("Ясненский район"))
locust.district = "Ясненский городской округ"; locust.district = "Ясненский городской округ";
if (locust.district.equals("Белогорский муниципальный округ")) {
locust.district = "городской округ Белгород";
locust.region_id = "69";
}
stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); 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 + "%';"; String sql_query = "select id from main.countriesdistricts where region_id=" + locust.region_id + " and name like '%" + locust.district + "%';";
@ -694,24 +739,26 @@ public class AcceptJSON implements ServletContextAware {
} }
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} finally { } finally {
if (rs != null) try { if (rs != null) try {
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
if (stt != null) try { if (stt != null) try {
stt.close(); stt.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
} }
}else{
throw new CustomException(200, 10000, "regionName.isEmpty()",null,true);
} }
String row = ""; String row = "";
@ -744,7 +791,7 @@ public class AcceptJSON implements ServletContextAware {
} }
if (locust.spray_platform == null || locust.spray_platform.isEmpty()) { if (locust.spray_platform == null || locust.spray_platform.isEmpty()) {
model.addAttribute("PreviewTable", "Error spray_platform"); model.addAttribute("PreviewTable", "Error spray_platform");
return "json"; throw new CustomException(200, 10000, "Error spray_platform",null,true);
} }
} }
@ -762,12 +809,12 @@ public class AcceptJSON implements ServletContextAware {
st = conn.createStatement(); st = conn.createStatement();
//ResultSet rs=null; //ResultSet rs=null;
try { try {
String sql = "select 1 from main.frmlocustdel where eid=" + String.valueOf(locust.eid); sql = "select 1 from main.frmlocustdel where eid=" + String.valueOf(locust.eid);
rs = st.executeQuery(sql); rs = st.executeQuery(sql);
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error select"); model.addAttribute("PreviewTable", "Error select");
return "json"; throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
if (rs != null) { if (rs != null) {
if (rs.next()) if (rs.next())
@ -777,11 +824,11 @@ public class AcceptJSON implements ServletContextAware {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error select 2"); model.addAttribute("PreviewTable", "Error select 2");
return "json"; throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
PreparedStatement stmt = null; PreparedStatement stmt = null;
String sql = ""; sql = "";
if (exists) { if (exists) {
System.out.println(String.valueOf(cntV)+") update main.frmlocustdel"); System.out.println(String.valueOf(cntV)+") update main.frmlocustdel");
sql = "update main.frmlocustdel set\n" sql = "update main.frmlocustdel set\n"
@ -806,7 +853,7 @@ public class AcceptJSON implements ServletContextAware {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error prepare 1"); model.addAttribute("PreviewTable", "Error prepare 1");
return "json"; throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} else { } else {
System.out.println(String.valueOf(cntV)+") insert into main.frmlocustdel"); System.out.println(String.valueOf(cntV)+") insert into main.frmlocustdel");
@ -849,7 +896,7 @@ public class AcceptJSON implements ServletContextAware {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error prepare 2"); model.addAttribute("PreviewTable", "Error prepare 2");
return "json"; throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
@ -880,7 +927,8 @@ public class AcceptJSON implements ServletContextAware {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error set data"); model.addAttribute("PreviewTable", "Error set data");
return "json";
throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
//Выпоняю запрос на свтавку либо обновление //Выпоняю запрос на свтавку либо обновление
@ -889,44 +937,36 @@ public class AcceptJSON implements ServletContextAware {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
model.addAttribute("PreviewTable", "Error execute frmlocustdel"); model.addAttribute("PreviewTable", "Error execute frmlocustdel");
return "json";
throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
cntO++; cntO++;
} else if (locust.phytoType.equals("Вредители")) { } else if (locust.phytoType.equals("Вредители")) {
if (!jsonObjSub.isNull("nameSubject"))
locust.locust = jsonObjSub.getString("nameSubject");
//Вид саранчи //Вид саранчи
locust.locust_type_id = ""; locust.locust_type_id = "";
if (locust.locust.equals("Короткокрылый зеленчук")) locust.locust_type_id = "4";
if (locust.locust.equals("Среднерусская перелётная саранча")) locust.locust_type_id = "4"; if(!jsonObjSub.isNull("nameSubject") && !jsonObjSub.optString("nameSubject","").isBlank()) {
if (locust.locust.equals("Сибирская кобылка")) locust.locust_type_id = "4"; locust.locust = jsonObjSub.getString("nameSubject");
if (locust.locust.equals("Кобылка изменчивая")) locust.locust_type_id = "4"; switch (jsonObjSub.optString("nameSubject",null).replace("'", "").trim()) {
if (locust.locust.equals("Кобылка пёстрая")) locust.locust_type_id = "4"; case "Короткокрылый зеленчук", "Среднерусская перелётная саранча", "Сибирская кобылка", "Кобылка изменчивая", "Кобылка пёстрая", "Кобылка крестовая", "Кобылка сибирская", "Кобылка голубокрылая", "Кобылка бескрылая", "Кобылка чернополосая", "Кобылка трескучая", "Кобылка египетская", "Трещотка ширококрылая", "Бахчевая кобылка", "Малая крестовичка", "Конёк белополосый (белополосая кобылка)", "Конек обыкновенный", "Конек обыкновенный", "Кобылка темнокрылая", "Краснокрылая кобылка", "Краснокрылая кобылка", "Степная кобылка", "Гребневка":
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"; locust.locust_type_id = "4";
if (locust.locust.equals("Конек обыкновенный")) locust.locust_type_id = "4"; break;
if (locust.locust.equals("Конек обыкновенный")) locust.locust_type_id = "4"; case "Азиатская перелётная саранча":
if (locust.locust.equals("Кобылка темнокрылая")) locust.locust_type_id = "4"; locust.locust_type_id = "3";
if (locust.locust.equals("Краснокрылая кобылка")) locust.locust_type_id = "4"; break;
if (locust.locust.equals("Краснокрылая кобылка")) locust.locust_type_id = "4"; case "Итальянский прус":
if (locust.locust.equals("Степная кобылка")) locust.locust_type_id = "4"; locust.locust_type_id = "1";
if (locust.locust.equals("Гребневка")) locust.locust_type_id = "4"; break;
if (locust.locust.equals("Азиатская перелётная саранча")) locust.locust_type_id = "3"; case "Мароккская саранча, мароккская кобылка, марокканка":
if (locust.locust.equals("Итальянский прус")) locust.locust_type_id = "1";
if (locust.locust.equals("Мароккская саранча, мароккская кобылка, марокканка"))
locust.locust_type_id = "2"; locust.locust_type_id = "2";
break;
default:
throw new CustomException(200, 10000, "Not find swarms_height: (" + locust.locust+")", null, true);
}
}else{
throw new CustomException(200, 10000, "Field nameSubject is null", null, true);
}
//фаза саранчи //фаза саранчи
if (!jsonObjSub.isNull("phaseEvolutionName")) if (!jsonObjSub.isNull("phaseEvolutionName"))
@ -942,6 +982,9 @@ public class AcceptJSON implements ServletContextAware {
if (locust.phase.equals("Личинка 5-го возраста")) locust.locust_have = "3"; if (locust.phase.equals("Личинка 5-го возраста")) locust.locust_have = "3";
if (locust.phase.equals("Имаго")) locust.locust_have = "5"; if (locust.phase.equals("Имаго")) locust.locust_have = "5";
} }
//Если эта анкета "Имаго" то записываем плотность имаго на m2 //Если эта анкета "Имаго" то записываем плотность имаго на m2
if (locust.locust_have.equals("5")) { if (locust.locust_have.equals("5")) {
if (!jsonObjSub.isNull("subPestCount")) if (!jsonObjSub.isNull("subPestCount"))
@ -1019,21 +1062,19 @@ public class AcceptJSON implements ServletContextAware {
} }
//Если те виды что нам нужны //Если те виды что нам нужны
if (regionName == null || regionName.isEmpty() || Double.parseDouble(locust.lat_center) == 0 || Double.parseDouble(locust.lon_center) == 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("Бахчевая коровка")) { if (regionName == null || regionName.isEmpty() || locust.lat_center == null || Double.parseDouble(locust.lat_center) == 0 || locust.lon_center == null || Double.parseDouble(locust.lon_center) == 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 { } else {
if (locust.locust_type_id.isEmpty()) { if (locust.locust_type_id.isEmpty()) {
System.out.println("locust.locust = "+locust.locust); System.out.println("locust.locust = "+locust.locust);
model.addAttribute("PreviewTable", "locust.locust_type_id == 0 locust name = " + locust.locust); model.addAttribute("PreviewTable", "locust.locust_type_id == 0 locust name = " + locust.locust);
logger.error("Error, not find locust.locust = "+locust.locust); throw new CustomException(200, 10000, "Error, not find locust.locust = "+locust.locust,null,true);
return "json";
} }
if (locust.region_id.isEmpty()) { if (locust.region_id.isEmpty()) {
System.out.println("locust.region = "+regionName); System.out.println("locust.region = "+regionName);
model.addAttribute("PreviewTable", "locust.region_id == 0 region name = " + regionName); model.addAttribute("PreviewTable", "locust.region_id == 0 region name = " + regionName);
logger.error("Error, not find locust.region = "+regionName); throw new CustomException(200, 10000, "Error, not find locust.region = "+regionName,null,true);
return "json";
} }
//Тех полей что нет в анкете вствляю в комментарии //Тех полей что нет в анкете вствляю в комментарии
@ -1088,7 +1129,7 @@ public class AcceptJSON implements ServletContextAware {
st = conn.createStatement(); st = conn.createStatement();
//ResultSet rs=null; //ResultSet rs=null;
try { try {
String sql = "select 1 from main.frmlocust where eid=" + String.valueOf(locust.eid); sql = "select 1 from main.frmlocust where eid=" + String.valueOf(locust.eid);
rs = st.executeQuery(sql); rs = st.executeQuery(sql);
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -1107,7 +1148,7 @@ public class AcceptJSON implements ServletContextAware {
} }
PreparedStatement stmt = null; PreparedStatement stmt = null;
String sql = ""; sql = "";
if (exists) { if (exists) {
System.out.println(String.valueOf(cntV)+") update main.frmlocust"); System.out.println(String.valueOf(cntV)+") update main.frmlocust");
sql = "update main.frmlocust set\n" sql = "update main.frmlocust set\n"
@ -1385,9 +1426,8 @@ public class AcceptJSON implements ServletContextAware {
st.execute("insert into integration.days_ru(date,count)values('" + lastDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'," + String.valueOf(cntV+cntO) + ");"); st.execute("insert into integration.days_ru(date,count)values('" + lastDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'," + String.valueOf(cntV+cntO) + ");");
st.close(); st.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace();
model.addAttribute("PreviewTable", "Error update img"); model.addAttribute("PreviewTable", "Error update img");
return "json"; throw new CustomException(200, 10000, ex.getMessage(),null,true);
} }
} }
} }
@ -1395,6 +1435,15 @@ public class AcceptJSON implements ServletContextAware {
//model.addAttribute("PreviewGEOJSON",json); //model.addAttribute("PreviewGEOJSON",json);
model.addAttribute("PreviewSQL",sqlData); model.addAttribute("PreviewSQL",sqlData);
} catch (CustomException e) {
if(e.isSaveToLog()) {
String uuid = UUID.randomUUID().toString();
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
}
} catch (Exception ex) {
String uuid = UUID.randomUUID().toString();
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage(), ex);
}
return "json"; return "json";
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -1837,7 +1886,7 @@ public class AcceptJSON implements ServletContextAware {
result.larva_born = null; // not used result.larva_born = null; // not used
if(!obj.isNull("hoppers_hatching") && !obj.optString("hoppers_hatching","").isBlank()){ if(!obj.isNull("hoppers_hatching") && !obj.optString("hoppers_hatching","").isBlank()){
switch (obj.optString("hoppers_hatching",null).replace("'", "").trim().trim()) { switch (obj.optString("hoppers_hatching",null).replace("'", "").trim()) {
case "Beginning", "Начало": case "Beginning", "Начало":
result.larva_born_id="1"; result.larva_born_id="1";
result.larva_born_uid="392db9f2-bfaa-44e0-8ca3-bb3cf1ff937a"; result.larva_born_uid="392db9f2-bfaa-44e0-8ca3-bb3cf1ff937a";

View File

@ -2,7 +2,7 @@ package org.ccalm.main.models;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.ccalm.main.utils.CustomException; //import org.ccalm.main.utils.CustomException;
import java.sql.Types; import java.sql.Types;

View File

@ -306,10 +306,10 @@
<!-- Language Selector --> <!-- Language Selector -->
<div class="language-selector"> <div class="language-selector">
<button id="lang-en" class="language-button active" onclick="switchLanguage('en')"> <button id="lang-en" class="language-button active" onclick="switchLanguage('en')">
🇬🇧 English English
</button> </button>
<button id="lang-ru" class="language-button" onclick="switchLanguage('ru')"> <button id="lang-ru" class="language-button" onclick="switchLanguage('ru')">
🇷🇺 Русский Русский
</button> </button>
</div> </div>