Объединение
This commit is contained in:
@ -1707,7 +1707,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
String imgDir="./data/frmlocust/";
|
||||
try{ new File(dataDir+imgDir).mkdirs(); }catch (Exception exception) {}
|
||||
|
||||
if(image_name1!=null && !image_name1.equals(""))
|
||||
if(image_name1!=null && !image_name1.isEmpty())
|
||||
{
|
||||
String filename1=dataDir+tmpDir+image_name1;
|
||||
File f = new File(filename1);
|
||||
@ -1715,7 +1715,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
f.renameTo(new File(dataDir+imgDir+image_name1));
|
||||
}
|
||||
}
|
||||
if(image_name2!=null && !image_name2.equals(""))
|
||||
if(image_name2!=null && !image_name2.isEmpty())
|
||||
{
|
||||
String filename2=dataDir+tmpDir+image_name2;
|
||||
File f = new File(filename2);
|
||||
@ -1723,7 +1723,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
f.renameTo(new File(dataDir+imgDir+image_name2));
|
||||
}
|
||||
}
|
||||
if(image_name3!=null && !image_name3.equals(""))
|
||||
if(image_name3!=null && !image_name3.isEmpty())
|
||||
{
|
||||
String filename3=dataDir+tmpDir+image_name3;
|
||||
File f = new File(filename3);
|
||||
@ -2453,7 +2453,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
//If there are drawings, then copy them.
|
||||
String imgDir="./data/frmlocustdel/";
|
||||
try{ new File(dataDir+imgDir).mkdirs(); }catch (Exception exception) {}
|
||||
if(image_name1!=null && !image_name1.equals(""))
|
||||
if(image_name1!=null && !image_name1.isEmpty())
|
||||
{
|
||||
String filename1=dataDir+tmpDir+image_name1;
|
||||
File f = new File(filename1);
|
||||
@ -2461,7 +2461,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
f.renameTo(new File(dataDir+imgDir+image_name1));
|
||||
}
|
||||
}
|
||||
if(image_name2!=null && !image_name2.equals(""))
|
||||
if(image_name2!=null && !image_name2.isEmpty())
|
||||
{
|
||||
String filename2=dataDir+tmpDir+image_name2;
|
||||
File f = new File(filename2);
|
||||
@ -2469,7 +2469,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
f.renameTo(new File(dataDir+imgDir+image_name2));
|
||||
}
|
||||
}
|
||||
if(image_name3!=null && !image_name3.equals(""))
|
||||
if(image_name3!=null && !image_name3.isEmpty())
|
||||
{
|
||||
String filename3=dataDir+tmpDir+image_name3;
|
||||
File f = new File(filename3);
|
||||
@ -2859,7 +2859,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
|
||||
//Проверка на существование полей в обеих таблицах
|
||||
ExistsType[] fb=new ExistsType[tbl.fields.size()];
|
||||
Map<String, String> col = TCTableTools.getTableSchema(conn, "main" + tbl.name);
|
||||
Map<String, String> col = TCTableTools.getTableSchema(conn, "main."+tbl.name);
|
||||
for(int i=0;i<tbl.fields.size();i++)
|
||||
{
|
||||
fb[i] = new ExistsType();
|
||||
@ -3252,7 +3252,7 @@ public class AcceptASDCController implements ServletContextAware {
|
||||
}
|
||||
nextnode = nextnode.getNextSibling();
|
||||
}
|
||||
if(result.equals("") || result.equals("null"))
|
||||
if(result.isEmpty() || result.equals("null"))
|
||||
return null;
|
||||
else
|
||||
return result;
|
||||
|
||||
@ -312,7 +312,7 @@ public class AcceptEXCEL implements ServletContextAware {
|
||||
locust.date=CutBeforeFirst(data,";"); //Дата
|
||||
|
||||
String row="<tr>";
|
||||
if(error==true || locust.lat==0 || locust.lon==0 || locust.region_id.equals("") || locust.district_id.equals("") || locust.terrain.equals("") || locust.locust_id.equals("")) {
|
||||
if(error==true || locust.lat==0 || locust.lon==0 || locust.region_id.isEmpty() || locust.district_id.isEmpty() || locust.terrain.isEmpty() || locust.locust_id.isEmpty()) {
|
||||
row="<tr style=\"background-color:red;\">";
|
||||
}
|
||||
row+="<td>"+i+"</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_id+"</td><td>"+locust.phase+" = "+locust.locust_have+"</td><td>"+locust.evp+"</td><td>"+locust.size+"</td><td>"+locust.date+"</td>";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -109,7 +109,7 @@ public class DataJSON implements ServletContextAware {
|
||||
sql_query = "select id,name from main.companies where del=false and name is not null and name!='' and (${country_id} is null or country_id=${country_id})";
|
||||
|
||||
PreparedStatementNamed stmtn = new PreparedStatementNamed(conn, sql_query);
|
||||
if(country_id==null || country_id.equals(""))
|
||||
if(country_id==null || country_id.isEmpty())
|
||||
stmtn.setNULLInt("country_id");
|
||||
else
|
||||
stmtn.setInt("country_id",Integer.parseInt(country_id));
|
||||
|
||||
@ -145,7 +145,7 @@ public class DownloadNDVI implements ServletContextAware {
|
||||
logger.info(ex.getMessage());
|
||||
result+=ex.getMessage()+"<br>";
|
||||
}
|
||||
if(!strPos1.equals(""))
|
||||
if(!strPos1.isEmpty())
|
||||
{
|
||||
//String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:"
|
||||
StringBuffer answer1=new StringBuffer(strPos1);
|
||||
@ -155,7 +155,7 @@ public class DownloadNDVI implements ServletContextAware {
|
||||
StringBuffer answer2=new StringBuffer(strPos2);
|
||||
CutBeforeFirst(answer2,":");
|
||||
String posEnd = CutBeforeFirst(answer2,":");
|
||||
if(posEnd==null || posEnd.equals("")) posEnd=""; else
|
||||
if(posEnd==null || posEnd.isEmpty()) posEnd=""; else
|
||||
{
|
||||
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
|
||||
}
|
||||
@ -275,7 +275,7 @@ public class DownloadNDVI implements ServletContextAware {
|
||||
logger.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||
if(country_id!=null && !country_id.isEmpty() && !country_id.equals("null"))
|
||||
{
|
||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||
try {
|
||||
|
||||
@ -91,7 +91,7 @@ public class DownloadWeather implements ServletContextAware {
|
||||
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
|
||||
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000
|
||||
//Example request: http://127.0.0.1:8080/CCALM/DownloadWeather?forecast=000
|
||||
if(date==null || date.equals(""))
|
||||
if(date==null || date.isEmpty())
|
||||
{
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
date=dateFormat.format(new Date()); //Date like as "20170327".
|
||||
@ -138,7 +138,7 @@ public class DownloadWeather implements ServletContextAware {
|
||||
logger.info(ex.getMessage());
|
||||
result+=ex.getMessage()+"<br>";
|
||||
}
|
||||
if(!strPos1.equals(""))
|
||||
if(!strPos1.isEmpty())
|
||||
{
|
||||
//String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:"
|
||||
StringBuffer answer1=new StringBuffer(strPos1);
|
||||
@ -148,7 +148,7 @@ public class DownloadWeather implements ServletContextAware {
|
||||
StringBuffer answer2=new StringBuffer(strPos2);
|
||||
CutBeforeFirst(answer2,":");
|
||||
String posEnd = CutBeforeFirst(answer2,":");
|
||||
if(posEnd==null || posEnd.equals("")) posEnd=""; else
|
||||
if(posEnd==null || posEnd.isEmpty()) posEnd=""; else
|
||||
{
|
||||
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
|
||||
}
|
||||
@ -268,7 +268,7 @@ public class DownloadWeather implements ServletContextAware {
|
||||
logger.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||
if(country_id!=null && !country_id.isEmpty() && !country_id.equals("null"))
|
||||
{
|
||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||
try {
|
||||
|
||||
@ -70,7 +70,7 @@ public class QGIS implements ServletContextAware {
|
||||
@ResponseBody
|
||||
public HttpEntity<byte[]> ajaxTamer(@ModelAttribute User user, @RequestParam(required=false,name="day") String day, @RequestParam(required=false,name="name") String name, @RequestParam(required=false,name="time") String time, @RequestParam(required=false,name="time_start") String time_start, @RequestParam(required=false,name="time_end") String time_end, @RequestParam(required=false,name="country_id") String country_id, @RequestParam(required=false,name="locust_type_id") String locust_type_id, @RequestParam(required=false,name="date_start") String date_start, @RequestParam(required=false,name="date_end") String date_end, @RequestParam(required=false,name="registered") String registered, @RequestParam(required=false,name="year") String year, @RequestParam(required=false,name="region_id") String region_id, @RequestParam(required=false,name="country_name") String country_name, @RequestParam(required=false,name="lng") String language_id, HttpServletResponse response)
|
||||
{
|
||||
if(language_id!=null && !language_id.equals("")) user.language_id=language_id;
|
||||
if(language_id!=null && !language_id.isEmpty()) user.language_id=language_id;
|
||||
logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id);
|
||||
m_locale=user.language_id;
|
||||
|
||||
@ -107,7 +107,7 @@ public class QGIS implements ServletContextAware {
|
||||
//Make SQL
|
||||
String sql = "1=1";
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -123,15 +123,15 @@ public class QGIS implements ServletContextAware {
|
||||
sql2+=" and country_id="+country_id;
|
||||
}
|
||||
}
|
||||
if(locust_type_id!=null && !locust_type_id.equals(""))
|
||||
if(locust_type_id!=null && !locust_type_id.isEmpty())
|
||||
{
|
||||
sql+=" and locust_type_id="+locust_type_id;
|
||||
}
|
||||
if(date_start!=null && !date_start.equals(""))
|
||||
if(date_start!=null && !date_start.isEmpty())
|
||||
{
|
||||
sql+=" and date>='"+date_start+"'";
|
||||
}
|
||||
if(date_end!=null && !date_end.equals(""))
|
||||
if(date_end!=null && !date_end.isEmpty())
|
||||
{
|
||||
sql+=" and date<='"+date_end+"'";
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class QGIS implements ServletContextAware {
|
||||
//Make SQL
|
||||
String sql = "1=1";
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
//sql+=" and country_id="+country_id;
|
||||
if(country_id.equals("-1"))
|
||||
@ -181,11 +181,11 @@ public class QGIS implements ServletContextAware {
|
||||
sql2+=" and country_id="+country_id;
|
||||
}
|
||||
}
|
||||
if(date_start!=null && !date_start.equals(""))
|
||||
if(date_start!=null && !date_start.isEmpty())
|
||||
{
|
||||
sql+=" and date>='"+date_start+"'";
|
||||
}
|
||||
if(date_end!=null && !date_end.equals(""))
|
||||
if(date_end!=null && !date_end.isEmpty())
|
||||
{
|
||||
sql+=" and date<='"+date_end+"'";
|
||||
}
|
||||
@ -213,7 +213,7 @@ public class QGIS implements ServletContextAware {
|
||||
|
||||
//Make SQL
|
||||
String sql = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -226,7 +226,7 @@ public class QGIS implements ServletContextAware {
|
||||
sql+=" and country_id="+country_id;
|
||||
}
|
||||
}
|
||||
if(locust_type_id!=null && !locust_type_id.equals(""))
|
||||
if(locust_type_id!=null && !locust_type_id.isEmpty())
|
||||
{
|
||||
sql+=" and locust_type_id="+locust_type_id;
|
||||
}
|
||||
@ -245,11 +245,11 @@ public class QGIS implements ServletContextAware {
|
||||
|
||||
//Make SQL
|
||||
String sql = "1=1";
|
||||
if(region_id!=null && !region_id.equals(""))
|
||||
if(region_id!=null && !region_id.isEmpty())
|
||||
{
|
||||
sql+=" and region_id="+region_id;
|
||||
}
|
||||
if(locust_type_id!=null && !locust_type_id.equals(""))
|
||||
if(locust_type_id!=null && !locust_type_id.isEmpty())
|
||||
{
|
||||
sql+=" and locust_type_id="+locust_type_id;
|
||||
}
|
||||
@ -263,7 +263,7 @@ public class QGIS implements ServletContextAware {
|
||||
{
|
||||
//Make SQL
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -287,7 +287,7 @@ public class QGIS implements ServletContextAware {
|
||||
{
|
||||
//Make SQL
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -311,7 +311,7 @@ public class QGIS implements ServletContextAware {
|
||||
{
|
||||
//Make SQL
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -335,7 +335,7 @@ public class QGIS implements ServletContextAware {
|
||||
{
|
||||
//Make SQL
|
||||
String sql2 = "1=1";
|
||||
if(country_id!=null && !country_id.equals(""))
|
||||
if(country_id!=null && !country_id.isEmpty())
|
||||
{
|
||||
if(country_id.equals("-1"))
|
||||
{
|
||||
@ -457,7 +457,7 @@ public class QGIS implements ServletContextAware {
|
||||
if(st!=null) try{st.close();}catch(SQLException ex) {}
|
||||
if(rs!=null) try{rs.close();}catch(SQLException ex) {}
|
||||
}
|
||||
if(result.equals(""))
|
||||
if(result.isEmpty())
|
||||
{
|
||||
result = Tools.replaceAll(key,"_", " ");
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public class SendMail implements ServletContextAware {
|
||||
public Object send(@ModelAttribute User user,@RequestParam(required=false,name="lng") String language_id) {
|
||||
|
||||
m_user = user;
|
||||
if(language_id!=null && !language_id.equals(""))
|
||||
if(language_id!=null && !language_id.isEmpty())
|
||||
user.language_id=language_id;
|
||||
logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id+" user.country_id="+user.country_id);
|
||||
|
||||
@ -445,7 +445,7 @@ public class SendMail implements ServletContextAware {
|
||||
if(rs!=null) try{rs.close();}catch(SQLException ex) {}
|
||||
}
|
||||
}
|
||||
if(result.equals(""))
|
||||
if(result.isEmpty())
|
||||
{
|
||||
result = key.replaceAll("_", " ");
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import jakarta.servlet.ServletContext;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
@ -11,9 +12,15 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import tools.DBTools;
|
||||
import tools.EmailUtility;
|
||||
import tools.Translation;
|
||||
import tools.User;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@ -21,6 +28,15 @@ import java.util.*;
|
||||
public class SendWarning {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SendWarning.class);
|
||||
|
||||
@Value("${mail.host}")
|
||||
String mail_host = "";
|
||||
@Value("${mail.port}")
|
||||
String mail_port = "";
|
||||
@Value("${mail.login}")
|
||||
String mail_login = "";
|
||||
@Value("${mail.password}")
|
||||
String mail_password = "";
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
@ -43,8 +59,7 @@ public class SendWarning {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(request, headers);
|
||||
//String url = "https://geoserver2.ccalm.org/geodatalist/getAirTemperature";
|
||||
String url = "https://geoserver.ccalm.org/geodatalist/getAirTemperature";
|
||||
String url = "https://geoserver2.ccalm.org/geodatalist/getAirTemperature";
|
||||
try {
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class);
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
||||
@ -63,23 +78,30 @@ public class SendWarning {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/api/main/v01/SendWarning",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||
@RequestMapping(value = "/api/main/v01/SendWarning",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public ResponseEntity<Object> send(@ModelAttribute User user, @RequestParam(required=false,name="lng") String language_id) {
|
||||
public ResponseEntity<Object> send() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("error_code", 0);
|
||||
|
||||
try {
|
||||
String sql = """
|
||||
select
|
||||
t.uid,
|
||||
t.user_uid,
|
||||
t.lat,
|
||||
t.lon,
|
||||
t.temperature
|
||||
t.temperature as value,
|
||||
u.email,
|
||||
l.short_name
|
||||
from
|
||||
main.frmcheckpoints t
|
||||
join main._users u on u.uid=t.user_uid
|
||||
join main._languages l on l.uid=u.language_uid
|
||||
where
|
||||
t.del=false
|
||||
and t.warn=true
|
||||
""";
|
||||
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
//parameters.addValue("language_id", language_id, Types.INTEGER);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
@ -87,14 +109,68 @@ public class SendWarning {
|
||||
JSONObject obj = new JSONObject(jsonString);
|
||||
JSONObject tmp = getSoilTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
||||
if(tmp!=null) {
|
||||
double temperature = obj.getDouble("temperature");
|
||||
if (temperature < tmp.getDouble("val")) {
|
||||
System.out.println(tmp.getDouble("val"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Translation trt=new Translation(obj.getString("short_name"),jdbcTemplate);
|
||||
double value = obj.getDouble("value");
|
||||
if (value < tmp.getDouble("value")) {
|
||||
String email = obj.getString("email");
|
||||
if(email.equals("irigm@mail.ru") || email.equals("ivanov.i@istt.kz")){ //TODO для тестирования потом удалить
|
||||
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<html>")
|
||||
.append("<head>")
|
||||
.append("<style>")
|
||||
.append("body { font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; margin: 0; padding: 0; }")
|
||||
.append(".container { max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border: 1px solid #ddd; position: relative; }")
|
||||
.append(".logo { position: absolute; top: 10px; right: 10px; width: 100px; height: auto; }")
|
||||
.append("h2 { color: #d9534f; margin-top: 50px; }") // Отступ для логотипа
|
||||
.append("table { border-collapse: collapse; width: 100%; margin: 20px 0; }")
|
||||
.append("th, td { padding: 10px; border: 1px solid #ddd; text-align: left; }")
|
||||
.append("th { background-color: #f9f9f9; }")
|
||||
.append("p { font-weight: bold; }")
|
||||
.append("</style>")
|
||||
.append("</head>")
|
||||
.append("<body>")
|
||||
.append("<div class='container'>")
|
||||
.append("<img src='https://ccalm.org/resources/images/locust.png' alt='Logo' class='logo'>") // Логотип
|
||||
.append("<h2>").append(trt.trt("Warning")).append("</h2>")
|
||||
.append("<p>").append(trt.trt("The_soil_temperature_has_exceeded_the_set_value")).append(": ").append(value).append("</p>")
|
||||
.append("<table>")
|
||||
.append("<tr><th>").append(trt.trt("Date")).append("</th><td>").append(tmp.getString("date")).append("</td></tr>")
|
||||
.append("<tr><th>").append(trt.trt("Value")).append("</th><td>").append(tmp.getDouble("value")).append(" °C</td></tr>")
|
||||
.append("</table>")
|
||||
.append(trt.trt("To_resume_monitoring_please_set_the_warn_field_to_true"))
|
||||
.append("</div>") // Закрываем контейнер
|
||||
.append("</body>")
|
||||
.append("</html>");
|
||||
|
||||
boolean send = false;
|
||||
try {
|
||||
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, email, trt.trt("Soil temperature"), html.toString());
|
||||
send = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(send) {
|
||||
sql= """
|
||||
update
|
||||
main.frmcheckpoints
|
||||
set
|
||||
warn=true
|
||||
where uid=:uid
|
||||
""";
|
||||
MapSqlParameterSource param = new MapSqlParameterSource();
|
||||
param.addValue("uid", obj.getString("uid"), Types.INTEGER);
|
||||
int rowsUpdated = jdbcTemplate.update(sql, param);
|
||||
System.out.println("rowsUpdated = "+String.valueOf(rowsUpdated));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
logger.error(uuid,e);
|
||||
}
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public class SessionController {
|
||||
|
||||
//response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
|
||||
JSONObject obj = new JSONObject();
|
||||
if(user.id==null || user.id.equals("") || user.id.equals("null"))
|
||||
if(user.id==null || user.id.isEmpty() || user.id.equals("null"))
|
||||
obj.put("result", "ERROR");
|
||||
else {
|
||||
obj.put("result", "OK");
|
||||
|
||||
@ -33,7 +33,7 @@ public class TranslationUtils {
|
||||
JSONObject obj = new JSONObject(jsonString);
|
||||
String key = obj.getString("identifier");
|
||||
String val = obj.getString("translation");
|
||||
if (val.equals("")) {
|
||||
if (val.isEmpty()) {
|
||||
val = val.replaceAll("_", " ");
|
||||
}
|
||||
model.addAttribute(key, val);
|
||||
|
||||
@ -108,7 +108,7 @@ public class EngineController implements ServletContextAware {
|
||||
return "redirect";
|
||||
}
|
||||
|
||||
//if(language_id!=null && !language_id.equals("")) user.language_id=language_id;
|
||||
//if(language_id!=null && !language_id.isEmpty()) user.language_id=language_id;
|
||||
//logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id);
|
||||
|
||||
long country_id=0;
|
||||
@ -153,10 +153,10 @@ public class EngineController implements ServletContextAware {
|
||||
String key = (String)k;
|
||||
String val="";
|
||||
//val = trt(conn,key,user); //Если есть то перевод беру из базы данных
|
||||
if(val.equals(""))
|
||||
if(val.isEmpty())
|
||||
{
|
||||
val = props.getProperty(key,"");
|
||||
if(val.equals(""))
|
||||
if(val.isEmpty())
|
||||
{
|
||||
val = val.replaceAll("_", " ");
|
||||
}
|
||||
@ -464,7 +464,7 @@ public class EngineController implements ServletContextAware {
|
||||
public String trt(Connection conn,String key,User user)
|
||||
{
|
||||
String result="";
|
||||
if(key.equals(""))
|
||||
if(key.isEmpty())
|
||||
return result;
|
||||
|
||||
try {
|
||||
@ -485,7 +485,7 @@ public class EngineController implements ServletContextAware {
|
||||
logger.info(ex.getMessage());
|
||||
}
|
||||
|
||||
if(result.equals(""))
|
||||
if(result.isEmpty())
|
||||
{
|
||||
result = key.replaceAll("_", " ");
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class PreparedStatementNamed {
|
||||
}else {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
if (fields.get(i).name.equals(name)) {
|
||||
if (value.equals("0") || value.equals("false") || value.equals(""))
|
||||
if (value.equals("0") || value.equals("false") || value.isEmpty())
|
||||
m_prepStmt.setBoolean(fields.get(i).pos, false);
|
||||
else
|
||||
m_prepStmt.setBoolean(fields.get(i).pos, true);
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
package tools;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.sql.*;
|
||||
//import tools.dbtools.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Translation {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Translation.class);
|
||||
|
||||
public int language_id;
|
||||
//public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
public Connection conn;
|
||||
public Translation(String lng, Connection conn){
|
||||
public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
public Translation(String lng, NamedParameterJdbcTemplate jdbcTemplate){
|
||||
language_id=1;
|
||||
switch (lng) {
|
||||
case "kz":
|
||||
@ -29,12 +29,10 @@ public class Translation {
|
||||
language_id = 1;
|
||||
break;
|
||||
}
|
||||
this.conn = conn;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public String trt(String text){
|
||||
|
||||
boolean find = false;
|
||||
String sql = """
|
||||
select
|
||||
translation
|
||||
@ -42,39 +40,19 @@ public class Translation {
|
||||
main._translations
|
||||
where
|
||||
del=false
|
||||
and language_id=${language_id}
|
||||
and identifier=${identifier};
|
||||
and language_id=:language_id
|
||||
and identifier=:identifier;
|
||||
""";
|
||||
|
||||
PreparedStatementNamed stmtn=null;
|
||||
try {
|
||||
stmtn = new PreparedStatementNamed(conn, sql);
|
||||
stmtn.setInt("language_id", language_id);
|
||||
stmtn.setString("identifier", text);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id);
|
||||
parameters.addValue("identifier", text);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new tools.DBTools.JsonRowMapper());
|
||||
int i = 0;
|
||||
for (i = 0; i < ret.size(); i++) {
|
||||
JSONObject json = new JSONObject(ret.get(i));
|
||||
text = json.getString("translation");
|
||||
}
|
||||
|
||||
if(stmtn!=null){
|
||||
PreparedStatement stmt=stmtn.getPreparedStatement();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
text = rs.getString(1);
|
||||
find = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try { if (rs != null) rs.close(); } catch (Exception e) {};
|
||||
try { if (stmt != null) stmt.close(); } catch (Exception e) {};
|
||||
}
|
||||
}
|
||||
|
||||
if(!find){
|
||||
if(i==0){
|
||||
text = text.replace("_", " ");
|
||||
}
|
||||
return text;
|
||||
|
||||
Reference in New Issue
Block a user