From 70626f9b6fb2a192d2b9c0923e85d419a1d7fa1a Mon Sep 17 00:00:00 2001 From: yiyan Date: Mon, 15 Apr 2019 19:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ifish/quartz/ExecuteJob.java | 87 ++++++++++++------- .../java/com/ifish/socketNew/SomeServer.java | 77 ++++++++-------- 2 files changed, 101 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/ifish/quartz/ExecuteJob.java b/src/main/java/com/ifish/quartz/ExecuteJob.java index 8a0a4fc..efd1143 100644 --- a/src/main/java/com/ifish/quartz/ExecuteJob.java +++ b/src/main/java/com/ifish/quartz/ExecuteJob.java @@ -5,6 +5,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ifish.entity.event.QueueEventBody; +import com.ifish.entity.event.QueueEventEntity; import org.apache.mina.core.session.IoSession; import org.quartz.Job; import org.quartz.JobDataMap; @@ -25,6 +29,10 @@ import com.ifish.netease.NeteaseIM; import com.ifish.service.DeviceService; import com.ifish.service.UserService; import com.ifish.socketNew.SomeServer; +import org.springframework.jms.core.JmsTemplate; + +import javax.jms.Destination; +import javax.jms.Session; public class ExecuteJob implements Job { @@ -35,6 +43,10 @@ public class ExecuteJob implements Job { private UserService userService; @Autowired private DeviceService deviceService; + @Autowired + private JmsTemplate jmsTemplate; + @Autowired + private Destination ifish7PushQueueDestination; public void execute(JobExecutionContext context) throws JobExecutionException { //任务传递的参数 @@ -65,42 +77,50 @@ public class ExecuteJob implements Job { String title = PushTypeEnum.offline_push.getValue(); String msg = "【"+title+"】你的水族箱“"+showName+"”于"+timestamp+"离线,请及时查看!"; //发送云信消息 - boolean neteaseBln = false; - Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); - if(neteaseMap!=null){ - neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); - } +// boolean neteaseBln = false; +// Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); +// if(neteaseMap!=null){ +// neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); +// } //IOS极光推送 - boolean jpushIosBln = false; +// boolean jpushIosBln = false; //推送记录 PushList pushList = new PushList(); Integer deviceId = deviceUser.getPriId().getDeviceId(); User user = userService.findById(userId); if(user!=null){ - String loginType = user.getLoginType(); - if(loginType!=null){ - Map map = new HashMap(); - map.put("device_id", deviceId.toString()); - map.put("device_name", showName); - map.put("timestamp", timestamp); - map.put("msg_type", PushTypeEnum.offline_push.getKey()); +// String loginType = user.getLoginType(); +// if(loginType!=null){ +// Map map = new HashMap(); +// map.put("device_id", deviceId.toString()); +// map.put("device_name", showName); +// map.put("timestamp", timestamp); +// map.put("msg_type", PushTypeEnum.offline_push.getKey()); //推送记录 - pushList.setUserId(userId); - pushList.setDeviceId(deviceId); - pushList.setPhoneType(loginType.toLowerCase()); - pushList.setShowName(showName); - pushList.setPushType(PushTypeEnum.offline_push.getKey()); - pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); - pushList.setPushTitle(title); - pushList.setPushContext(msg); - pushList.setCreateTime(new Date()); - pushList.setNumber1(number1); - pushList.setNumber2(number2); - pushList.setNumber3(number3); - pushList.setNumber4(number4); - pushList.setNumber5(number5); - this.userService.save(pushList); - } + pushList.setUserId(userId); + pushList.setDeviceId(deviceId); + pushList.setPhoneType("ALL"); + pushList.setShowName(showName); + pushList.setPushType(PushTypeEnum.offline_push.getKey()); +// pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); + pushList.setPushTitle(title); + pushList.setPushContext(msg); +// pushList.setCreateTime(new Date()); + pushList.setNumber1(number1); + pushList.setNumber2(number2); + pushList.setNumber3(number3); + pushList.setNumber4(number4); + pushList.setNumber5(number5); + 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)); +// this.userService.save(pushList); +// } } } } @@ -110,4 +130,13 @@ public class ExecuteJob implements Job { log.error("error msg:{}",e.toString()); } } + + /** + * 推送Push消息队列 + * @param json 内容 + */ + private void sendPushQueueMessage(final String json) { + jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json)); + } + } \ No newline at end of file diff --git a/src/main/java/com/ifish/socketNew/SomeServer.java b/src/main/java/com/ifish/socketNew/SomeServer.java index b1eef77..164c5f8 100644 --- a/src/main/java/com/ifish/socketNew/SomeServer.java +++ b/src/main/java/com/ifish/socketNew/SomeServer.java @@ -5,6 +5,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ifish.entity.*; import com.ifish.entity.event.QueueEventBody; @@ -450,43 +451,51 @@ public class SomeServer { User user = userService.findById(userId); if(user!=null){ //云信推送 - boolean neteaseBln = false; +// boolean neteaseBln = false; //极光推送 - boolean jpushIosBln = false; - boolean jpushAndroidBln = false; +// boolean jpushIosBln = false; +// boolean jpushAndroidBln = false; //发送云信消息 - Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); - if(neteaseMap!=null){ - neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); - } - String loginType = user.getLoginType(); - if(loginType!=null){ +// Map neteaseMap = neteaseIM.sendMsg("ifish", userId.toString(), msg); +// if(neteaseMap!=null){ +// neteaseBln = neteaseMap.get("code").equals(NeteaseEnum.status200.getKey()); +// } +// String loginType = user.getLoginType(); +// if(loginType!=null){ //推送记录 - PushList pushList = new PushList(); - Map map = new HashMap(); - map.put("device_id", deviceId.toString()); - map.put("device_name", showName); - map.put("timestamp", timestamp); - map.put("msg_type", PushTypeEnum.wendu_warn.getKey()); - //记录推送 - if(jpushIosBln || jpushAndroidBln || neteaseBln){ - pushList.setUserId(userId); - pushList.setDeviceId(deviceId); - pushList.setPhoneType(loginType.toLowerCase()); - pushList.setShowName(showName); - pushList.setPushType(PushTypeEnum.wendu_warn.getKey()); - pushList.setPushTitle(title); - pushList.setPushContext(msg); - pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); - pushList.setCreateTime(new Date()); - pushList.setNumber1(device.getNumber1()); - pushList.setNumber2(device.getNumber2()); - pushList.setNumber3(device.getNumber3()); - pushList.setNumber4(device.getNumber4()); - pushList.setNumber5(device.getNumber5()); - this.userService.save(pushList); - } - } + PushList pushList = new PushList(); +// Map map = new HashMap(); +// map.put("device_id", deviceId.toString()); +// map.put("device_name", showName); +// map.put("timestamp", timestamp); +// map.put("msg_type", PushTypeEnum.wendu_warn.getKey()); + //记录推送 +// if(jpushIosBln || jpushAndroidBln || neteaseBln){ + pushList.setUserId(userId); + pushList.setDeviceId(deviceId); + pushList.setPhoneType("ALL"); + pushList.setShowName(showName); + pushList.setPushType(PushTypeEnum.wendu_warn.getKey()); + pushList.setPushTitle(title); + pushList.setPushContext(msg); +// pushList.setNeteaseStatus(neteaseBln?BooleanEnum.YES.getKey():BooleanEnum.NO.getKey()); +// pushList.setCreateTime(new Date()); + 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)); +// this.userService.save(pushList); +// } +// } } }