+
This commit is contained in:
@ -546,8 +546,8 @@ public class AcceptJSON implements ServletContextAware {
|
||||
locust.district = jsonObj.getString("townName");
|
||||
|
||||
if (!jsonObj.isNull("point")) {
|
||||
locust.lon = jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(0);
|
||||
locust.lat = jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(1);
|
||||
locust.lon_center = String.valueOf(jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(0));
|
||||
locust.lat_center = String.valueOf(jsonObj.getJSONObject("point").getJSONArray("coordinates").getDouble(1));
|
||||
}
|
||||
|
||||
//Контур зоны распространения ВО Polygon (geoJSON)
|
||||
@ -720,7 +720,7 @@ public class AcceptJSON implements ServletContextAware {
|
||||
for (Object o2 : jsonArraySub) {
|
||||
JSONObject jsonObjSub = (JSONObject) o2;
|
||||
|
||||
locust.eid = jsonObjSub.getInt("id");
|
||||
locust.eid = String.valueOf(jsonObjSub.getInt("id"));
|
||||
locust.phytoType = jsonObjSub.getString("phytoType"); //"Вредители" или "Обработка"
|
||||
if (locust.phytoType.equals("Обработка")) {
|
||||
locust.insecticide_name = jsonObjSub.getString("nameSubject"); //Наименование действующего вещества
|
||||
@ -852,9 +852,9 @@ public class AcceptJSON implements ServletContextAware {
|
||||
}
|
||||
|
||||
try {
|
||||
stmt.setLong(1, locust.eid);
|
||||
stmt.setDouble(2, locust.lat);
|
||||
stmt.setDouble(3, locust.lon);
|
||||
if (locust.eid == null) stmt.setNull(1, Types.INTEGER); else stmt.setLong(1, Long.parseLong(locust.eid));
|
||||
if (locust.lat_center == null) stmt.setNull(2, Types.DOUBLE); else stmt.setDouble(2, Double.parseDouble(locust.lat_center));
|
||||
if (locust.lon_center == null) stmt.setNull(3, Types.DOUBLE); else stmt.setDouble(3, Double.parseDouble(locust.lon_center));
|
||||
stmt.setInt(4, 7); //country_id
|
||||
stmt.setInt(5, Integer.parseInt(locust.region_id)); //region_id
|
||||
stmt.setString(6, locust.district); //Пишу в поле "area"
|
||||
@ -1017,7 +1017,7 @@ public class AcceptJSON implements ServletContextAware {
|
||||
}
|
||||
|
||||
//Если те виды что нам нужны
|
||||
if (regionName == null || regionName.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("Бахчевая коровка")) {
|
||||
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("Бахчевая коровка")) {
|
||||
|
||||
} else {
|
||||
|
||||
@ -1076,7 +1076,7 @@ public class AcceptJSON implements ServletContextAware {
|
||||
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>" + regionName + " = " + 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 += "<td>" + String.valueOf(cntO+cntV) + "</td><td>" + locust.eid + "</td><td>" + locust.lat_center + "</td><td>" + locust.lon_center + "</td><td>" + regionName + " = " + 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";
|
||||
|
||||
//Если записи не существует то вставляем если существует то обновляем
|
||||
@ -1183,9 +1183,9 @@ public class AcceptJSON implements ServletContextAware {
|
||||
}
|
||||
|
||||
try {
|
||||
stmt.setLong(1, locust.eid);
|
||||
stmt.setDouble(2, locust.lat);
|
||||
stmt.setDouble(3, locust.lon);
|
||||
stmt.setLong(1, Long.parseLong(locust.eid));
|
||||
stmt.setDouble(2, Double.parseDouble(locust.lat_center));
|
||||
stmt.setDouble(3, Double.parseDouble(locust.lon_center));
|
||||
stmt.setInt(4, 7);
|
||||
stmt.setInt(5, Integer.parseInt(locust.region_id));
|
||||
stmt.setString(6, locust.district); //Пишу в поле "area"
|
||||
@ -2377,9 +2377,9 @@ public class AcceptJSON implements ServletContextAware {
|
||||
FrmLocustModel result = new FrmLocustModel();
|
||||
|
||||
result.company_uid = "dc271f2e-1a4b-4987-96ec-7afd91350684"; //Компания: "Узбекистан саранча"
|
||||
result.eid = obj.getInt("id");
|
||||
result.eid = String.valueOf(obj.getInt("id"));
|
||||
result.seq = obj.getLong("seq")*1000;
|
||||
result.country_id = 10; //Uzbekistan
|
||||
result.country_id = "10"; //Uzbekistan
|
||||
result.country_uid = "05592f5a-1c8b-4d87-a47f-67697cc12c49"; //Uzbekistan
|
||||
|
||||
if(!obj.isNull("region_name")) {
|
||||
@ -2450,8 +2450,8 @@ public class AcceptJSON implements ServletContextAware {
|
||||
|
||||
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);
|
||||
result.lon_center = String.valueOf(obj.getJSONObject("point").getJSONArray("coordinates").getDouble(0));
|
||||
result.lat_center = String.valueOf(obj.getJSONObject("point").getJSONArray("coordinates").getDouble(1));
|
||||
}
|
||||
|
||||
//Биотоп
|
||||
|
||||
@ -2,6 +2,8 @@ package org.ccalm.main;
|
||||
|
||||
import org.ccalm.main.models.FrmLocustModel;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import tools.DBTools;
|
||||
@ -15,6 +17,8 @@ import java.util.List;
|
||||
|
||||
public class UpdateLocust {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UpdateLocust.class);
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
UpdateLocust(NamedParameterJdbcTemplate jdbcTemplate){
|
||||
@ -25,13 +29,14 @@ public class UpdateLocust {
|
||||
|
||||
String sql;
|
||||
boolean exists=false; //Is there a record.
|
||||
MapSqlParameterSource parameters;
|
||||
|
||||
//Если данные пришли из внешнего источника то проверяем по 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 = new MapSqlParameterSource();
|
||||
parameters.addValue("eid", locust.eid, Types.BIGINT);
|
||||
parameters.addValue("company_uid", locust.company_uid, Types.VARCHAR);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
@ -47,7 +52,7 @@ public class UpdateLocust {
|
||||
sql= """
|
||||
select uid from main.frmlocust where uid=CAST(:uid AS uuid);
|
||||
""";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("uid", locust.uid, Types.VARCHAR);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
for (String s : ret) {
|
||||
@ -264,7 +269,7 @@ public class UpdateLocust {
|
||||
)
|
||||
""";
|
||||
}
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("uid", locust.uid, Types.VARCHAR);
|
||||
|
||||
if(locust.user_id == null) { parameters.addValue("user_id", null, Types.BIGINT); } else { parameters.addValue("user_id", Long.parseLong(locust.user_id), Types.BIGINT); }
|
||||
@ -292,21 +297,21 @@ public class UpdateLocust {
|
||||
parameters.addValue("date", null, Types.DATE);
|
||||
}else
|
||||
{
|
||||
if(date.indexOf("-")==-1) //If old date format in UNIX time
|
||||
if(locust.date.indexOf("-")==-1) //If old date format in UNIX time
|
||||
{
|
||||
int uDate=Integer.parseInt(date)+1;
|
||||
int uDate=Integer.parseInt(locust.date)+1;
|
||||
java.sql.Timestamp tm=new java.sql.Timestamp((long)uDate*1000);
|
||||
stmt.setTimestamp(14, tm);
|
||||
parameters.addValue("date", locust.date, Types.DATE);
|
||||
}else
|
||||
{
|
||||
java.sql.Timestamp tm=null;
|
||||
DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //2016-05-29 18:00:01 in "GMT"
|
||||
try{
|
||||
tm = new java.sql.Timestamp(dfm.parse(date).getTime());
|
||||
tm = new java.sql.Timestamp(dfm.parse(locust.date).getTime());
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error",ex.getMessage());
|
||||
}
|
||||
stmt.setTimestamp(14, tm);
|
||||
parameters.addValue("date", locust.date, Types.DATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,9 +10,11 @@ public class FrmLocustModel {
|
||||
public String uid;
|
||||
public String eid; //Внешний идентификатор
|
||||
public long seq;
|
||||
public long country_id;
|
||||
public String country_id;
|
||||
public String country_uid;
|
||||
|
||||
public String user_id;
|
||||
|
||||
public String phytoType; //Вредители либо обработка
|
||||
public String observer;
|
||||
|
||||
@ -28,8 +30,9 @@ public class FrmLocustModel {
|
||||
public String region_id; //Область
|
||||
public String region_uid; //Область
|
||||
|
||||
public String area; //Rayon
|
||||
public String district; //Район
|
||||
public String district_id;
|
||||
public String district_id; //
|
||||
|
||||
public String terrain=""; //Название месности
|
||||
|
||||
@ -53,6 +56,7 @@ public class FrmLocustModel {
|
||||
public String drawPolygon="null"; //Область обследования GeoGSON
|
||||
public String size; //Заселённая площадь (polygonArea Площадь контура зоны распространения, в случае если специалист указал его)
|
||||
public String date; //Дата
|
||||
public String timezone;
|
||||
|
||||
public String description="";
|
||||
|
||||
@ -66,7 +70,7 @@ public class FrmLocustModel {
|
||||
public String larva_behavior = null; //Behaviour character varying(50) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
|
||||
public String larva_behavior_id = null; // integer,
|
||||
public String larva_behavior_uid = null; // integer,
|
||||
public String larva_density = null; //Hopper density numeric,
|
||||
public String larva_density = null; //Hopper density numeric, (Плотность личинок)
|
||||
public String larva_density_to = null; //Hopper density to numeric,
|
||||
|
||||
//Eggs
|
||||
@ -107,8 +111,6 @@ public class FrmLocustModel {
|
||||
public String imago_flying = null;
|
||||
|
||||
|
||||
public String larva_density=null; //Плотность личинок
|
||||
|
||||
public String bio_hectare=null; //Обследованная площадь
|
||||
public String bio_biotope_id=null; //Тип тиотопа
|
||||
public String bio_biotope_uid=null; //Тип тиотопа
|
||||
|
||||
Reference in New Issue
Block a user