|  |  |  | 
|---|
|  |  |  | package com.moral.task; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.temporal.ChronoUnit; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.moral.mapper.DeviceMapper; | 
|---|
|  |  |  | import com.moral.mapper.HistoryHourlyMapper; | 
|---|
|  |  |  | import com.moral.util.AlarmUtils_2; | 
|---|
|  |  |  | import com.xxl.job.core.biz.model.ReturnT; | 
|---|
|  |  |  | import com.xxl.job.core.handler.annotation.XxlJob; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private DeviceMapper deviceMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private HistoryHourlyMapper historyHourlyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("OffLineDevices") | 
|---|
|  |  |  | public ReturnT OffLineAlarm(String params) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ReturnT(500, "无掉线设备,不发送邮件"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("hourOffLine") | 
|---|
|  |  |  | public ReturnT hourOffLine(String params) { | 
|---|
|  |  |  | //获取参数 | 
|---|
|  |  |  | Map<String, Object> map = JSON.parseObject(params, Map.class); | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()) { | 
|---|
|  |  |  | String orgId = entry.getKey(); | 
|---|
|  |  |  | List<String> emails = (List<String>) entry.getValue(); | 
|---|
|  |  |  | //获取该组织下离线设备 | 
|---|
|  |  |  | List<Map<String, Object>> devices = deviceMapper.getOfflineDeviceOfDiseaseCenter(orgId); | 
|---|
|  |  |  | List<String> devicesInfo = devices.stream() | 
|---|
|  |  |  | .map(device -> device.get("name").toString()) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(devicesInfo)) { | 
|---|
|  |  |  | emails.forEach(email -> AlarmUtils_2.sendMail(email, "小时-设备掉线警报!!!", devicesInfo + "设备掉线!")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ReturnT(200, "执行成功!有邮件发送!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("dayOffLine") | 
|---|
|  |  |  | public ReturnT dayOffLine(String params) { | 
|---|
|  |  |  | LocalDateTime now = LocalDateTime.now(); | 
|---|
|  |  |  | LocalDateTime end = now.truncatedTo(ChronoUnit.DAYS); | 
|---|
|  |  |  | LocalDateTime start = now.minusDays(1); | 
|---|
|  |  |  | Map<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("start", start); | 
|---|
|  |  |  | hashMap.put("end", end); | 
|---|
|  |  |  | //获取参数 | 
|---|
|  |  |  | Map<String, Object> map = JSON.parseObject(params, Map.class); | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()) { | 
|---|
|  |  |  | String orgId = entry.getKey(); | 
|---|
|  |  |  | List<String> emails = (List<String>) entry.getValue(); | 
|---|
|  |  |  | //获取该组织下所有设备 | 
|---|
|  |  |  | List<Map<String, Object>> devices = deviceMapper.getAllDeviceByOrg(orgId); | 
|---|
|  |  |  | List<String> devicesInfo = new ArrayList<>(); | 
|---|
|  |  |  | devices.forEach(device -> { | 
|---|
|  |  |  | hashMap.put("mac", device.get("mac").toString()); | 
|---|
|  |  |  | int count = historyHourlyMapper.selectCountByMac(hashMap); | 
|---|
|  |  |  | if (count == 0) { | 
|---|
|  |  |  | devicesInfo.add(device.get("name").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(devicesInfo)) { | 
|---|
|  |  |  | emails.forEach(email -> AlarmUtils_2.sendMail(email, "昨日-设备掉线警报!!!", devicesInfo + "设备掉线!")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ReturnT(200, "执行成功!有邮件发送!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|