IVI modif
This commit is contained in:
1
pom.xml
1
pom.xml
@ -143,6 +143,7 @@
|
|||||||
<version>1.18.36</version>
|
<version>1.18.36</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -110,6 +110,7 @@ public class SendWarning {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//https://ccalm.test/api/locust/v01/SendWarning
|
||||||
@RequestMapping(value = {"/api/locust/v01/SendWarning"},method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
|
@RequestMapping(value = {"/api/locust/v01/SendWarning"},method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<Object> send() {
|
public ResponseEntity<Object> send() {
|
||||||
@ -143,128 +144,118 @@ public class SendWarning {
|
|||||||
for (String jsonString : ret) {
|
for (String jsonString : ret) {
|
||||||
JSONObject obj = new JSONObject(jsonString);
|
JSONObject obj = new JSONObject(jsonString);
|
||||||
|
|
||||||
JSONObject tmp_soil = getSoilTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
|
||||||
JSONObject tmp_air = getAirTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
JSONObject tmp_air = getAirTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
||||||
|
JSONObject tmp_soil = getSoilTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
||||||
|
|
||||||
if(tmp_air!=null) {
|
if(tmp_air!=null) {
|
||||||
Translation trt=new Translation(obj.getString("short_name"),jdbcTemplate);
|
Translation trt=new Translation(obj.getString("short_name"),jdbcTemplate);
|
||||||
double value = obj.getDouble("value");
|
double value = obj.getDouble("temperature_air");
|
||||||
if (value < tmp_air.getDouble("value")) {
|
if (value < tmp_air.getDouble("value")) {
|
||||||
String email = obj.getString("email");
|
String email = obj.getString("email");
|
||||||
if(email.equals("irigm@mail.ru") || email.equals("ivanov.i@istt.kz")){ //TODO для тестирования потом удалить
|
StringBuilder html = new StringBuilder(1024);
|
||||||
|
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: 20px auto 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; }")
|
||||||
|
.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("<h2>").append(trt.trt(true,"Warning")).append("</h2>")
|
||||||
|
.append("<p>").append(trt.trt(true,"The_soil_temperature_has_exceeded_the_set_value")).append(": ").append(value).append("</p>")
|
||||||
|
.append("<table>")
|
||||||
|
.append("<tr><th>").append(trt.trt(true,"Date")).append("</th><td>").append(tmp_air.getString("date")).append("</td></tr>")
|
||||||
|
.append("<tr><th>").append(trt.trt(true,"Value")).append("</th><td>").append(tmp_air.getDouble("value")).append(" °C</td></tr>")
|
||||||
|
.append("</table>")
|
||||||
|
.append(trt.trt(true,"To_resume_monitoring_please_set_the_warn_field_to_true"))
|
||||||
|
.append("</div>") // Закрываем контейнер
|
||||||
|
.append("</body>")
|
||||||
|
.append("</html>");
|
||||||
|
|
||||||
StringBuilder html = new StringBuilder(1024);
|
boolean send = false;
|
||||||
html.append("<html>")
|
try {
|
||||||
.append("<head>")
|
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, email, trt.trt(true,"Soil temperature"), html.toString());
|
||||||
.append("<style>")
|
send = true;
|
||||||
.append("body { font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; margin: 0; padding: 0; }")
|
} catch (Exception e) {
|
||||||
.append(".container { max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border: 1px solid #ddd; position: relative; }")
|
e.printStackTrace();
|
||||||
.append(".logo { position: absolute; top: 10px; right: 10px; width: 100px; height: auto; }")
|
}
|
||||||
.append("h2 { color: #d9534f; margin-top: 50px; }") // Отступ для логотипа
|
if(send) {
|
||||||
.append("table { border-collapse: collapse; width: 100%; margin: 20px 0; }")
|
sql= """
|
||||||
.append("th, td { padding: 10px; border: 1px solid #ddd; text-align: left; }")
|
update
|
||||||
.append("th { background-color: #f9f9f9; }")
|
main.frmcheckpoints
|
||||||
.append("p { font-weight: bold; }")
|
set
|
||||||
.append("</style>")
|
warn_air=true
|
||||||
.append("</head>")
|
where uid=CAST(:uid AS uuid)
|
||||||
.append("<body>")
|
""";
|
||||||
.append("<div class='container'>")
|
MapSqlParameterSource param = new MapSqlParameterSource();
|
||||||
.append("<img src='https://ccalm.org/resources/images/locust.png' alt='Logo' class='logo'>") // Логотип
|
param.addValue("uid", obj.getString("uid"), Types.VARCHAR);
|
||||||
.append("<h2>").append(trt.trt(true,"Warning")).append("</h2>")
|
int rowsUpdated = jdbcTemplate.update(sql, param);
|
||||||
.append("<p>").append(trt.trt(true,"The_soil_temperature_has_exceeded_the_set_value")).append(": ").append(value).append("</p>")
|
System.out.println("rowsUpdated = "+String.valueOf(rowsUpdated));
|
||||||
.append("<table>")
|
|
||||||
.append("<tr><th>").append(trt.trt(true,"Date")).append("</th><td>").append(tmp_air.getString("date")).append("</td></tr>")
|
|
||||||
.append("<tr><th>").append(trt.trt(true,"Value")).append("</th><td>").append(tmp_air.getDouble("value")).append(" °C</td></tr>")
|
|
||||||
.append("</table>")
|
|
||||||
.append(trt.trt(true,"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(true,"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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tmp_soil!=null) {
|
if(tmp_soil!=null) {
|
||||||
Translation trt=new Translation(obj.getString("short_name"),jdbcTemplate);
|
Translation trt=new Translation(obj.getString("short_name"),jdbcTemplate);
|
||||||
double value = obj.getDouble("value");
|
double value = obj.getDouble("temperature_soil");
|
||||||
if (value < tmp_soil.getDouble("value")) {
|
if (value < tmp_soil.getDouble("value")) {
|
||||||
String email = obj.getString("email");
|
String email = obj.getString("email");
|
||||||
if(email.equals("irigm@mail.ru") || email.equals("ivanov.i@istt.kz")){ //TODO для тестирования потом удалить
|
StringBuilder html = new StringBuilder(1024);
|
||||||
|
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: 20px auto 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; }")
|
||||||
|
.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("<h2>").append(trt.trt(true,"Warning")).append("</h2>")
|
||||||
|
.append("<p>").append(trt.trt(true,"The_soil_temperature_has_exceeded_the_set_value")).append(": ").append(value).append("</p>")
|
||||||
|
.append("<table>")
|
||||||
|
.append("<tr><th>").append(trt.trt(true,"Date")).append("</th><td>").append(tmp_soil.getString("date")).append("</td></tr>")
|
||||||
|
.append("<tr><th>").append(trt.trt(true,"Value")).append("</th><td>").append(tmp_soil.getDouble("value")).append(" °C</td></tr>")
|
||||||
|
.append("</table>")
|
||||||
|
.append(trt.trt(true,"To_resume_monitoring_please_set_the_warn_field_to_true"))
|
||||||
|
.append("</div>") // Закрываем контейнер
|
||||||
|
.append("</body>")
|
||||||
|
.append("</html>");
|
||||||
|
|
||||||
StringBuilder html = new StringBuilder(1024);
|
boolean send = false;
|
||||||
html.append("<html>")
|
try {
|
||||||
.append("<head>")
|
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, email, trt.trt(true,"Soil temperature"), html.toString());
|
||||||
.append("<style>")
|
send = true;
|
||||||
.append("body { font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; margin: 0; padding: 0; }")
|
} catch (Exception e) {
|
||||||
.append(".container { max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border: 1px solid #ddd; position: relative; }")
|
e.printStackTrace();
|
||||||
.append(".logo { position: absolute; top: 10px; right: 10px; width: 100px; height: auto; }")
|
}
|
||||||
.append("h2 { color: #d9534f; margin-top: 50px; }") // Отступ для логотипа
|
if(send) {
|
||||||
.append("table { border-collapse: collapse; width: 100%; margin: 20px 0; }")
|
sql= """
|
||||||
.append("th, td { padding: 10px; border: 1px solid #ddd; text-align: left; }")
|
update
|
||||||
.append("th { background-color: #f9f9f9; }")
|
main.frmcheckpoints
|
||||||
.append("p { font-weight: bold; }")
|
set
|
||||||
.append("</style>")
|
warn_soil=true
|
||||||
.append("</head>")
|
where uid=CAST(:uid AS uuid)
|
||||||
.append("<body>")
|
""";
|
||||||
.append("<div class='container'>")
|
MapSqlParameterSource param = new MapSqlParameterSource();
|
||||||
.append("<img src='https://ccalm.org/resources/images/locust.png' alt='Logo' class='logo'>") // Логотип
|
param.addValue("uid", obj.getString("uid"), Types.VARCHAR);
|
||||||
.append("<h2>").append(trt.trt(true,"Warning")).append("</h2>")
|
int rowsUpdated = jdbcTemplate.update(sql, param);
|
||||||
.append("<p>").append(trt.trt(true,"The_soil_temperature_has_exceeded_the_set_value")).append(": ").append(value).append("</p>")
|
System.out.println("rowsUpdated = "+String.valueOf(rowsUpdated));
|
||||||
.append("<table>")
|
|
||||||
.append("<tr><th>").append(trt.trt(true,"Date")).append("</th><td>").append(tmp_soil.getString("date")).append("</td></tr>")
|
|
||||||
.append("<tr><th>").append(trt.trt(true,"Value")).append("</th><td>").append(tmp_soil.getDouble("value")).append(" °C</td></tr>")
|
|
||||||
.append("</table>")
|
|
||||||
.append(trt.trt(true,"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(true,"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 ex) {
|
} catch (Exception ex) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
|||||||
@ -13,54 +13,49 @@ import javax.mail.Transport;
|
|||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility class for sending e-mail messages
|
|
||||||
* @author www.codejava.net
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EmailUtility {
|
public class EmailUtility {
|
||||||
|
|
||||||
public static void sendEmail(String host, String port,
|
public static void sendEmail(String host, String port,
|
||||||
final String userName, final String password, String toAddress,
|
final String userName, final String password, String toAddress,
|
||||||
String subject, String message) throws AddressException,
|
String subject, String message) throws AddressException,
|
||||||
MessagingException
|
MessagingException
|
||||||
{
|
{
|
||||||
|
// sets SMTP server properties
|
||||||
|
Properties properties = new Properties();
|
||||||
|
|
||||||
// sets SMTP server properties
|
properties.put("mail.smtp.host", host);
|
||||||
Properties properties = new Properties();
|
properties.put("mail.smtp.port", port);
|
||||||
|
properties.put("mail.smtp.auth", "true");
|
||||||
properties.put("mail.smtp.host", host);
|
//properties.put("mail.smtp.starttls.enable","true"); STARTTLS requested but already using SSL
|
||||||
properties.put("mail.smtp.port", port);
|
properties.put("mail.smtp.EnableSSL.enable","true");
|
||||||
properties.put("mail.smtp.auth", "true");
|
properties.put("mail.smtp.socketFactory.port", port);
|
||||||
//properties.put("mail.smtp.starttls.enable","true"); STARTTLS requested but already using SSL
|
properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
|
||||||
properties.put("mail.smtp.EnableSSL.enable","true");
|
//properties.put("mail.debug", "true");
|
||||||
properties.put("mail.smtp.socketFactory.port", port);
|
|
||||||
properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
|
|
||||||
//properties.put("mail.debug", "true");
|
|
||||||
|
|
||||||
|
|
||||||
// creates a new session with an authenticator
|
|
||||||
Authenticator auth = new Authenticator() {
|
// creates a new session with an authenticator
|
||||||
public PasswordAuthentication getPasswordAuthentication() {
|
Authenticator auth = new Authenticator() {
|
||||||
return new PasswordAuthentication(userName, password);
|
public PasswordAuthentication getPasswordAuthentication() {
|
||||||
}
|
return new PasswordAuthentication(userName, password);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
Session session = Session.getInstance(properties, auth);
|
|
||||||
|
Session session = Session.getInstance(properties, auth);
|
||||||
//creates a new e-mail message
|
|
||||||
Message msg = new MimeMessage(session);
|
//creates a new e-mail message
|
||||||
|
Message msg = new MimeMessage(session);
|
||||||
msg.setFrom(new InternetAddress(userName));
|
|
||||||
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
|
msg.setFrom(new InternetAddress(userName));
|
||||||
msg.setRecipients(Message.RecipientType.TO, toAddresses);
|
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
|
||||||
msg.setSubject(subject);
|
msg.setRecipients(Message.RecipientType.TO, toAddresses);
|
||||||
msg.setSentDate(new Date());
|
msg.setSubject(subject);
|
||||||
//msg.setText(message);
|
msg.setSentDate(new Date());
|
||||||
msg.setContent(message, "text/html; charset=utf-8");
|
//msg.setText(message);
|
||||||
|
msg.setContent(message, "text/html; charset=utf-8");
|
||||||
// sends the e-mail
|
|
||||||
Transport.send(msg);
|
// sends the e-mail
|
||||||
|
Transport.send(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1171,8 +1171,21 @@ new Calendar({
|
|||||||
<td style="padding: 1px; width: 158px; white-space: nowrap;" th:text="${Year}">Year</td>
|
<td style="padding: 1px; width: 158px; white-space: nowrap;" th:text="${Year}">Year</td>
|
||||||
<td style="padding: 1px;">
|
<td style="padding: 1px;">
|
||||||
<select style="width: 100%;" id="filter_ivi_year">
|
<select style="width: 100%;" id="filter_ivi_year">
|
||||||
<option value="2023_03_05">2023 (03..05)</option>
|
|
||||||
|
<option value="2025_02_04">2025 (02..04)</option>
|
||||||
|
<option value="2025_03_05">2025 (03..05)</option>
|
||||||
|
<option value="2025_04_06">2025 (04..06)</option>
|
||||||
|
<option value="2025_05_07">2025 (05..07)</option>
|
||||||
|
|
||||||
|
<option value="2024_02_04">2024 (02..04)</option>
|
||||||
|
<option value="2024_03_05">2024 (03..05)</option>
|
||||||
|
<option value="2024_04_06">2024 (04..06)</option>
|
||||||
|
<option value="2024_05_07">2024 (05..07)</option>
|
||||||
|
|
||||||
<option value="2023_02_04">2023 (02..04)</option>
|
<option value="2023_02_04">2023 (02..04)</option>
|
||||||
|
<option value="2023_03_05">2023 (03..05)</option>
|
||||||
|
<option value="2023_04_06">2023 (04..06)</option>
|
||||||
|
<option value="2023_05_07">2023 (05..07)</option>
|
||||||
|
|
||||||
<option value="2022_02_04">2022 (02..04)</option>
|
<option value="2022_02_04">2022 (02..04)</option>
|
||||||
<option value="2022_03_05">2022 (03..05)</option>
|
<option value="2022_03_05">2022 (03..05)</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user