Compare commits
9 Commits
f9c47e25e4
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b67d8ce01 | |||
| d6acc01422 | |||
| f27abbd081 | |||
| fa1c872897 | |||
| 9462f5caab | |||
| 7020497109 | |||
| 07be57d5cf | |||
| 7a8fdc2f4e | |||
| bbb7bedc94 |
@@ -45,9 +45,10 @@ CREATE TABLE device_info (
|
|||||||
sn VARCHAR(255),
|
sn VARCHAR(255),
|
||||||
device_model VARCHAR(255),
|
device_model VARCHAR(255),
|
||||||
last_online_time BIGINT,
|
last_online_time BIGINT,
|
||||||
status INT
|
status INT,
|
||||||
|
remark VARCHAR(255)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO device_info (is_monitored, time_out_period, device_brand, android_version, sn, device_model, last_online_time, status) VALUES
|
INSERT INTO device_info (is_monitored, time_out_period, device_brand, android_version, sn, device_model, last_online_time, status,remark) VALUES
|
||||||
(1, 600, 'google', 'Android 10', UNIX_TIMESTAMP(), 1),
|
(1, 1800, 'google', 'Android 10',,'Pixel 3', UNIX_TIMESTAMP(), 1,'转发设备'),
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ FROM openjdk:17-jdk-slim
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 将构建生成的可执行jar包复制到容器内。假设jar包位于target/目录下,并命名为wePush-1.0.0.jar。
|
# 将构建生成的可执行jar包复制到容器内。假设jar包位于target/目录下,并命名为wePush-1.0.0.jar。
|
||||||
COPY target/wePush-1.0.0.jar ./app.jar
|
COPY ../target/wePushApp-1.2.0.jar ./app.jar
|
||||||
|
|
||||||
# 配置容器启动时运行的命令,这里用来启动Spring Boot应用。
|
# 配置容器启动时运行的命令,这里用来启动Spring Boot应用。
|
||||||
# 使用非root用户运行Java应用是一个好的安全实践。
|
# 使用非root用户运行Java应用是一个好的安全实践。
|
||||||
@@ -21,4 +21,5 @@ public class DeviceInfoDAO {
|
|||||||
private String deviceModel;
|
private String deviceModel;
|
||||||
private long lastOnlineTime;
|
private long lastOnlineTime;
|
||||||
private int status;
|
private int status;
|
||||||
|
private String remark;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.kimgo.wepush.service;
|
package com.kimgo.wepush.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -102,7 +102,7 @@ public class HeartBeatService {
|
|||||||
try {
|
try {
|
||||||
DeviceInfoDAO deviceInfoDAO = deviceInfoDAOMapper.selectOne(queryWrapper);
|
DeviceInfoDAO deviceInfoDAO = deviceInfoDAOMapper.selectOne(queryWrapper);
|
||||||
if (deviceInfoDAO != null) {
|
if (deviceInfoDAO != null) {
|
||||||
logger.info("Data is queried in the database based on the SN");
|
//logger.info("Data is queried in the database based on the SN");
|
||||||
return deviceInfoDAO;
|
return deviceInfoDAO;
|
||||||
}
|
}
|
||||||
return null; // 数据不存在
|
return null; // 数据不存在
|
||||||
@@ -120,7 +120,7 @@ public class HeartBeatService {
|
|||||||
* @return 转换后的 DeviceInfoDAO 对象。
|
* @return 转换后的 DeviceInfoDAO 对象。
|
||||||
*/
|
*/
|
||||||
private DeviceInfoDAO convertToDeviceInfoDAO(DeviceInfo deviceInfo) {
|
private DeviceInfoDAO convertToDeviceInfoDAO(DeviceInfo deviceInfo) {
|
||||||
logger.info("start convert to device info dao");
|
// logger.info("start convert to device info dao");
|
||||||
|
|
||||||
DeviceInfoDAO deviceInfoDAO = new DeviceInfoDAO();
|
DeviceInfoDAO deviceInfoDAO = new DeviceInfoDAO();
|
||||||
deviceInfoDAO.setIsMonitored(1);
|
deviceInfoDAO.setIsMonitored(1);
|
||||||
|
|||||||
@@ -70,15 +70,15 @@ public class MonitorService {
|
|||||||
long timeDifferenceSeconds = timeDifferenceMillis / 1000;
|
long timeDifferenceSeconds = timeDifferenceMillis / 1000;
|
||||||
// 如果设备超出设定的超时周期未上线,则认为设备离线,并进行相应处理
|
// 如果设备超出设定的超时周期未上线,则认为设备离线,并进行相应处理
|
||||||
if (timeDifferenceSeconds > device.getTimeOutPeriod()) {
|
if (timeDifferenceSeconds > device.getTimeOutPeriod()) {
|
||||||
logger.info("Device offline. SN: {}, LastOnlineTime: {}, TimeDifference: {}, TimeoutPeriod: {}",
|
//logger.info("Device offline. SN: {}, LastOnlineTime: {}, TimeDifference: {}, TimeoutPeriod: {}",
|
||||||
device.getSN(), device.getLastOnlineTime(), timeDifferenceSeconds, device.getTimeOutPeriod());
|
//device.getSN(), device.getLastOnlineTime(), timeDifferenceSeconds, device.getTimeOutPeriod());
|
||||||
updateStatus(device, 0); // 更新设备状态为离线
|
updateStatus(device, 0); // 更新设备状态为离线
|
||||||
logger.info("Update the device status to offline.");
|
logger.info("Update the device status to offline.");
|
||||||
sendNotification(device); // 发送设备离线通知
|
sendNotification(device); // 发送设备离线通知
|
||||||
} else {
|
} else {
|
||||||
// 如果设备仍在设定的超时周期内上线,则认为设备在线,并更新设备状态
|
// 如果设备仍在设定的超时周期内上线,则认为设备在线,并更新设备状态
|
||||||
updateStatus(device, 1); // 更新设备状态为在线
|
updateStatus(device, 1); // 更新设备状态为在线
|
||||||
logger.info("update the device status to online.");
|
//logger.info("update the device status to online.");
|
||||||
}
|
}
|
||||||
} catch (DatabaseUpdateException dbe) {
|
} catch (DatabaseUpdateException dbe) {
|
||||||
// 更新数据库出错时的处理逻辑
|
// 更新数据库出错时的处理逻辑
|
||||||
@@ -138,6 +138,7 @@ public class MonitorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建并设置文本卡片消息的内容。
|
* 构建并设置文本卡片消息的内容。
|
||||||
|
*
|
||||||
* @param deviceInfoDAO 设备信息数据访问对象,用于获取设备的详细信息。
|
* @param deviceInfoDAO 设备信息数据访问对象,用于获取设备的详细信息。
|
||||||
* @return TextCardMessage 返回构建完成的文本卡片消息对象。
|
* @return TextCardMessage 返回构建完成的文本卡片消息对象。
|
||||||
*/
|
*/
|
||||||
@@ -162,6 +163,7 @@ public class MonitorService {
|
|||||||
"<div class='highlight'>安卓版本: " + deviceInfoDAO.getAndroidVersion() + "</div>" +
|
"<div class='highlight'>安卓版本: " + deviceInfoDAO.getAndroidVersion() + "</div>" +
|
||||||
"<div class='highlight'>SN: " + deviceInfoDAO.getSN() + "</div>" +
|
"<div class='highlight'>SN: " + deviceInfoDAO.getSN() + "</div>" +
|
||||||
"<div class='highlight'>监测到掉线时间: " + formattedCurrentTime + "</div>" +
|
"<div class='highlight'>监测到掉线时间: " + formattedCurrentTime + "</div>" +
|
||||||
|
"<div class='highlight'>备注: " + deviceInfoDAO.getRemark() + "</div>" +
|
||||||
"检测到设备已掉线,请及时查看设备状态.");
|
"检测到设备已掉线,请及时查看设备状态.");
|
||||||
textCard.setUrl("https://kimgo.cn");
|
textCard.setUrl("https://kimgo.cn");
|
||||||
// 将构建的TextCard对象设置到TextCardMessage中
|
// 将构建的TextCard对象设置到TextCardMessage中
|
||||||
@@ -176,6 +178,7 @@ public class MonitorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备的状态信息。
|
* 更新设备的状态信息。
|
||||||
|
*
|
||||||
* @param device 设备信息对象,包含需要更新的设备的SN(序列号)。
|
* @param device 设备信息对象,包含需要更新的设备的SN(序列号)。
|
||||||
* @param status 需要更新到的新状态。
|
* @param status 需要更新到的新状态。
|
||||||
* @throws DatabaseUpdateException 如果数据库更新过程中发生异常,则抛出此异常。
|
* @throws DatabaseUpdateException 如果数据库更新过程中发生异常,则抛出此异常。
|
||||||
|
|||||||
Reference in New Issue
Block a user