| | |
| | | package com.ruoyi.quartz.task; |
| | | |
| | | import com.ruoyi.alarm.globalAlarm.domain.GuidePriorityQueue; |
| | | import com.ruoyi.alarm.globalAlarm.domain.GuideTask; |
| | | import com.ruoyi.alarm.globalAlarm.service.IGlobalAlarmService; |
| | | import com.ruoyi.alarm.stealAlarm.domain.ArdAlarmStealelec; |
| | | import com.ruoyi.alarm.stealAlarm.service.IStealElecAlarmService; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.LonlatConver; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.common.websocket.util.WebSocketUtils; |
| | | import com.ruoyi.device.camera.service.IArdCamerasService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.PriorityBlockingQueue; |
| | | |
| | | import static com.ruoyi.common.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Component("AlarmTask") |
| | | @Slf4j(topic = "AlarmTask") |
| | | @Slf4j |
| | | public class AlarmTask { |
| | | |
| | | @Resource |
| | | IStealElecAlarmService IStealElecAlarmService; |
| | | @Resource |
| | | ISysUserService sysUserService; |
| | | @Resource |
| | | IGlobalAlarmService globalAlarmService; |
| | | |
| | | /** |
| | | * @描述 盗电报警实时推送任务 |
| | | * @描述 定时推送所有报警的点位数量 |
| | | * @参数 [] |
| | | * @返回值 void |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/3/6 15:10 |
| | | * @创建时间 2023/6/15 15:43 |
| | | * @修改人和其它信息 |
| | | */ |
| | | public void stealElecAlarmPush() { |
| | | log.info("盗电报警推送开始"); |
| | | // 开始时间 |
| | | long stime = System.currentTimeMillis(); |
| | | try { |
| | | for (String userId : ONLINE_USER_SESSIONS.keySet()) { |
| | | SysUser sysUser = sysUserService.selectUserById(userId); |
| | | List<ArdAlarmStealelec> alarms = IStealElecAlarmService.getRealAlarm(sysUser.getDeptId()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | List<ArdAlarmStealelec> objs = new ArrayList<>(); |
| | | for (ArdAlarmStealelec data : alarms) { |
| | | |
| | | //经纬度火星转84 |
| | | if (data.getLongitude() != 0 && data.getLatitude() != 0) { |
| | | double[] wgs84 = LonlatConver.gcj02_To_Wgs84(data.getLongitude(), data.getLatitude());//火星转84 |
| | | data.setLongitude(wgs84[0]); |
| | | data.setLatitude(wgs84[1]); |
| | | } |
| | | |
| | | //判断当前数据是否10S内 |
| | | Date startTime = data.getStartTime(); |
| | | SimpleDateFormat formatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//HH是24小时制,12小时用hh |
| | | Calendar calendar = Calendar.getInstance(); |
| | | //从当前时间减去10秒 |
| | | calendar.add(Calendar.MINUTE, -30); |
| | | String currentTime = formatTime.format(calendar.getTime()); |
| | | int dateFlag = formatTime.format(startTime).compareTo(currentTime); |
| | | if (dateFlag > 0) { |
| | | objs.add(data); |
| | | } |
| | | data.setId(data.getDescribe() + "&" + data.getCommand()); |
| | | } |
| | | if (objs.size() > 0) { |
| | | map.put("obj", objs); |
| | | } else { |
| | | map.put("obj", -1); |
| | | } |
| | | map.put("Command", 8000); |
| | | map.put("count", objs.size()); |
| | | map.put("total", alarms.size()); |
| | | map.put("data", alarms); |
| | | if (alarms.size() > 0) { |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(userId), map); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("盗电报警推送异常:" + ex.getMessage()); |
| | | } |
| | | // 结束时间 |
| | | long etime = System.currentTimeMillis(); |
| | | // 计算执行时间 |
| | | log.info("盗电报警推送结束:" + (etime - stime) + " 毫秒"); |
| | | } |
| | | |
| | | /** |
| | | * @描述 盗电报警api拉取任务 |
| | | * @参数 [] |
| | | * @返回值 void |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/2/28 11:51 |
| | | * @修改人和其它信息 |
| | | */ |
| | | public void stealElecAlarmPull() { |
| | | log.info("盗电数据拉取开始"); |
| | | // 开始时间 |
| | | long stime = System.currentTimeMillis(); |
| | | try { |
| | | // String url = "http://iot.zhdk.net:8090/Warning/GetWarning?userName=cy4oil"; |
| | | IStealElecAlarmService.getAlarmByApi(); |
| | | } catch (Exception ex) { |
| | | log.error("盗电数据拉取异常:" + ex.getMessage()); |
| | | } |
| | | // 结束时间 |
| | | long etime = System.currentTimeMillis(); |
| | | // 计算执行时间 |
| | | log.info("盗电数据拉取结束:" + (etime - stime) + " 毫秒"); |
| | | } |
| | | |
| | | public void globalAlarmCountPush() { |
| | | Map<String, Integer> stringIntegerMap = globalAlarmService.selectAlarmLogsCount(); |
| | | IGlobalAlarmService globalAlarmService = SpringUtils.getBean(IGlobalAlarmService.class); |
| | | Map<String, Object> stringIntegerMap = globalAlarmService.selectAlarmLogsCount(); |
| | | if (ONLINE_USER_SESSIONS.size() > 0) { |
| | | WebSocketUtils.sendMessageAll(stringIntegerMap); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 定时清空引导队列 |
| | | * 刘苏义 |
| | | * 2023/7/1 10:41 |
| | | */ |
| | | public void clearGuideQueue() { |
| | | log.info("定时清理引导队列"); |
| | | for(PriorityBlockingQueue<GuideTask> guideQueue:GuidePriorityQueue.cameraQueueMap.values()) |
| | | { |
| | | guideQueue.clear(); |
| | | } |
| | | } |
| | | } |