IVI modif
This commit is contained in:
1
pom.xml
1
pom.xml
@ -143,6 +143,7 @@
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -110,6 +110,7 @@ public class SendWarning {
|
||||
return result;
|
||||
}
|
||||
|
||||
//https://ccalm.test/api/locust/v01/SendWarning
|
||||
@RequestMapping(value = {"/api/locust/v01/SendWarning"},method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public ResponseEntity<Object> send() {
|
||||
@ -143,128 +144,118 @@ public class SendWarning {
|
||||
for (String jsonString : ret) {
|
||||
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_soil = getSoilTemperature(obj.getDouble("lat"),obj.getDouble("lon"));
|
||||
|
||||
if(tmp_air!=null) {
|
||||
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")) {
|
||||
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);
|
||||
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(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>");
|
||||
|
||||
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));
|
||||
}
|
||||
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_air=true
|
||||
where uid=CAST(:uid AS uuid)
|
||||
""";
|
||||
MapSqlParameterSource param = new MapSqlParameterSource();
|
||||
param.addValue("uid", obj.getString("uid"), Types.VARCHAR);
|
||||
int rowsUpdated = jdbcTemplate.update(sql, param);
|
||||
System.out.println("rowsUpdated = "+String.valueOf(rowsUpdated));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(tmp_soil!=null) {
|
||||
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")) {
|
||||
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);
|
||||
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(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>");
|
||||
|
||||
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));
|
||||
}
|
||||
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_soil=true
|
||||
where uid=CAST(:uid AS uuid)
|
||||
""";
|
||||
MapSqlParameterSource param = new MapSqlParameterSource();
|
||||
param.addValue("uid", obj.getString("uid"), Types.VARCHAR);
|
||||
int rowsUpdated = jdbcTemplate.update(sql, param);
|
||||
System.out.println("rowsUpdated = "+String.valueOf(rowsUpdated));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
@ -14,53 +14,48 @@ import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
/**
|
||||
* A utility class for sending e-mail messages
|
||||
* @author www.codejava.net
|
||||
*
|
||||
*/
|
||||
public class EmailUtility {
|
||||
|
||||
public static void sendEmail(String host, String port,
|
||||
final String userName, final String password, String toAddress,
|
||||
String subject, String message) throws AddressException,
|
||||
final String userName, final String password, String toAddress,
|
||||
String subject, String message) throws AddressException,
|
||||
MessagingException
|
||||
{
|
||||
// sets SMTP server properties
|
||||
Properties properties = new Properties();
|
||||
|
||||
// sets SMTP server properties
|
||||
Properties properties = new Properties();
|
||||
|
||||
properties.put("mail.smtp.host", host);
|
||||
properties.put("mail.smtp.port", port);
|
||||
properties.put("mail.smtp.auth", "true");
|
||||
//properties.put("mail.smtp.starttls.enable","true"); STARTTLS requested but already using SSL
|
||||
properties.put("mail.smtp.EnableSSL.enable","true");
|
||||
properties.put("mail.smtp.socketFactory.port", port);
|
||||
properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
|
||||
//properties.put("mail.debug", "true");
|
||||
properties.put("mail.smtp.host", host);
|
||||
properties.put("mail.smtp.port", port);
|
||||
properties.put("mail.smtp.auth", "true");
|
||||
//properties.put("mail.smtp.starttls.enable","true"); STARTTLS requested but already using SSL
|
||||
properties.put("mail.smtp.EnableSSL.enable","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() {
|
||||
public PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(userName, password);
|
||||
}
|
||||
};
|
||||
// creates a new session with an authenticator
|
||||
Authenticator auth = new Authenticator() {
|
||||
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.setRecipients(Message.RecipientType.TO, toAddresses);
|
||||
msg.setSubject(subject);
|
||||
msg.setSentDate(new Date());
|
||||
//msg.setText(message);
|
||||
msg.setContent(message, "text/html; charset=utf-8");
|
||||
msg.setFrom(new InternetAddress(userName));
|
||||
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
|
||||
msg.setRecipients(Message.RecipientType.TO, toAddresses);
|
||||
msg.setSubject(subject);
|
||||
msg.setSentDate(new Date());
|
||||
//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;">
|
||||
<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_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_03_05">2022 (03..05)</option>
|
||||
|
||||
Reference in New Issue
Block a user