|
|
|
@ -1,6 +1,9 @@ |
|
|
|
package com.topsail.scheduletask.task; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.topsail.scheduletask.mapper.InformLogDao; |
|
|
|
import com.topsail.scheduletask.mapper.TopsailTransmitLogDao; |
|
|
|
import com.topsail.scheduletask.pojo.FocusDeviceOnline; |
|
|
|
import com.topsail.scheduletask.service.AmqpService; |
|
|
|
import com.topsail.scheduletask.util.MaiSenderlUtil; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -11,9 +14,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Component |
|
|
|
@Configuration //1.主要用于标记配置类,兼备Component的效果。 |
|
|
|
@ -27,6 +29,10 @@ public class CheckRabbitMqScheduleTask { |
|
|
|
AmqpService amqpService; |
|
|
|
@Value("${ignore.mq.queue}") |
|
|
|
String ignoreQueue; |
|
|
|
@Autowired |
|
|
|
TopsailTransmitLogDao topsailTransmitLogDao; |
|
|
|
@Autowired |
|
|
|
InformLogDao informLogDao; |
|
|
|
|
|
|
|
//1.每个小时定时检查rabbitmq |
|
|
|
// @Scheduled(cron = "0 0 0/1 * * ?") |
|
|
|
@ -55,7 +61,51 @@ public class CheckRabbitMqScheduleTask { |
|
|
|
amqpService.SendMessage("mailNotice", json); |
|
|
|
} |
|
|
|
} |
|
|
|
// @Scheduled(cron = "1/60 * * * * ?") |
|
|
|
|
|
|
|
/** |
|
|
|
* 每分钟检查设备是否在线 |
|
|
|
*/ |
|
|
|
@Scheduled(cron = "0 * * * * ?") |
|
|
|
// @Scheduled(cron = "1/60 * * * * ?") |
|
|
|
//1.每分钟检查设备是否在线 |
|
|
|
//或直接指定时间间隔,例如:5秒 |
|
|
|
// @Scheduled(fixedRate=5000) |
|
|
|
private void checkDeviceOnline() { |
|
|
|
try { |
|
|
|
//1.查询需要监控的设备 |
|
|
|
List<FocusDeviceOnline> focusDeviceOnlineList = topsailTransmitLogDao.getFocusDevice(1); |
|
|
|
if (focusDeviceOnlineList != null && focusDeviceOnlineList.size() > 0) { |
|
|
|
for (FocusDeviceOnline focusDeviceOnline : focusDeviceOnlineList) { |
|
|
|
String imeis = focusDeviceOnline.getFocusImeis(); |
|
|
|
List<String> imeiList = new ArrayList<>(); |
|
|
|
if (imeis != null && imeis.length() > 0) { |
|
|
|
String[] imeisArray = imeis.split(","); |
|
|
|
for (String imei : imeisArray) { |
|
|
|
imeiList.add(imei); |
|
|
|
} |
|
|
|
} |
|
|
|
//2.查询设备离线数量 |
|
|
|
long count = topsailTransmitLogDao.getOfflineDeviceCount(imeiList, focusDeviceOnline.getProjectId()); |
|
|
|
if (count > 0) { |
|
|
|
String subject = "紧急--设备离线通知"+"-" + focusDeviceOnline.getUserName(); |
|
|
|
String today = new SimpleDateFormat("yyyy-MM-dd HH:00:00").format(new Date()); |
|
|
|
Integer logCount = informLogDao.getNewInformLogCount(subject, today); |
|
|
|
if (logCount == null || (logCount != null && logCount < 1)) { |
|
|
|
//3.发送邮件 |
|
|
|
String content = "客户:" + focusDeviceOnline.getUserName() + ",设备离线数量:" + count + "个,请进入系统查看原因"; |
|
|
|
maiSenderlUtil.sendMail("1129801211@qq.com", subject, content, true, null, subject); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
System.out.println("发送邮件失败"); |
|
|
|
System.out.println(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// @Scheduled(cron = "1/60 * * * * ?") |
|
|
|
// //或直接指定时间间隔,例如:5秒 |
|
|
|
//// @Scheduled(fixedRate=5000) |
|
|
|
// private void checkMail() { |
|
|
|
|