Compare commits
No commits in common. "4e4084e15d29198a4c7f678d0407edd5452784ea" and "a67580c387f4f818720d8b5c8996789a58c82d28" have entirely different histories.
4e4084e15d
...
a67580c387
|
|
@ -1,11 +0,0 @@
|
|||
package com.kimgo.wepush.exceptions;
|
||||
|
||||
public class DatabaseUpdateException extends Exception{
|
||||
public DatabaseUpdateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DatabaseUpdateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,6 @@ package com.kimgo.wepush.service;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.kimgo.wepush.exceptions.DatabaseQueryException;
|
||||
import com.kimgo.wepush.exceptions.DatabaseUpdateException;
|
||||
import com.kimgo.wepush.mapper.DeviceInfoDAOMapper;
|
||||
import com.kimgo.wepush.model.DeviceInfoDAO;
|
||||
import com.kimgo.wepush.model.TextCardMessage;
|
||||
|
|
@ -16,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
|
@ -35,18 +34,10 @@ public class MonitorService {
|
|||
|
||||
@Scheduled(fixedDelay = 480000)
|
||||
public void monitorOnlineDevices() {
|
||||
|
||||
List<DeviceInfoDAO> devices;
|
||||
try {
|
||||
devices = getAllDevices();
|
||||
} catch (DatabaseQueryException e) {
|
||||
logger.error("monitor online devices error.");
|
||||
return;
|
||||
}
|
||||
List<DeviceInfoDAO> devices = getAllDevices();
|
||||
if (devices.isEmpty()) {
|
||||
// 没有找到数据的处理逻辑
|
||||
logger.info("no data was queried.");
|
||||
return;
|
||||
}
|
||||
for (DeviceInfoDAO device : devices) {
|
||||
try {
|
||||
|
|
@ -67,11 +58,7 @@ public class MonitorService {
|
|||
updateStatus(device, 1); // 设备在线
|
||||
logger.info("update the device status to online.");
|
||||
}
|
||||
} catch (DatabaseUpdateException dbe){
|
||||
logger.error("update to mysql error.");
|
||||
return;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Error processing device with SN " + device.getSN(), e);
|
||||
}
|
||||
}
|
||||
|
|
@ -82,7 +69,7 @@ public class MonitorService {
|
|||
*
|
||||
* @return 包含所有id的列表。
|
||||
*/
|
||||
private List<DeviceInfoDAO> getAllDevices() throws DatabaseQueryException {
|
||||
private List<DeviceInfoDAO> getAllDevices() {
|
||||
try {
|
||||
// 查询所有DeviceInfoDAO对象
|
||||
List<DeviceInfoDAO> deviceInfoDAOs = deviceInfoDAOMapper.selectList(new QueryWrapper<>());
|
||||
|
|
@ -90,8 +77,8 @@ public class MonitorService {
|
|||
return deviceInfoDAOs;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error querying all device info IDs", e);
|
||||
throw new DatabaseQueryException("get all devices error.",e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -134,7 +121,7 @@ public class MonitorService {
|
|||
|
||||
return textCardMessage;
|
||||
}
|
||||
private void updateStatus(DeviceInfoDAO device, int status) throws DatabaseUpdateException {
|
||||
private void updateStatus(DeviceInfoDAO device, int status) {
|
||||
try {
|
||||
UpdateWrapper<DeviceInfoDAO> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("SN", device.getSN());
|
||||
|
|
@ -148,8 +135,6 @@ public class MonitorService {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error updating status for SN: " + device.getSN(), e);
|
||||
throw new DatabaseUpdateException("update to mysql error.",e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue