From 63ce6f845daff34219e1f6fe582ce55a73393f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=84=B1?= Date: Tue, 24 Sep 2019 23:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=97=B6=E9=95=BF10=E6=94=B9?= =?UTF-8?q?=E4=B8=BA30=E5=88=86=E9=92=9F=20=E7=83=AD=E6=B5=81=E5=99=A8?= =?UTF-8?q?=E6=B0=B4=E6=B5=81=E9=87=8F=E9=A2=84=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ifish/enums/PushTypeEnum.java | 5 +- .../ifish/socketNew/MinaServerHandler.java | 4 +- .../java/com/ifish/socketNew/SomeServer.java | 64 +++++++++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ifish/enums/PushTypeEnum.java b/src/main/java/com/ifish/enums/PushTypeEnum.java index 4ffa4e8..6b92f02 100644 --- a/src/main/java/com/ifish/enums/PushTypeEnum.java +++ b/src/main/java/com/ifish/enums/PushTypeEnum.java @@ -6,8 +6,9 @@ public enum PushTypeEnum { qu_reply("qu_reply","问题反馈"), app_update("app_update","IOS更新推送"), remind_water("remind_water","换水提醒"), - offline_push("offline_push","离线通知"); - + offline_push("offline_push","离线通知"), + ph_warn("ph_warn","水流量预警"); + private PushTypeEnum(String key,String value){ this.key = key; this.value = value; diff --git a/src/main/java/com/ifish/socketNew/MinaServerHandler.java b/src/main/java/com/ifish/socketNew/MinaServerHandler.java index c200fda..a3f4dbb 100644 --- a/src/main/java/com/ifish/socketNew/MinaServerHandler.java +++ b/src/main/java/com/ifish/socketNew/MinaServerHandler.java @@ -90,8 +90,8 @@ public class MinaServerHandler extends IoHandlerAdapter { //离线时间 jobGroup.setTimestamp(IfishUtil.format(new Date())); //10分钟后推送 update 30分钟 -// jobGroup.setStartTime(new Date(System.currentTimeMillis() + 600000L * 3)); - jobGroup.setStartTime(new Date(System.currentTimeMillis() + 60000L)); + jobGroup.setStartTime(new Date(System.currentTimeMillis() + 600000L * 3)); +// jobGroup.setStartTime(new Date(System.currentTimeMillis() + 60000L)); scheduleJob.addJob(jobGroup); } diff --git a/src/main/java/com/ifish/socketNew/SomeServer.java b/src/main/java/com/ifish/socketNew/SomeServer.java index 6fdf1ea..4c4adfd 100644 --- a/src/main/java/com/ifish/socketNew/SomeServer.java +++ b/src/main/java/com/ifish/socketNew/SomeServer.java @@ -30,9 +30,7 @@ import org.springframework.jms.core.JmsTemplate; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Session; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; @@ -62,6 +60,7 @@ public class SomeServer { public static final ConcurrentHashMap remoteAddress = new ConcurrentHashMap(); public static final ConcurrentHashMap sessions_cz = new ConcurrentHashMap(); private ConcurrentHashMap> sessions_sjs = new ConcurrentHashMap>(); + private volatile Map heaterPushStatus = new HashMap<>(); /** * 过滤收到的数据 服务器收到数据,进行协议类型匹配,如果不匹配,则不执行相应操作。 @@ -104,6 +103,17 @@ public class SomeServer { } else { deviceService.save(heater); } + Integer status = heaterPushStatus.get(macAddress); + //当前水流量不正常 并且更新过正常水流标记 或者是第一次出现没有水流 + if (heater.getPh() != 499 && ((status != null && status.intValue() == 2) || status == null)) { + //已推送标记 + heaterPushStatus.put(macAddress, 1); + pushNotifcationByPh(macAddress,PushTypeEnum.ph_warn.getValue(),"没有水流, 请及时查看!"); + } else { + if (heater.getPh() == 499) { + heaterPushStatus.put(macAddress, 2); + } + } //设备重新连接上,则移除延时推送的任务 JobGroup jobGroup = new JobGroup(); jobGroup.setJobName(macAddress); @@ -318,12 +328,58 @@ public class SomeServer { session.write(model); } } + /** - * 温度预警推送 + * 智能加热棒 水流量提醒 * @param strSrc * @param title * @param contont */ + public void pushNotifcationByPh(String strSrc,String title,String contont) { + Device device = deviceService.getUniqueByProperty("macAddress", strSrc); + try { + if(device!=null) { + Integer deviceId = device.getDeviceId(); + //绑定设备的用户 + List list = deviceService.getListByProperty(device.getDeviceId()); + for (DeviceUser deviceUser : list) { + Integer userId = deviceUser.getPriId().getUserId(); + String showName = deviceUser.getShowName(); + String msg = "【" + title + "】你的水族箱“" + showName + "”" + contont; + User user = userService.findById(userId); + if(user!=null){ + //推送记录 + PushList pushList = new PushList(); + //记录推送 + pushList.setUserId(userId); + pushList.setDeviceId(deviceId); + pushList.setPhoneType("ALL"); + pushList.setShowName(showName); + pushList.setPushType(PushTypeEnum.ph_warn.getKey()); + pushList.setPushTitle(title); + pushList.setPushContext(msg); + pushList.setNumber1(device.getNumber1()); + pushList.setNumber2(device.getNumber2()); + pushList.setNumber3(device.getNumber3()); + pushList.setNumber4(device.getNumber4()); + pushList.setNumber5(device.getNumber5()); + JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); + QueueEventEntity eventEntity = new QueueEventEntity(); + eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent"); + eventEntity.setEventProcess("deviceNotifcationPlus"); + QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data); + eventEntity.setEventBody(eventBody); + //推送至消息推送队列 + sendPushQueueMessage(JSONObject.toJSONString(eventEntity)); + } + } + } + }catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + } + + } + /** * 温度预警推送 * @param strSrc